Skip to content

Commit 4a35cc4

Browse files
committed
Next steps with import std;
CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is still needed Build and install always a header only lib Fix some clang-tidy warnings pre-commit autoupdate
1 parent 3d810f1 commit 4a35cc4

18 files changed

Lines changed: 467 additions & 146 deletions

.github/workflows/ci_tests.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ on:
1313

1414
jobs:
1515
beman-submodule-check:
16-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-submodule-check.yml@1.2.1
16+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-submodule-check.yml@1.3.0
1717

1818
preset-test:
19-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-preset-test.yml@1.2.1
19+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-preset-test.yml@1.3.0
2020
with:
2121
matrix_config: >
2222
[
@@ -31,7 +31,7 @@ jobs:
3131
]
3232
3333
build-and-test:
34-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-build-and-test.yml@1.2.1
34+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-build-and-test.yml@1.3.0
3535
with:
3636
matrix_config: >
3737
{
@@ -42,9 +42,9 @@ jobs:
4242
"tests": [
4343
{ "stdlibs": ["libstdc++"],
4444
"tests": [
45-
"Debug.Default", "Release.Default", "Release.TSan",
46-
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic",
47-
"Debug.Coverage"
45+
"Debug.Default", "Release.Default", "Release.MaxSan",
46+
"Debug.Coverage", "Debug.Werror",
47+
"Debug.Dynamic", "Release.Dynamic"
4848
]
4949
}
5050
]
@@ -69,8 +69,8 @@ jobs:
6969
"tests": [
7070
{ "stdlibs": ["libc++"],
7171
"tests": [
72-
"Debug.Default", "Release.Default", "Release.TSan",
73-
"Release.MaxSan", "Debug.Werror", "Debug.Dynamic"
72+
"Debug.Default", "Release.Default", "Release.MaxSan",
73+
"Debug.Dynamic", "Release.Dynamic"
7474
]
7575
}
7676
]
@@ -107,7 +107,9 @@ jobs:
107107
{ "cxxversions": ["c++23"],
108108
"tests": [
109109
{ "stdlibs": ["stl"],
110-
"tests": ["Debug.Default", "Release.Default", "Release.MaxSan"]
110+
"tests": ["Debug.Default", "Release.Default", "Release.MaxSan",
111+
"Debug.Dynamic", "Release.Dynamic"
112+
]
111113
}
112114
]
113115
}
@@ -119,4 +121,4 @@ jobs:
119121
create-issue-when-fault:
120122
needs: [preset-test, build-and-test]
121123
if: failure() && github.event_name == 'schedule'
122-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-create-issue-when-fault.yml@1.2.1
124+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-create-issue-when-fault.yml@1.3.0

.github/workflows/pre-commit-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ on:
1010

1111
jobs:
1212
pre-commit:
13-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-pre-commit.yml@1.2.1
13+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-pre-commit.yml@1.3.0

.github/workflows/pre-commit-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
auto-update-pre-commit:
12-
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-update-pre-commit.yml@1.2.1
12+
uses: bemanproject/infra-workflows/.github/workflows/reusable-beman-update-pre-commit.yml@1.3.0
1313
secrets:
1414
APP_ID: ${{ secrets.AUTO_PR_BOT_APP_ID }}
1515
PRIVATE_KEY: ${{ secrets.AUTO_PR_BOT_PRIVATE_KEY }}

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@ repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v6.0.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
1010
exclude: ^\.clang-(format|tidy)$
11-
- id: check-added-large-files
11+
- id: check-added-large-files
1212

1313
# Clang-format for C++
1414
# This brings in a portable version of clang-format.
1515
# See also: https://github.com/ssciwr/clang-format-wheel
1616
- repo: https://github.com/pre-commit/mirrors-clang-format
1717
rev: v22.1.0
1818
hooks:
19-
- id: clang-format
20-
types_or: [c++, c, json]
19+
- id: clang-format
20+
types_or: [c++, c, json]
2121

2222
# CMake linting and formatting
2323
- repo: https://github.com/BlankSpruce/gersemi
2424
rev: 0.26.0
2525
hooks:
26-
- id: gersemi
27-
name: CMake linting
28-
exclude: ^.*/tests/.*/data/ # Exclude test data directories
26+
- id: gersemi
27+
name: CMake linting
28+
exclude: ^.*/tests/.*/data/ # Exclude test data directories
2929

3030
# Markdown linting
3131
# Config file: .markdownlint.yaml
32-
# Commented out to disable this by default. Uncomment to enable markdown linting.
32+
# Commented out to disable this by default. Uncomment to enable markdown linting.
3333
# - repo: https://github.com/igorshubovych/markdownlint-cli
34-
# rev: v0.46.0
34+
# rev: v0.47.0
3535
# hooks:
36-
# - id: markdownlint
36+
# - id: markdownlint
3737

3838
- repo: https://github.com/codespell-project/codespell
3939
rev: v2.4.1

CMakeLists.txt

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22

33
cmake_minimum_required(VERSION 3.30...4.3)
44

5+
include(./cmake/prelude.cmake)
6+
57
project(
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)
2324
endif()
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]
3029
option(
@@ -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)
110107
endif()
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

114122
set_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

119129
include(GNUInstallDirs)
@@ -122,7 +132,7 @@ set(package_install_dir ${CMAKE_INSTALL_LIBDIR}/cmake/beman.scope)
122132

123133
# TBD: always? CK
124134
install(
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}

CMakePresets.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"generator": "Ninja",
88
"binaryDir": "${sourceDir}/build/${presetName}",
99
"cacheVariables": {
10+
"BEMAN_SCOPE_USE_DANIELA_ADVICE": true,
11+
"BEMAN_USE_MODULES": true,
1012
"BEMAN_USE_STD_MODULE": true,
11-
"CMAKE_CXX_EXTENSIONS": true,
12-
"CMAKE_CXX_SCAN_FOR_MODULES": true,
1313
"CMAKE_CXX_STANDARD": "23",
14+
"CMAKE_CXX_EXTENSIONS": true,
1415
"CMAKE_CXX_STANDARD_REQUIRED": true,
1516
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
17+
"CMAKE_INSTALL_MESSAGE": "LAZY",
1618
"CMAKE_SKIP_TEST_ALL_DEPENDENCY": false,
1719
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "infra/cmake/use-fetch-content.cmake"
1820
}
@@ -73,7 +75,6 @@
7375
"_debug-base"
7476
],
7577
"cacheVariables": {
76-
"BEMAN_USE_STD_MODULE": false,
7778
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
7879
},
7980
"environment": {
@@ -89,7 +90,6 @@
8990
"_release-base"
9091
],
9192
"cacheVariables": {
92-
"BEMAN_USE_STD_MODULE": false,
9393
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/llvm-libc++-toolchain.cmake"
9494
},
9595
"environment": {
@@ -106,7 +106,7 @@
106106
],
107107
"cacheVariables": {
108108
"BEMAN_USE_STD_MODULE": false,
109-
"CMAKE_CXX_SCAN_FOR_MODULES": false,
109+
"BEMAN_USE_MODULES": false,
110110
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
111111
}
112112
},
@@ -119,7 +119,7 @@
119119
],
120120
"cacheVariables": {
121121
"BEMAN_USE_STD_MODULE": false,
122-
"CMAKE_CXX_SCAN_FOR_MODULES": false,
122+
"BEMAN_USE_MODULES": false,
123123
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/appleclang-toolchain.cmake"
124124
}
125125
},
@@ -131,8 +131,12 @@
131131
"_debug-base"
132132
],
133133
"cacheVariables": {
134-
"BUILD_SHARED_LIBS": false,
135134
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
135+
},
136+
"condition": {
137+
"type": "equals",
138+
"lhs": "${hostSystemName}",
139+
"rhs": "Windows"
136140
}
137141
},
138142
{
@@ -143,8 +147,12 @@
143147
"_release-base"
144148
],
145149
"cacheVariables": {
146-
"BUILD_SHARED_LIBS": false,
147150
"CMAKE_TOOLCHAIN_FILE": "infra/cmake/msvc-toolchain.cmake"
151+
},
152+
"condition": {
153+
"type": "equals",
154+
"lhs": "${hostSystemName}",
155+
"rhs": "Windows"
148156
}
149157
}
150158
],

0 commit comments

Comments
 (0)