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

Use native c++ module support from CMake #3990

Closed
yujincheng08 opened this issue Jun 4, 2024 · 3 comments · Fixed by #3991
Closed

Use native c++ module support from CMake #3990

yujincheng08 opened this issue Jun 4, 2024 · 3 comments · Fixed by #3991

Comments

@yujincheng08
Copy link
Contributor

yujincheng08 commented Jun 4, 2024

Hi, fmtlib supports using FMT_MODULE to make itself a c++ module, but the implementation is building manually rather than using native support from CMake. This leads to some problems. For example, we cannot add definitions like FMT_STATIC_THOUSANDS_SEPARATOR.

I saw previous discussion #3429 (comment) concerning native support from CMake is not yet ready. But now it has been stabilize: https://www.kitware.com/import-cmake-the-experiment-is-over. Maybe it's time to add the support?

I tried something like

add_library(fmt STATIC)
target_sources(fmt PUBLIC FILE_SET CXX_MODULES FILES fmt/src/fmt.cc)
target_include_directories(fmt PRIVATE fmt/include)
target_compile_definitions(fmt PUBLIC FMT_USE_FLOAT=0 FMT_USE_DOUBLE=0 FMT_USE_LONG_DOUBLE=0 FMT_USE_FLOAT128=0 FMT_USE_LONG_DOUBLE=0)

and it does work! (though we cannot add FMT_STATIC_THOUSANDS_SEPARATOR unless we comment out chrono.h.)

@yujincheng08 yujincheng08 changed the title Use native module support in CMake Use native c++ module support from CMake Jun 4, 2024
@vitaut
Copy link
Contributor

vitaut commented Jun 4, 2024

Now that C++20 module support has been released in CMake I think it's reasonable to add it, at least as an option. Thanks for the suggestion.

@yujincheng08
Copy link
Contributor Author

@vitaut I have raised a PR for it. Lets see if it is a good start point.

@LeenHawk
Copy link

Hi, fmtlib supports using FMT_MODULE to make itself a c++ module, but the implementation is building manually rather than using native support from CMake. This leads to some problems. For example, we cannot add definitions like FMT_STATIC_THOUSANDS_SEPARATOR.

I saw previous discussion #3429 (comment) concerning native support from CMake is not yet ready. But now it has been stabilize: https://www.kitware.com/import-cmake-the-experiment-is-over. Maybe it's time to add the support?

I tried something like

add_library(fmt STATIC)
target_sources(fmt PUBLIC FILE_SET CXX_MODULES FILES fmt/src/fmt.cc)
target_include_directories(fmt PRIVATE fmt/include)
target_compile_definitions(fmt PUBLIC FMT_USE_FLOAT=0 FMT_USE_DOUBLE=0 FMT_USE_LONG_DOUBLE=0 FMT_USE_FLOAT128=0 FMT_USE_LONG_DOUBLE=0)

and it does work! (though we cannot add FMT_STATIC_THOUSANDS_SEPARATOR unless we comment out chrono.h.)

excuse me, could you help me for an example of import fmt? I have failed for a day....

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

Successfully merging a pull request may close this issue.

3 participants