Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of spdlog with fmt #3196

Open
copilot0058 opened this issue Sep 22, 2024 · 7 comments
Open

Usage of spdlog with fmt #3196

copilot0058 opened this issue Sep 22, 2024 · 7 comments

Comments

@copilot0058
Copy link

copilot0058 commented Sep 22, 2024

Install the spdlog with fmt, then I try to find_package(SPDLOG)

it show the error, but I alread install the spdlog with fmt.
Why does it still need twice?
one is cmake build spdlog with fmt, another is use find_package(SPDLOG) on project.

the error is find_package(SPDLOG), by the way, I already install the spdlog with fmt

> [CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
1> [CMake]   Could not find a package configuration file provided by "fmt" with any of
1> [CMake]   the following names:
1> [CMake] 
1> [CMake]     fmtConfig.cmake
1> [CMake]     fmt-config.cmake
1> [CMake] 
1> [CMake]   Add the installation prefix of "fmt" to CMAKE_PREFIX_PATH or set "fmt_DIR"
1> [CMake]   to a directory containing one of the above files.  If "fmt" provides a
1> [CMake]   separate development package or SDK, be sure it has been installed.

option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)

https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt

@tt4g
Copy link
Contributor

tt4g commented Sep 22, 2024

fmt is not always installed with spdlog.
And, it is the bundled fmt (header files) that is installed, not fmt.dll.

spdlog/CMakeLists.txt

Lines 322 to 325 in 2c76e61

if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
endif()

If you installed spdlog with SPDLOG_FMT_EXTERNAL=ON, you are responsible for installing fmt on your machine.

@copilot0058
Copy link
Author

copilot0058 commented Sep 22, 2024

I want to clarify: I have already installed fmt and spdlog, and I have set SPDLOG_FMT_EXTERNAL=ON.
Now I want to use the already compiled spdlog (with fmt) in my own project.
Therefore, I used find_package(SPDLOG). Since I have already compiled spdlog (with fmt), I shouldn't need the fmt config, right?

Here is the compiled spdlog

C:.
├─include
│  └─spdlog
│      ├─cfg
│      ├─details
│      ├─fmt
│      └─sinks
└─lib
    ├─spdlog.lib
    ├─cmake
    │  └─spdlog
    └─pkgconfig

@tt4g
Copy link
Contributor

tt4g commented Sep 22, 2024

If C:\lib\fmt.lib is missing, fmt is not installed.
You must download the source code from the fmt project and install fmt.
Then, spdlog must be rebuilt to reference the installed fmt.

@copilot0058
Copy link
Author

If I want to build spdlog with fmt and only use find_package(SPDLOG) on my project. (no find_package(fmt) on my project )
how can I set the cmake option?

@tt4g
Copy link
Contributor

tt4g commented Sep 22, 2024

Rebuild and reinstall spdlog without defining SPDLOG_FMT_EXTERNAL.

@copilot0058
Copy link
Author

Thanks,

So the default setting is using include/spdlog/fmt ?

https://github.com/gabime/spdlog/tree/v1.x/include/spdlog/fmt

SPDLOG_FMT_EXTERNAL=OFF     ====>      using include/spdlog/fmt of spdlog 
SPDLOG_FMT_EXTERNAL=ON      ====>      using external fmt

@tt4g
Copy link
Contributor

tt4g commented Sep 22, 2024

include/spdlog/fmt is a header file for spdlog to use fmt and std::format separately.
Bundled fmt is include/spdlog/fmt/bundled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants