Skip to content

Commit f01699f

Browse files
committed
Trying more compilers
1 parent 11c1278 commit f01699f

File tree

5 files changed

+140
-9
lines changed

5 files changed

+140
-9
lines changed

.github/workflows/build.yml

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
- 'cmake/**'
2222

2323
jobs:
24-
build-cxx23:
24+
linux-cxx23:
2525
runs-on:
2626
group: default
2727
strategy:
@@ -84,7 +84,7 @@ jobs:
8484
cd .build
8585
ctest -L cxx23 --output-on-failure
8686
87-
build-cxx20:
87+
linux-cxx20:
8888
runs-on:
8989
group: default
9090
strategy:
@@ -143,3 +143,105 @@ jobs:
143143
run: |
144144
cd .build
145145
ctest -L cxx20 --output-on-failure
146+
147+
macos-cxx23:
148+
runs-on: macos-${{ matrix.env.osver }}
149+
strategy:
150+
fail-fast: false
151+
matrix:
152+
configuration:
153+
- Debug
154+
- Release
155+
env:
156+
- compiler: clang++
157+
osver: 15
158+
- compiler: "$(brew --prefix llvm@18)/bin/clang++"
159+
osver: 15
160+
steps:
161+
- uses: actions/checkout@v4
162+
163+
- name: Prepare build
164+
run: |
165+
mkdir .build
166+
cd .build
167+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_CXX_COMPILER=${{ matrix.env.compiler }} ..
168+
COMPILER=$( grep -E "^CMAKE_CXX_COMPILER:FILEPATH=" CMakeCache.txt | sed -e "s|^[^=]*=||" )
169+
FLAGS=$( grep -iE "^CMAKE_CXX_FLAGS:STRING=" CMakeCache.txt | sed -e "s|^[^=]*=||" )
170+
printf "C++ compiler: %s\n" "$COMPILER"
171+
printf "C++ compiler version: %s\n" "$( $COMPILER --version | head -1 )"
172+
printf "C++ compilation options: %s\n" "$FLAGS"
173+
174+
- name: Build all
175+
run: |
176+
cd .build
177+
cmake --build . --target cxx23
178+
179+
- name: Run tests
180+
run: |
181+
cd .build
182+
ctest -L cxx23 -C ${{ matrix.configuration }} --output-on-failure
183+
184+
macos-cxx20:
185+
runs-on: macos-${{ matrix.env.osver }}
186+
strategy:
187+
fail-fast: false
188+
matrix:
189+
configuration:
190+
- Debug
191+
- Release
192+
env:
193+
- compiler: clang++
194+
osver: 15
195+
steps:
196+
- uses: actions/checkout@v4
197+
198+
- name: Prepare build
199+
run: |
200+
mkdir .build
201+
cd .build
202+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_CXX_COMPILER=${{ matrix.env.compiler }} ..
203+
COMPILER=$( grep -E "^CMAKE_CXX_COMPILER:FILEPATH=" CMakeCache.txt | sed -e "s|^[^=]*=||" )
204+
FLAGS=$( grep -iE "^CMAKE_CXX_FLAGS:STRING=" CMakeCache.txt | sed -e "s|^[^=]*=||" )
205+
printf "C++ compiler: %s\n" "$COMPILER"
206+
printf "C++ compiler version: %s\n" "$( $COMPILER --version | head -1 )"
207+
printf "C++ compilation options: %s\n" "$FLAGS"
208+
209+
- name: Build all
210+
run: |
211+
cd .build
212+
cmake --build . --target cxx20
213+
214+
- name: Run tests
215+
run: |
216+
cd .build
217+
ctest -L cxx20 -C ${{ matrix.configuration }} --output-on-failure
218+
219+
windows-cxx20:
220+
runs-on: windows-${{ matrix.env.osver }}
221+
strategy:
222+
fail-fast: false
223+
matrix:
224+
configuration:
225+
- Debug
226+
- Release
227+
env:
228+
- vsver: "Visual Studio 17 2022"
229+
osver: 2025
230+
steps:
231+
- uses: actions/checkout@v4
232+
233+
- name: Prepare build
234+
run: |
235+
mkdir .build
236+
cd .build
237+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "${{ matrix.env.vsver }}" -A x64 ..
238+
239+
- name: Build all
240+
run: |
241+
cd .build
242+
cmake --build . --target cxx20
243+
244+
- name: Run tests
245+
run: |
246+
cd .build
247+
ctest -L cxx20 -C ${{ matrix.configuration }} --output-on-failure

cmake/CompilationOptions.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Add compilation options appropriate for the current compiler
2+
3+
function(append_compilation_options)
4+
set(options WARNINGS OPTIMIZATION)
5+
set(oneValueArgs NAME)
6+
cmake_parse_arguments(Options "${options}" "${oneValueArgs}" "" ${ARGN})
7+
8+
if(NOT DEFINED Options_NAME)
9+
message(FATAL_ERROR "NAME must be set")
10+
endif()
11+
12+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
13+
if(Options_WARNINGS)
14+
target_compile_options(${Options_NAME} PRIVATE /W4)
15+
endif()
16+
17+
if(Options_OPTIMIZATION)
18+
target_compile_options(${Options_NAME} PRIVATE $<IF:$<CONFIG:Debug>,/Od,/Ox>)
19+
endif()
20+
else()
21+
if(Options_WARNINGS)
22+
target_compile_options(${Options_NAME} PRIVATE -Wall -Wextra -Wpedantic)
23+
endif()
24+
25+
if(Options_OPTIMIZATION)
26+
target_compile_options(${Options_NAME} PRIVATE $<IF:$<CONFIG:Debug>,-O0,-O2>)
27+
endif()
28+
endif()
29+
endfunction()

cmake/TargetGenerator.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function(create_target_for_file)
44
set(oneValueArgs NAME SOURCE SOURCE_ROOT NEW_SOURCE)
5-
set(multiValueArgs DEPENDENCIES COMPILE_OPTIONS)
5+
set(multiValueArgs DEPENDENCIES)
66
cmake_parse_arguments(Generator "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
77

88
if(NOT DEFINED Generator_SOURCE)
@@ -27,6 +27,4 @@ function(create_target_for_file)
2727
endif()
2828

2929
target_link_libraries(${Generator_NAME} ${Generator_DEPENDENCIES})
30-
31-
target_compile_options(${Generator_NAME} PRIVATE ${Generator_COMPILE_OPTIONS})
3230
endfunction()

include/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ install(TARGETS include_pfn
2828
DESTINATION include)
2929

3030
include(TargetGenerator)
31+
include(CompilationOptions)
3132

3233
# Generate sentinel target for each individual header, as a basic sanity check
3334
foreach(cxxrel 20 23)
@@ -41,8 +42,8 @@ foreach(cxxrel 20 23)
4142
NEW_SOURCE "#include <${source}>\nint main() {}\n"
4243
SOURCE_ROOT "${CMAKE_BINARY_DIR}/sentinel"
4344
DEPENDENCIES include_pfn
44-
COMPILE_OPTIONS -Wall -Wextra -Wpedantic
4545
)
46+
append_compilation_options(NAME "${target}" WARNINGS)
4647
add_dependencies("cxx${cxxrel}" "${target}")
4748
set_property(TARGET "${target}" PROPERTY CXX_STANDARD "${cxxrel}")
4849

@@ -112,8 +113,8 @@ foreach(cxxrel 23)
112113
NEW_SOURCE "#include <${source}>\nint main() {}\n"
113114
SOURCE_ROOT "${CMAKE_BINARY_DIR}/sentinel"
114115
DEPENDENCIES include_fn
115-
COMPILE_OPTIONS -Wall -Wextra -Wpedantic
116116
)
117+
append_compilation_options(NAME "${target}" WARNINGS)
117118
add_dependencies("cxx${cxxrel}" "${target}")
118119
set_property(TARGET "${target}" PROPERTY CXX_STANDARD "${cxxrel}")
119120

tests/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(TESTS_PFN_SOURCES
2020
)
2121

2222
include(TargetGenerator)
23+
include(CompilationOptions)
2324

2425
# Generate separate target for each individual test source
2526
foreach(cxxrel 20 23)
@@ -31,8 +32,8 @@ foreach(cxxrel 20 23)
3132
NAME "${target}"
3233
SOURCE "${source}"
3334
DEPENDENCIES include_pfn Catch2::Catch2WithMain
34-
COMPILE_OPTIONS -Wall -Wextra -Wpedantic "$<$<CONFIG:DEBUG>:-O0>"
3535
)
36+
append_compilation_options(NAME "${target}" WARNINGS OPTIMIZATION)
3637
add_dependencies("cxx${cxxrel}" "${target}")
3738
set_property(TARGET "${target}" PROPERTY CXX_STANDARD "${cxxrel}")
3839

@@ -87,8 +88,8 @@ foreach(cxxrel 23)
8788
NAME "${target}"
8889
SOURCE "${source}"
8990
DEPENDENCIES include_fn tests_util Catch2::Catch2WithMain
90-
COMPILE_OPTIONS -Wall -Wextra -Wpedantic "$<$<CONFIG:DEBUG>:-O0>"
9191
)
92+
append_compilation_options(NAME "${target}" WARNINGS OPTIMIZATION)
9293
add_dependencies("cxx${cxxrel}" "${target}")
9394
set_property(TARGET "${target}" PROPERTY CXX_STANDARD "${cxxrel}")
9495

0 commit comments

Comments
 (0)