Skip to content

Commit ddad8cf

Browse files
committed
Using cmake for C++ modules
1 parent 951d6ec commit ddad8cf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
project(modules_test)
4+
5+
function(target_enable_modules TARGET)
6+
if(CMAKE_BUILD_TYPE MATCHES "^Debug$" OR NOT DEFINED CMAKE_BUILD_TYPE)
7+
set(_MODULES_PATH $ENV{IFCPATH}/Debug)
8+
else()
9+
set(_MODULES_PATH $ENV{IFCPATH}/Release)
10+
endif()
11+
find_library(_MODULES_LIB NAME std PATHS ${_MODULES_PATH} NO_DEFAULT_PATH)
12+
13+
add_library(Modules::std UNKNOWN IMPORTED)
14+
if(EXISTS "${_MODULES_LIB}")
15+
set_target_properties(Modules::std PROPERTIES
16+
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
17+
IMPORTED_LOCATION "${_MODULES_LIB}")
18+
endif()
19+
20+
target_compile_options(${TARGET} PRIVATE /experimental:module "/module:search ${_MODULES_PATH}")
21+
endfunction()
22+
23+
24+
set(MODULES actor.ixx manager.ixx)
25+
set(SOURCES main.cpp manager.cpp)
26+
list(APPEND SOURCES ${MODULES})
27+
28+
add_executable(${PROJECT_NAME} ${SOURCES})
29+
set_source_files_properties(${MODULES} PROPERTIES LANGUAGE CXX)
30+
target_enable_modules(${PROJECT_NAME})
31+
32+
target_link_libraries(${PROJECT_NAME} Modules::std)
33+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)

0 commit comments

Comments
 (0)