From 48c0954fb339c6efdce1115da4623990688c3782 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 1 Jan 2025 14:07:52 +0100 Subject: [PATCH 1/4] Set FMT_USE_MODULES again format cmake files --- CMakeLists.txt | 18 ++++++++---------- cmake/install-rules.cmake | 7 ++++--- module/tests/CMakeLists.txt | 1 - 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfa1fd1..e43850f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,6 @@ project(fmt include(cmake/variables.cmake) -if(CMAKE_BUILD_TYPE STREQUAL Release) - include(cmake/example.cmake) -endif() - set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_EXTENSIONS ON) set(CMAKE_CXX_STANDARD_REQUIRED YES) @@ -31,10 +27,8 @@ set(CPPdefinitions FMT_USE_FCNTL=0) set(ADD_STDLIB_MODULES) option(FMT_SEPARATE_COMPILATION "build fmt lib too" ${PROJECT_IS_TOP_LEVEL}) -if(UNIX) - option(FMT_USE_MODULES "Export a CXX_MODULE fmt if possible" ${PROJECT_IS_TOP_LEVEL}) -endif() -# TODO: option(FMT_IMPORT_STD "Import the module std" ${PROJECT_IS_TOP_LEVEL}) +option(FMT_USE_MODULES "Export a CXX_MODULE fmt if possible" ${PROJECT_IS_TOP_LEVEL}) +option(FMT_IMPORT_STD "Import the module std" ${PROJECT_IS_TOP_LEVEL}) if(FMT_USE_MODULES) list(APPEND CPPdefinitions FMT_MODULE) @@ -81,6 +75,10 @@ else() set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL}) endif() +if(ADD_STDLIB_MODULES AND CMAKE_BUILD_TYPE STREQUAL Release) + include(cmake/example.cmake) +endif() + # ---- add dependency libraries ---- include(cmake/CPM.cmake) @@ -153,13 +151,13 @@ if(FMT_SEPARATE_COMPILATION) # cmake-format: on else() add_library(fmt::fmt ALIAS fmt) - set(CMAKE_CXX_SCAN_FOR_MODULES OFF) + set_target_properties(fmt PROPERTIES CXX_SCAN_FOR_MODULES OFF) target_compile_definitions(fmt PUBLIC ${CPPdefinitions}) target_sources(fmt PUBLIC ${_fmt_all_sources}) endif() if(FMT_WARNINGS_AS_ERRORS AND FMT_DEVELOPER_MODE AND UNIX) - target_compile_options(fmt PUBLIC -Werror) + target_compile_options(fmt PRIVATE -Werror) endif() endif() diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index 0768e7d..cc903b9 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -18,11 +18,12 @@ mark_as_advanced(FMT_INSTALL_CMAKEDIR) install(TARGETS fmt-header-only EXPORT fmtTargets FILE_SET HEADERS) if(FMT_USE_MODULES) - install(TARGETS fmt EXPORT fmtTargets FILE_SET public_headers FILE_SET public_modules - DESTINATION ${FMT_INSTALL_CMAKEDIR}/module + install(TARGETS fmt EXPORT fmtTargets FILE_SET public_headers # + FILE_SET public_modules DESTINATION ${FMT_INSTALL_CMAKEDIR}/module ) -else() install(FILES module/fmt.cppm DESTINATION ${FMT_INSTALL_CMAKEDIR}/module) +else() + install(TARGETS fmt EXPORT fmtTargets FILE_SET public_headers) endif() install(FILES ${_fmt_all_sources} DESTINATION ${FMT_INSTALL_CMAKEDIR}/module) diff --git a/module/tests/CMakeLists.txt b/module/tests/CMakeLists.txt index 1c9999d..d741c21 100644 --- a/module/tests/CMakeLists.txt +++ b/module/tests/CMakeLists.txt @@ -50,7 +50,6 @@ foreach(_file ${ALL_TESTS}) target_sources(module_${_file} PRIVATE ../../tests/${_file}.cc) if(USE_MODULES) target_link_libraries(module_${_file} fmt-module ${ADD_STDLIB_MODULES}) - # XXX: NOT USED! target_compile_definitions(module_${_file} PUBLIC USE_MODULES) else() target_link_libraries(module_${_file} fmt::fmt-header-only) endif() From 6565e41731a694cad72d955434b9574386e875b9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 27 Dec 2024 09:57:04 +0100 Subject: [PATCH 2/4] Prevent build errors --- CMakeLists.txt | 4 ++-- cmake/CPM.cmake | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e43850f..69725b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,8 @@ set(CPPdefinitions FMT_USE_FCNTL=0) set(ADD_STDLIB_MODULES) option(FMT_SEPARATE_COMPILATION "build fmt lib too" ${PROJECT_IS_TOP_LEVEL}) -option(FMT_USE_MODULES "Export a CXX_MODULE fmt if possible" ${PROJECT_IS_TOP_LEVEL}) -option(FMT_IMPORT_STD "Import the module std" ${PROJECT_IS_TOP_LEVEL}) +#XXX option(FMT_USE_MODULES "Export a CXX_MODULE fmt if possible" ${PROJECT_IS_TOP_LEVEL}) +#XXX option(FMT_IMPORT_STD "Import the module std" ${PROJECT_IS_TOP_LEVEL}) if(FMT_USE_MODULES) list(APPEND CPPdefinitions FMT_MODULE) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 8bcca85..cb79e5b 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -16,7 +16,8 @@ endif() # Expand relative path. This is important if the provided path contains a tilde (~) get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} ) From fb47b09991c536147b546639967f80d493e9e68e Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 8 Dec 2024 18:49:13 +0100 Subject: [PATCH 3/4] Buggy, only to show the problem --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69725b4..521b242 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ endif() configure_file(${fmt_SOURCE_DIR}/src/format.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/format.cc COPYONLY) configure_file(${fmt_SOURCE_DIR}/src/os.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/os.cc COPYONLY) +configure_file(${fmt_SOURCE_DIR}/src/fmt.cc ${CMAKE_CURRENT_SOURCE_DIR}/module/fmt.cc COPYONLY) file(GLOB_RECURSE _fmt_all_sources "module/*.cc") # fmt interface library From c436473bda85be2a6a336cdfc330c51fc416586c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 1 Jan 2025 18:56:57 +0100 Subject: [PATCH 4/4] Do not set CMAKE_CXX_MODULE_STD --- CMakeLists.txt | 2 +- cmake/CPM.cmake | 3 +-- cmake/install-rules.cmake | 1 - module/tests/CMakeLists.txt | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 521b242..9ff6301 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,7 +154,7 @@ if(FMT_SEPARATE_COMPILATION) add_library(fmt::fmt ALIAS fmt) set_target_properties(fmt PROPERTIES CXX_SCAN_FOR_MODULES OFF) target_compile_definitions(fmt PUBLIC ${CPPdefinitions}) - target_sources(fmt PUBLIC ${_fmt_all_sources}) + target_sources(fmt PRIVATE ${_fmt_all_sources}) endif() if(FMT_WARNINGS_AS_ERRORS AND FMT_DEVELOPER_MODE AND UNIX) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index cb79e5b..8bcca85 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -16,8 +16,7 @@ endif() # Expand relative path. This is important if the provided path contains a tilde (~) get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -file(DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake +file(DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} ) diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index cc903b9..3a64584 100644 --- a/cmake/install-rules.cmake +++ b/cmake/install-rules.cmake @@ -21,7 +21,6 @@ if(FMT_USE_MODULES) install(TARGETS fmt EXPORT fmtTargets FILE_SET public_headers # FILE_SET public_modules DESTINATION ${FMT_INSTALL_CMAKEDIR}/module ) - install(FILES module/fmt.cppm DESTINATION ${FMT_INSTALL_CMAKEDIR}/module) else() install(TARGETS fmt EXPORT fmtTargets FILE_SET public_headers) endif() diff --git a/module/tests/CMakeLists.txt b/module/tests/CMakeLists.txt index d741c21..582ac5b 100644 --- a/module/tests/CMakeLists.txt +++ b/module/tests/CMakeLists.txt @@ -31,7 +31,7 @@ if(PROJECT_IS_TOP_LEVEL) endif() message(STATUS "CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}") endif() - if(USE_MODULES) + if(USE_MODULES AND CMAKE_CXX_MODULE_STD) if(NOT CMAKE_CXX_COMPILER_IMPORT_STD AND ADD_STDLIB_MODULES) message(WARNING "ADD_STDLIB_MODULES=${ADD_STDLIB_MODULES}") add_stdlib_module(${ADD_STDLIB_MODULES}) @@ -48,7 +48,7 @@ message(STATUS "Module tests to be built: ${ALL_TESTS}") foreach(_file ${ALL_TESTS}) add_executable(module_${_file}) target_sources(module_${_file} PRIVATE ../../tests/${_file}.cc) - if(USE_MODULES) + if(CMAKE_CXX_MODULE_STD) target_link_libraries(module_${_file} fmt-module ${ADD_STDLIB_MODULES}) else() target_link_libraries(module_${_file} fmt::fmt-header-only)