Skip to content

Commit 898f2de

Browse files
Trying specific handling for CMake examples
1 parent b5eddf3 commit 898f2de

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

docpages/example_code/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,31 @@
2828
# libmpg123-dev
2929
# dpp latest master with -DDPP_CORO=ON installed sytemwide
3030

31-
cmake_minimum_required (VERSION 3.16)
31+
cmake_minimum_required (VERSION 3.28)
3232
project(documentation_tests)
3333

3434
string(ASCII 27 Esc)
3535

36-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -DDPP_MODULES -std=c++20 -pthread -O0 -fPIC -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations")
36+
option(DPP_MODULES "Build examples with C++20 modules support" ON)
37+
38+
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")
3739
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
3840

3941
file(GLOB example_list ./*.cpp)
4042
foreach (example ${example_list})
4143
get_filename_component(examplename ${example} NAME)
44+
4245
message(STATUS "Found example '${Esc}[1;34m${examplename}${Esc}[m'")
4346
add_executable(${examplename}_out ${example})
4447
target_link_libraries(${examplename}_out dl dpp mpg123 oggz ogg opusfile opus)
4548
include_directories(/usr/include/opus)
49+
50+
target_compile_definitions(${examplename}_out PRIVATE DPP_MODULES)
51+
set_target_properties(${examplename}_out PROPERTIES CXX_SCAN_FOR_MODULES ON)
52+
53+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
54+
target_compile_options(${examplename}_out PRIVATE -fmodules-ts)
55+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
56+
target_compile_options(${examplename}_out PRIVATE -fmodules)
57+
endif()
4658
endforeach(example)

0 commit comments

Comments
 (0)