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

Avoid compiling static library when using FetchContent with fmt::fmt-header-only #4022

Closed
filippobistaffa opened this issue Jun 16, 2024 · 3 comments
Labels

Comments

@filippobistaffa
Copy link

My goal is to avoid compiling libfmt.a with the following CMakeList.txt and test.cpp

cmake_minimum_required(VERSION 3.20)
project(test)

include(FetchContent)
FetchContent_Declare(fmt
    GIT_REPOSITORY https://github.com/fmtlib/fmt.git
    GIT_TAG master
)
FetchContent_MakeAvailable(fmt)

add_executable(test test.cpp)
target_link_libraries(test PRIVATE fmt::fmt-header-only)
#include <fmt/core.h>

int main() {

    fmt::print("Hello world!\n");
    return 0;
}

Is it possible to achieve this? What I'm getting instead is the following:

[ 20%] Building CXX object _deps/fmt-build/CMakeFiles/fmt.dir/src/format.cc.o
[ 40%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[ 60%] Building CXX object _deps/fmt-build/CMakeFiles/fmt.dir/src/os.cc.o
[ 80%] Linking CXX executable test
[100%] Linking CXX static library libfmt.a
[100%] Built target fmt
[100%] Built target test
@vitaut
Copy link
Contributor

vitaut commented Jun 17, 2024

I am not sure, you might want to check the CMake docs. In general, the header-only config is not recommended and there are even fewer reason to use it with FetchConfig.

@filippobistaffa
Copy link
Author

In general, the header-only config is not recommended and there are even fewer reason to use it with FetchConfig.

Do you mean using fmt::fmt-header-only in CMake or using #define FMT_HEADER_ONLY? Also, why is it "not recommended" (not that I don't believe you, just curious if there's any technical drawback).

@vitaut
Copy link
Contributor

vitaut commented Jun 18, 2024

Do you mean using fmt::fmt-header-only in CMake or using #define FMT_HEADER_ONLY?

Both.

Header-only is generally bad for compile times, see e.g. https://stackoverflow.com/a/68020236/471164.

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

No branches or pull requests

2 participants