22
33cmake_minimum_required (VERSION 3.30...4.3 )
44
5+ include (./cmake/prelude.cmake )
6+
57project (
68 beman.scope
79 DESCRIPTION "Generic Scope Guard"
810 LANGUAGES CXX
9- VERSION 0.0.1
11+ VERSION 0.1.0
1012)
1113
12- # gersemi: off
13-
1414# Modules opt in only on compilers that support it: msvc, g++-15 and clang-20+
15- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
16- set (CMAKE_CXX_SCAN_FOR_MODULES 1)
17- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
18- set (CMAKE_CXX_SCAN_FOR_MODULES 1)
19- elseif (MSVC )
20- set (CMAKE_CXX_SCAN_FOR_MODULES 1)
21- else ()
22- set (CMAKE_CXX_SCAN_FOR_MODULES 0)
15+ include (./cmake/cxx-modules-rules.cmake )
16+
17+ #===============================================================================
18+ if (BEMAN_USE_MODULES)
19+ option (BUILD_SHARED_LIBS "Build using shared libraries" OFF )
20+
21+ set (CMAKE_CXX_SCAN_FOR_MODULES ON )
22+ set (CMAKE_CXX_VISIBILITY_PRESET hidden)
23+ set (CMAKE_VISIBILITY_INLINES_HIDDEN ON )
2324endif ()
2425
25- set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
26- set (CMAKE_CXX_VISIBILITY_PRESET hidden)
27- set (CMAKE_VISIBILITY_INLINES_HIDDEN TRUE )
26+ # gersemi: off
2827
2928# [CMAKE.SKIP_TESTS]
3029option (
@@ -46,22 +45,15 @@ option(
4645 ${PROJECT_IS_TOP_LEVEL}
4746)
4847
49- message (
50- "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION} "
51- )
52- message (
53- "cmake is: ${CMAKE_VERSION} modules scan: ${CMAKE_CXX_SCAN_FOR_MODULES} "
54- )
48+ message (STATUS "Compiler is: ${CMAKE_CXX_COMPILER_ID} version: ${CMAKE_CXX_COMPILER_VERSION} " )
49+ message (STATUS "Cmake is: ${CMAKE_VERSION} modules scan: ${CMAKE_CXX_SCAN_FOR_MODULES} " )
5550
5651# gersemi: on
5752
58- if (CMAKE_CXX_SCAN_FOR_MODULES)
59- if (NOT DEFINED CMAKE_CXX_STANDARD )
60- set (CMAKE_CXX_STANDARD 23)
61- endif ()
53+ set (BEMAN_SCOPE_TARGETS beman.scope_headers)
6254
63- # TODO(CK): check if possible to enable
64- option (BEMAN_SCOPE_IMPORT_STD "use import std; if possible" OFF )
55+ if (BEMAN_USE_MODULES)
56+ option (BEMAN_SCOPE_IMPORT_STD "Use import std;" ${BEMAN_HAS_IMPORT_STD} )
6557
6658 add_library (beman.scope )
6759
@@ -76,11 +68,14 @@ if(CMAKE_CXX_SCAN_FOR_MODULES)
7668 set_target_properties (beman.scope PROPERTIES CXX_MODULE_STD ON )
7769 target_compile_definitions (beman.scope PUBLIC BEMAN_SCOPE_IMPORT_STD )
7870 endif ()
79- else ()
80- add_library (beman.scope INTERFACE )
81- endif ()
71+ if (BEMAN_SCOPE_USE_DANIELA_ADVICE)
72+ target_compile_definitions (
73+ beman.scope
74+ PUBLIC BEMAN_SCOPE_USE_DANIELA_ADVICE
75+ )
76+ endif ()
77+ add_library (beman::scope ALIAS beman.scope )
8278
83- if (CMAKE_CXX_SCAN_FOR_MODULES)
8479 target_sources (
8580 beman.scope
8681 PUBLIC
@@ -95,25 +90,40 @@ if(CMAKE_CXX_SCAN_FOR_MODULES)
9590 BASE_DIRS include
9691 FILES include /beman/scope/beman.scope.cppm
9792 )
93+
94+ # CMake requires the language standard to be specified as compile feature
95+ # when a target provides C++23 modules and the target will be installed
9896 target_compile_features (beman.scope PUBLIC cxx_std_${CMAKE_CXX_STANDARD} )
99- else ()
100- target_sources (
101- beman.scope
102- INTERFACE
103- FILE_SET HEADERS
104- BASE_DIRS include ${CMAKE_CURRENT_BINARY_DIR}
105- FILES
106- include /beman/scope/scope.hpp
107- include /beman/scope/scope_impl.hpp
108- # NO! ${CMAKE_CURRENT_BINARY_DIR}/beman/scope/modules_export.hpp
109- )
97+
98+ # FIXME: Quickfix only to prevent linker problems on windows dll? CK
99+ if (WIN32 AND BUILD_SHARED_LIBS )
100+ set_target_properties (
101+ beman.scope
102+ PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON
103+ )
104+ endif ()
105+ set_target_properties (beman.scope PROPERTIES EXPORT_NAME scope )
106+ list (APPEND BEMAN_SCOPE_TARGETS beman.scope)
110107endif ()
111108
112- add_library (beman::scope ALIAS beman.scope )
109+ add_library (beman.scope_headers INTERFACE )
110+ target_sources (
111+ beman.scope_headers
112+ INTERFACE
113+ FILE_SET HEADERS
114+ BASE_DIRS include ${CMAKE_CURRENT_BINARY_DIR}
115+ FILES
116+ include /beman/scope/scope.hpp
117+ include /beman/scope/scope_impl.hpp
118+ )
119+
120+ add_library (beman::scope_headers ALIAS beman.scope_headers )
113121
114122set_target_properties (
115- beman.scope
116- PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON EXPORT_NAME scope
123+ beman.scope_headers
124+ PROPERTIES
125+ VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL}
126+ EXPORT_NAME scope_headers
117127)
118128
119129include (GNUInstallDirs )
@@ -122,7 +132,7 @@ set(package_install_dir ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope)
122132
123133# TBD: always? CK
124134install (
125- TARGETS beman.scope
135+ TARGETS ${BEMAN_SCOPE_TARGETS}
126136 COMPONENT beman.scope
127137 EXPORT beman.scope-targets
128138 FILE_SET CXX_MODULES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
0 commit comments