add cmake option XLNT_CXX_LANG to set the targetted cxx standard

- valid options are 11, 14, and 17
- default is 14
- cmake will error if an invalid value is provided
- requires cmake >= 3.10.* to take effect in visual studio
This commit is contained in:
Crzyrndm 2018-07-15 21:23:22 +12:00
parent 25d75cb5c3
commit 5671167d1d
4 changed files with 67 additions and 49 deletions

View File

@ -12,25 +12,6 @@ notifications:
# set up build matrix
matrix:
include:
# ============= CODE COVERAGE ===============
# gcc-6, c++11, debug build, static linking, code coverage enabled
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
- lcov
env:
- CXX_COMPILER=g++-6
- C_COMPILER=gcc-6
- BUILD_TYPE=Debug
- COVERAGE=ON
- STATIC=ON
- SAMPLES=OFF
# ============= GCC ==================
# gcc-6, c++11, debug build, dynamic linking
- os: linux
@ -44,12 +25,13 @@ matrix:
env:
- CXX_COMPILER=g++-6
- C_COMPILER=gcc-6
- CXX_VER=11
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=OFF
- SAMPLES=OFF
# gcc-8, c++11, release build, static linking, samples + benchmarks compiled
# gcc-7, c++14, release build, static linking, samples + benchmarks compiled
- os: linux
compiler: gcc
addons:
@ -61,12 +43,13 @@ matrix:
env:
- CXX_COMPILER=g++-7
- C_COMPILER=gcc-7
- CXX_VER=14
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=ON
- SAMPLES=ON
# gcc-8, c++11, release build, static linking, samples + benchmarks compiled
# gcc-8, c++17, release build, static linking, samples + benchmarks compiled
- os: linux
compiler: gcc
addons:
@ -78,6 +61,7 @@ matrix:
env:
- CXX_COMPILER=g++-8
- C_COMPILER=gcc-8
- CXX_VER=17
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=ON
@ -97,11 +81,13 @@ matrix:
env:
- CXX_COMPILER=clang++-4.0
- C_COMPILER=clang-4.0
- CXX_VER=11
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=OFF
- SAMPLES=OFF
# clang 5, c++11, release build, dynamic linking, samples + benchmarks compiled
# clang 5, c++14, release build, dynamic linking, samples + benchmarks compiled
- os: linux
compiler: clang
addons:
@ -114,11 +100,13 @@ matrix:
env:
- CXX_COMPILER=clang++-5.0
- C_COMPILER=clang-5.0
- CXX_VER=14
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=ON
- SAMPLES=ON
# clang 6, c++11, release build, static linking, samples compiled
# clang 6, c++17, release build, static linking, samples compiled
- os: linux
compiler: clang
addons:
@ -131,10 +119,31 @@ matrix:
env:
- CXX_COMPILER=clang++-6.0
- C_COMPILER=clang-6.0
- CXX_VER=17
- BUILD_TYPE=Release
- COVERAGE=OFF
- STATIC=ON
- SAMPLES=ON
# ============= CODE COVERAGE ===============
# gcc-6, c++11, debug build, static linking, code coverage enabled
- os: linux
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
- lcov
env:
- CXX_COMPILER=g++-6
- C_COMPILER=gcc-6
- CXX_VER=11
- BUILD_TYPE=Debug
- COVERAGE=ON
- STATIC=ON
- SAMPLES=OFF
before_install:
- export CC=${C_COMPILER}
@ -158,7 +167,7 @@ script:
- mkdir build
- cd build
- cmake -D STATIC=$STATIC -D BENCHMARKS=$BENCHMARKS -D SAMPLES=$SAMPLES -D COVERAGE=$COVERAGE -D CMAKE_BUILD_TYPE=$BUILD_TYPE ..
- cmake .. -DXLNT_CXX_LANG=${CXX_VER} -DSTATIC=$STATIC -DBENCHMARKS=$BENCHMARKS -DSAMPLES=$SAMPLES -DCOVERAGE=$COVERAGE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- cmake --build . -- -j2
- ./tests/xlnt.test

View File

@ -7,6 +7,18 @@ set(COMBINED_PROJECT TRUE)
# Library type
option(STATIC "Set to ON to build xlnt as a static library instead of a shared library" OFF)
# c++ language standard to use
set(XLNT_LANGS 11 14 17)
set(XLNT_CXX_LANG "14" CACHE STRING "c++ language features to compile with")
# enumerate allowed values for cmake gui
set_property(CACHE XLNT_CXX_LANG PROPERTY STRINGS ${XLNT_LANGS})
# validate value is in XLNT_LANGS
list(FIND XLNT_LANGS ${XLNT_CXX_LANG} index)
if(index EQUAL -1)
message(FATAL_ERROR "XLNT_CXX_LANG must be one of ${XLNT_LANGS}")
endif()
# Optional components
option(TESTS "Set to OFF to skip building test executable (in ./tests)" ON)
option(SAMPLES "Set to ON to build executable code samples (in ./samples)" OFF)

View File

@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(xlnt VERSION 1.2)
# Require C99 and C++11 compilers
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CXX_EXTENSIONS OFF)
# Project metadata
set(PROJECT_VENDOR "Thomas Fussell")
@ -156,6 +152,8 @@ else()
target_compile_definitions(xlnt PUBLIC XLNT_STATIC=1)
endif()
target_compile_features(xlnt PUBLIC cxx_std_${XLNT_CXX_LANG})
# Includes
target_include_directories(xlnt PUBLIC ${XLNT_INCLUDE_DIR})
target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR})
@ -178,23 +176,23 @@ if(MSVC)
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/cryptography/aes.cpp
PROPERTIES
COMPILE_FLAGS "/wd\"4996\"")
endif()
# Platform- and file-specific settings, Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/miniz.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-undef")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/zstream.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-undef -Wno-shorten-64-to-32")
endif()
# Platform- and file-specific settings, GCC
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/miniz.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-strict-aliasing")
else()
# Platform- and file-specific settings, Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/miniz.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-undef")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/zstream.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-undef -Wno-shorten-64-to-32")
endif()
# Platform- and file-specific settings, GCC
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/detail/serialization/miniz.cpp
PROPERTIES
COMPILE_FLAGS "-Wno-strict-aliasing")
endif()
endif()
# Group files into pseudo-folders in IDEs

View File

@ -1,9 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(xlnt.test)
# Require C++11 compiler
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CXX_EXTENSIONS OFF)
if(NOT COMBINED_PROJECT)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
@ -48,6 +46,7 @@ target_include_directories(xlnt.test
set(XLNT_TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
target_compile_definitions(xlnt.test PRIVATE XLNT_TEST_DATA_DIR=${XLNT_TEST_DATA_DIR})
target_compile_features(xlnt.test PRIVATE cxx_std_${XLNT_CXX_LANG})
if(MSVC)
# bigobj because there are so many headers in one source file