@@ -3,23 +3,19 @@ cmake_minimum_required(VERSION 3.30...4.2)
33
44include (cmake/prelude.cmake )
55
6- set (CMAKE_CXX_SCAN_FOR_MODULES ON )
6+ option (
7+ CMAKE_CXX_SCAN_FOR_MODULES
8+ "Whether to scan C++ source files for module dependencies"
9+ ON
10+ )
11+ option (BUILD_SHARED_LIBS "Build using shared libraries" ON )
712
813# Set experimental flag to enable `import std` support from CMake.
914# This must be enabled before C++ language support.
1015if (CMAKE_CXX_SCAN_FOR_MODULES)
1116 set (CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
1217 "d0edc3af-4c50-42ea-a356-e2862fe7a444"
1318 )
14- # if(APPLE AND $ENV{CXX} STREQUAL g++-15)
15- # set(CMAKE_CXX_STDLIB_MODULES_JSON
16- # $ENV{GCC_DIR}/lib/gcc/current/libstdc++.modules.json
17- # )
18- # else()
19- # set(CMAKE_CXX_STDLIB_MODULES_JSON
20- # $ENV{LLVM_DIR}/lib/c++/libc++.modules.json
21- # )
22- # endif()
2319endif ()
2420
2521#==================================================
@@ -39,16 +35,12 @@ set(CMAKE_CXX_EXTENSIONS ON)
3935set (CMAKE_CXX_STANDARD_REQUIRED ON )
4036
4137set (CMAKE_DEBUG_POSTFIX D)
42- # to prevent -Winclude-angled-in-module-purview in fmt/os.h
43- # see /Users/clausklein/.cache/CPM/fmt/297020319ba1d5d14e1599714def59a1788711c5/include/fmt/os.h:33
44- set (CPPdefinitions FMT_USE_FCNTL=0)
45- set (ADD_STDLIB_MODULES)
38+ set (CMAKE_SKIP_TEST_ALL_DEPENDENCY OFF )
4639
47- option (
48- FMT_SEPARATE_COMPILATION
49- "build fmt lib too"
50- ${CMAKE_CXX_SCAN_FOR_MODULES}
51- )
40+ # FIXME: to prevent -Winclude-angled-in-module-purview in fmt/os.h
41+ # see /Users/clausklein/.cache/CPM/fmt/6226dc0d560c5dca8bcd81db09f7e2752ccb8cef/include/fmt/os.h:33
42+ set (CPPdefinitions FMT_USE_FCNTL=0)
43+ option (FMT_SEPARATE_COMPILATION "build fmt lib too" ${PROJECT_IS_TOP_LEVEL} )
5244option (
5345 FMT_USE_MODULES
5446 "Export a CXX_MODULE fmt if possible"
@@ -82,35 +74,6 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
8274 set (LLVM_DIR ${LLVM_DIR} CACHE PATH "" )
8375 message (STATUS "LLVM_DIR=${LLVM_DIR} " )
8476
85- # if(LINUX AND EXISTS ${LLVM_LIBC_SOURCE}/std.cppm)
86- # message(WARNING "LLVM_LIBC_SOURCE=${LLVM_LIBC_SOURCE}")
87- # set(ADD_STDLIB_MODULES stdc++)
88- # list(APPEND CMAKE_CXX_COMPILER_IMPORT_STD 23)
89- # endif()
90-
91- # Build the stdlib module
92- function (add_stdlib_module NAME )
93- add_library (${NAME} )
94- target_sources (
95- ${NAME}
96- PUBLIC
97- FILE_SET CXX_MODULES
98- BASE_DIRS ${LLVM_LIBC_SOURCE}
99- FILES
100- ${LLVM_LIBC_SOURCE} /std.cppm
101- ${LLVM_LIBC_SOURCE} /std.compat.cppm
102- )
103- target_compile_features (${NAME} PUBLIC cxx_std_23 )
104- target_compile_definitions (
105- ${NAME}
106- PUBLIC _LIBCPP_HAS_NO_LOCALIZATION
107- )
108- target_compile_options (
109- ${NAME}
110- PRIVATE -Wno-reserved-module-identifier
111- )
112- endfunction ()
113-
11477 add_compile_options (-fexperimental-library )
11578 add_link_options (-L${LLVM_DIR}/lib/c++ -lc++experimental )
11679 add_compile_options (-stdlib=libc++ )
@@ -129,7 +92,7 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
12992 set (CMAKE_CXX_MODULE_STD ON )
13093 endif ()
13194
132- if (CMAKE_CXX_MODULE_STD OR ADD_STDLIB_MODULES )
95+ if (CMAKE_CXX_MODULE_STD)
13396 list (APPEND CPPdefinitions FMT_IMPORT_STD)
13497 endif ()
13598
@@ -141,31 +104,27 @@ if(CMAKE_GENERATOR STREQUAL "Ninja" AND FMT_USE_MODULES)
141104 message (STATUS "CMAKE_CXX_MODULE_STD=${CMAKE_CXX_MODULE_STD} " )
142105 message (STATUS "CPPdefinitions=${CPPdefinitions} " )
143106else ()
144- set (CMAKE_VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL} )
107+ option (CMAKE_VERIFY_INTERFACE_HEADER_SETS "" ${PROJECT_IS_TOP_LEVEL} )
145108endif ()
146109
147- #XXX if(MSVC)
148- #XXX include(cmake/example.cmake)
149- #XXX endif()
150-
151110# ---- add dependency libraries ----
152111
153112include (cmake/CPM.cmake )
154113
155- # gersemi: off
156114cpmaddpackage (
157115 NAME fmt
158116 GITHUB_REPOSITORY fmtlib/fmt
159117 GIT_TAG 12.1.0
160118 VERSION 12.1.0
161119 DOWNLOAD_ONLY ON
162- # XXX PATCH_COMMAND git apply -p 1 ${CMAKE_CURRENT_SOURCE_DIR}/fmt.patch
120+ # NO! PATCH_COMMAND git apply -p 1 ${CMAKE_CURRENT_SOURCE_DIR}/fmt.patch
163121)
164- # gersemi: on
165122
166- # ---- Declare library ----
123+ # -----------------------------------------
124+ # ---- Collect the fmt library sources ----
125+ # -----------------------------------------
167126
168- # TODO: only if needed (compare) and possible!
127+ # TODO(CK): manually apply the patch if needed (compare) and possible!
169128if (
170129 EXISTS ${fmt_SOURCE_DIR} /src/fmt.cc
171130 AND NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /module/fmt.cppm
@@ -187,13 +146,29 @@ configure_file(
187146 ${CMAKE_CURRENT_SOURCE_DIR} /module/os.cc
188147 COPYONLY
189148)
190- file (GLOB_RECURSE _fmt_all_sources "module/*.cc" )
191149
192- # fmt interface library
150+ file (
151+ GLOB_RECURSE _fmt_all_sources
152+ CONFIGURE_DEPENDS
153+ RELATIVE ${CMAKE_CURRENT_LIST_DIR}
154+ module/*.cc
155+ )
156+
157+ # -----------------------------------------
158+ # -----------------------------------------
159+
160+ #
161+ # build the fmt interface library
162+ #
193163add_library (fmt-header-only INTERFACE )
194164add_library (fmt::fmt-header-only ALIAS fmt-header-only )
195165
196- file (GLOB_RECURSE _fmt_public_header "${fmt_SOURCE_DIR} /include/fmt/*.h" )
166+ file (
167+ GLOB_RECURSE _fmt_public_header
168+ CONFIGURE_DEPENDS
169+ # NO! RELATIVE ${fmt_SOURCE_DIR}/include
170+ ${fmt_SOURCE_DIR} /include/fmt/*.h
171+ )
197172target_sources (
198173 fmt-header-only
199174 INTERFACE
@@ -211,10 +186,11 @@ target_compile_options(
211186 INTERFACE $<$<AND :$<COMPILE_LANGUAGE :CXX >,$<CXX_COMPILER_ID :MSVC >>:/utf -8>
212187)
213188
189+ #
190+ # build the fmt library
191+ #
214192if (FMT_SEPARATE_COMPILATION)
215- # file(GLOB_RECURSE _fmt_all_sources "${fmt_SOURCE_DIR}/src/*.cc")
216-
217- add_library (fmt STATIC )
193+ add_library (fmt )
218194 target_sources (
219195 fmt
220196 PUBLIC
@@ -244,10 +220,10 @@ if(FMT_SEPARATE_COMPILATION)
244220 )
245221 target_compile_definitions (fmt PUBLIC ${CPPdefinitions} )
246222 else ()
247- message (FATAL_ERROR "FMT_USE_MODULES= ${FMT_USE_MODULES} !" )
223+ message (WARNING "Missing or disabled support for CXX_MODULES !" )
248224 add_library (fmt::fmt ALIAS fmt )
249225 target_compile_definitions (fmt PUBLIC ${CPPdefinitions} )
250- target_sources (fmt PUBLIC ${_fmt_all_sources} )
226+ target_sources (fmt PRIVATE ${_fmt_all_sources} )
251227 endif ()
252228
253229 if (FMT_WARNINGS_AS_ERRORS AND FMT_DEVELOPER_MODE AND UNIX )
0 commit comments