Skip to content

Commit

Permalink
Allow setting C++ version to compile with in CMake config
Browse files Browse the repository at this point in the history
Set CMAKE_CXX_STANDARD to 11, 14, 17, ...
  • Loading branch information
joto committed Dec 21, 2021
1 parent bbb2a95 commit ebd2e4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/actions/cmake/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ runs:
run: |
cmake -LA .. \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DPROTOZERO_DATA_VIEW=$PROTOZERO_DATA_VIEW
-DPROTOZERO_DATA_VIEW=${PROTOZERO_DATA_VIEW} \
-DCMAKE_CXX_STANDARD=${CPP_VERSION}
shell: bash
working-directory: build
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ jobs:
- "fedora:35" # gcc 11.2.1, clang 13.0.0, cmake 3.22.0
build_type: [Debug]
cpp_compiler: [g++]
cpp_version: [c++11]
cpp_version: [11]
include:
- image: "debian:bullseye"
cpp_version: c++17
cpp_version: 14
- image: "debian:bullseye"
cpp_version: c++20
cpp_version: 17
- image: "debian:bullseye"
cpp_version: 20
- image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
cpp_version: 14
- image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++17
cpp_version: 17
- image: "debian:bullseye"
c_compiler: clang
cpp_compiler: clang++
cpp_version: c++20
cpp_version: 20
- image: "debian:bullseye"
build_type: Release
- image: "debian:bullseye"
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#-----------------------------------------------------------------------------

if (NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 11)
endif()
message(STATUS "Building in C++${CMAKE_CXX_STANDARD} mode")
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#-----------------------------------------------------------------------------

option(BUILD_TESTING "Build tests" ON)
option(WERROR "Add -Werror flag to build (turns warnings into errors)" ON)

if(MSVC)
add_compile_options(/W3)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
else()
add_compile_options(-std=c++11 -Wall -Wextra -pedantic -Wsign-compare -Wunused-parameter -Wno-float-equal -Wno-covered-switch-default)
add_compile_options(-Wall -Wextra -pedantic -Wsign-compare -Wunused-parameter -Wno-float-equal -Wno-covered-switch-default)
if(WERROR)
add_compile_options(-Werror)
endif()
Expand Down

0 comments on commit ebd2e4f

Please sign in to comment.