Skip to content

Commit 3d336da

Browse files
committed
Update cmake c++ modules support
1 parent ddad8cf commit 3d336da

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ function(target_enable_modules TARGET)
2020
target_compile_options(${TARGET} PRIVATE /experimental:module "/module:search ${_MODULES_PATH}")
2121
endfunction()
2222

23+
function(target_add_module TARGET MODULE_FILES)
24+
set(_module_files ${MODULE_FILES} ${ARGN})
25+
get_target_property(_srcs ${TARGET} SOURCES)
26+
27+
foreach(_module_file ${_module_files})
28+
message(${_module_file})
29+
set_source_files_properties(${_module_file} PROPERTIES LANGUAGE CXX)
30+
list(INSERT _srcs 0 ${_module_file})
31+
endforeach()
32+
33+
set_target_properties(${TARGET} PROPERTIES SOURCES "${_srcs}")
34+
endfunction()
2335

24-
set(MODULES actor.ixx manager.ixx)
2536
set(SOURCES main.cpp manager.cpp)
26-
list(APPEND SOURCES ${MODULES})
2737

2838
add_executable(${PROJECT_NAME} ${SOURCES})
29-
set_source_files_properties(${MODULES} PROPERTIES LANGUAGE CXX)
3039
target_enable_modules(${PROJECT_NAME})
40+
target_add_module(${PROJECT_NAME} actor.ixx manager.ixx)
3141

3242
target_link_libraries(${PROJECT_NAME} Modules::std)
3343
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)

0 commit comments

Comments
 (0)