Skip to content

Commit ce88aff

Browse files
Manually link the module instead of relying on CMake for now
1 parent 1d41aa9 commit ce88aff

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docpages/example_code/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ option(DPP_MODULES "Build examples with C++20 modules support" ON)
3838
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -std=c++20 -pthread -O0 -fPIC -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
3939
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
4040

41+
# Create gcm.cache directory and symlink to the main build's dpp.gcm
42+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
43+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/gcm.cache")
44+
file(CREATE_LINK "${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir/dpp.gcm"
45+
"${CMAKE_BINARY_DIR}/gcm.cache/dpp.gcm" SYMBOLIC)
46+
endif()
47+
4148
file(GLOB example_list ./*.cpp)
4249
foreach (example ${example_list})
4350
get_filename_component(examplename ${example} NAME)
@@ -53,6 +60,10 @@ foreach (example ${example_list})
5360
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5461
target_compile_options(${examplename}_out PRIVATE -fmodules-ts)
5562
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
56-
target_compile_options(${examplename}_out PRIVATE -fmodules)
63+
target_compile_options(${examplename}_out PRIVATE
64+
-fmodules
65+
-mavx2
66+
-fprebuilt-module-path=${CMAKE_SOURCE_DIR}/../../build/library/CMakeFiles/dpp.dir
67+
)
5768
endif()
5869
endforeach(example)

docpages/example_code/using_modules.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#include <string>
2+
#include <typeinfo>
3+
14
import dpp;
25

36
int main() {
@@ -9,7 +12,7 @@ int main() {
912
}
1013
});
1114

12-
bot.on_ready([&bot](const std::ready_t& event) -> void {
15+
bot.on_ready([&bot](const dpp::ready_t& event) -> void {
1316
if (dpp::run_once<struct register_bot_commands>()) {
1417
bot.global_command_create(
1518
dpp::slashcommand("ping", "Ping pong!", bot.me.id)

library/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,9 @@ endif()
461461

462462
if (DPP_MODULES)
463463
message("-- ${Green}Modules are enabled!${ColourReset}")
464-
464+
465+
set_target_properties(dpp PROPERTIES CXX_EXTENSIONS OFF)
466+
465467
# Add module file set directly to the dpp target
466468
target_sources(dpp
467469
PUBLIC
@@ -500,7 +502,7 @@ if (DPP_BUILD_TEST)
500502
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
501503
target_compile_options(${testname} PRIVATE -fmodules)
502504
endif()
503-
set_target_properties(${testname} PROPERTIES CXX_SCAN_FOR_MODULES ON)
505+
set_target_properties(${testname} PROPERTIES CXX_SCAN_FOR_MODULES ON CXX_EXTENSIONS OFF)
504506
elseif(BUILD_SHARED_LIBS)
505507
target_link_libraries(${testname} PUBLIC ${modname})
506508
else()

0 commit comments

Comments
 (0)