diff --git a/.travis.yml b/.travis.yml index c373da2..bb32890 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,23 +23,23 @@ matrix: ########################################################################## # XCode 8.3 - - env: COMPILER=clang++ BUILD_TYPE=Debug + - env: COMPILER=clang++ BUILD_TYPE=Debug GSL_CXX_STANDARD=14 os: osx osx_image: xcode8.3 compiler: clang - - env: COMPILER=clang++ BUILD_TYPE=Release + - env: COMPILER=clang++ BUILD_TYPE=Release GSL_CXX_STANDARD=14 os: osx osx_image: xcode8.3 compiler: clang # XCode 9.1 - - env: COMPILER=clang++ BUILD_TYPE=Debug + - env: COMPILER=clang++ BUILD_TYPE=Debug GSL_CXX_STANDARD=14 os: osx osx_image: xcode9.1 compiler: clang - - env: COMPILER=clang++ BUILD_TYPE=Release + - env: COMPILER=clang++ BUILD_TYPE=Release GSL_CXX_STANDARD=14 os: osx osx_image: xcode9.1 compiler: clang @@ -49,7 +49,7 @@ matrix: ########################################################################## # Clang 3.6 - - env: COMPILER=clang++-3.6 BUILD_TYPE=Debug + - env: COMPILER=clang++-3.6 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang36 apt: packages: @@ -59,11 +59,11 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.6 - - env: COMPILER=clang++-3.6 BUILD_TYPE=Release + - env: COMPILER=clang++-3.6 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *clang36 # Clang 3.7 - - env: COMPILER=clang++-3.7 BUILD_TYPE=Debug + - env: COMPILER=clang++-3.7 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang37 apt: packages: @@ -73,11 +73,11 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.7 - - env: COMPILER=clang++-3.7 BUILD_TYPE=Release + - env: COMPILER=clang++-3.7 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *clang37 # Clang 3.8 - - env: COMPILER=clang++-3.8 BUILD_TYPE=Debug + - env: COMPILER=clang++-3.8 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang38 apt: packages: @@ -87,11 +87,11 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.8 - - env: COMPILER=clang++-3.8 BUILD_TYPE=Release + - env: COMPILER=clang++-3.8 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *clang38 # Clang 3.9 - - env: COMPILER=clang++-3.9 BUILD_TYPE=Debug + - env: COMPILER=clang++-3.9 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang39 apt: packages: @@ -101,11 +101,11 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.9 - - env: COMPILER=clang++-3.9 BUILD_TYPE=Release + - env: COMPILER=clang++-3.9 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *clang39 # Clang 4.0 - - env: COMPILER=clang++-4.0 BUILD_TYPE=Debug + - env: COMPILER=clang++-4.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang40 apt: packages: @@ -115,11 +115,11 @@ matrix: - ubuntu-toolchain-r-test - llvm-toolchain-trusty-4.0 - - env: COMPILER=clang++-4.0 BUILD_TYPE=Release + - env: COMPILER=clang++-4.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *clang40 # Clang 5.0 - - env: COMPILER=clang++-5.0 BUILD_TYPE=Debug + - env: COMPILER=clang++-5.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &clang50 apt: packages: @@ -131,46 +131,76 @@ matrix: - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-5.0 main' key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - env: COMPILER=clang++-5.0 BUILD_TYPE=Release - addons: *clang50 + - env: COMPILER=clang++-5.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14 + addons: *clang50 + + # Clang 6.0 + - env: COMPILER=clang++-6.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 + addons: &clang60 + apt: + packages: + - clang-6.0 + - g++-6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-6.0 + - sourceline: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + + - env: COMPILER=clang++-6.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14 + addons: *clang60 + + # Does not work due to #695 + # Clang 6.0 c++17 + #- env: COMPILER=clang++-6.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=17 + # addons: *clang60 + + #- env: COMPILER=clang++-6.0 BUILD_TYPE=Release GSL_CXX_STANDARD=17 + # addons: *clang60 ########################################################################## # GCC on Linux ########################################################################## # GCC 5 - - env: COMPILER=g++-5 BUILD_TYPE=Debug + - env: COMPILER=g++-5 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &gcc5 apt: packages: g++-5 sources: - ubuntu-toolchain-r-test - - env: COMPILER=g++-5 BUILD_TYPE=Release + - env: COMPILER=g++-5 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *gcc5 # GCC 6 - - env: COMPILER=g++-6 BUILD_TYPE=Debug + - env: COMPILER=g++-6 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &gcc6 apt: packages: g++-6 sources: - ubuntu-toolchain-r-test - - env: COMPILER=g++-6 BUILD_TYPE=Release + - env: COMPILER=g++-6 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *gcc6 # GCC 7 - - env: COMPILER=g++-7 BUILD_TYPE=Debug + - env: COMPILER=g++-7 BUILD_TYPE=Debug GSL_CXX_STANDARD=14 addons: &gcc7 apt: packages: g++-7 sources: - ubuntu-toolchain-r-test - - env: COMPILER=g++-7 BUILD_TYPE=Release + - env: COMPILER=g++-7 BUILD_TYPE=Release GSL_CXX_STANDARD=14 addons: *gcc7 + # GCC 7 c++17 + - env: COMPILER=g++-7 BUILD_TYPE=Debug GSL_CXX_STANDARD=17 + addons: *gcc7 + + - env: COMPILER=g++-7 BUILD_TYPE=Release GSL_CXX_STANDARD=17 + addons: *gcc7 install: # Set the ${CXX} variable properly @@ -230,7 +260,7 @@ before_script: # have CMake to generate build files - cd "${TRAVIS_BUILD_DIR}" - mkdir build && cd build - - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE + - cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DGSL_CXX_STANDARD=$GSL_CXX_STANDARD script: # build and run tests diff --git a/CMakeLists.txt b/CMakeLists.txt index e96fb64..b0de85d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,32 +14,28 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(GSL_STANDALONE_PROJECT ON) endif () +set(GSL_CXX_STANDARD "14" CACHE STRING "Use c++ standard") +set(GSL_CXX_STD "cxx_std_${GSL_CXX_STANDARD}") -include(CheckCXXCompilerFlag) -if (NOT MSVC) - CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) +if (MSVC) + set(GSL_CXX_STD_OPT "-std:c++${GSL_CXX_STANDARD}") else() - CHECK_CXX_COMPILER_FLAG("-std:c++14" COMPILER_SUPPORTS_CXX14) + set(GSL_CXX_STD_OPT "-std=c++${GSL_CXX_STANDARD}") endif() # when minimum version required is 3.8.0 remove if below # both branches do exactly the same thing if (CMAKE_VERSION VERSION_LESS 3.7.9) - if (NOT MSVC) - if(COMPILER_SUPPORTS_CXX14) - target_compile_options(GSL INTERFACE "-std=c++14") - else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.") - endif() + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG("${GSL_CXX_STD_OPT}" COMPILER_SUPPORTS_CXX_STANDARD) + + if(COMPILER_SUPPORTS_CXX_STANDARD) + target_compile_options(GSL INTERFACE "${GSL_CXX_STD_OPT}") else() - if(COMPILER_SUPPORTS_CXX14) - target_compile_options(GSL INTERFACE "-std:c++14") - else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.") - endif() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no c++${GSL_CXX_STANDARD} support. Please use a different C++ compiler.") endif() else () - target_compile_features(GSL INTERFACE cxx_std_14) + target_compile_features(GSL INTERFACE "${GSL_CXX_STD}") # on *nix systems force the use of -std=c++XX instead of -std=gnu++XX (default) set(CMAKE_CXX_EXTENSIONS OFF) endif() @@ -49,6 +45,8 @@ target_compile_definitions(GSL INTERFACE $<$: # remove unnecessary warnings about unchecked iterators _SCL_SECURE_NO_WARNINGS + # remove deprecation warnings about std::uncaught_exception() (from catch) + _SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING > ) diff --git a/appveyor.yml b/appveyor.yml index d978a5d..2fc8a16 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,6 +12,16 @@ image: - Visual Studio 2015 - Visual Studio 2017 +environment: + matrix: + - GSL_CXX_STANDARD: 14 + - GSL_CXX_STANDARD: 17 + +matrix: + exclude: + - image: Visual Studio 2015 + GSL_CXX_STANDARD: 17 + cache: - C:\cmake-3.8.0-win32-x86 @@ -27,6 +37,7 @@ before_build: - ps: | mkdir build cd build + if ("$env:APPVEYOR_JOB_NAME" -match "Image: Visual Studio 2015") { $env:generator="Visual Studio 14 2015" } else { @@ -36,7 +47,7 @@ before_build: $env:generator="$env:generator Win64" } echo generator="$env:generator" - cmake .. -G "$env:generator" + cmake .. -G "$env:generator" -DGSL_CXX_STANDARD="$env:GSL_CXX_STANDARD" build_script: - cmake --build . --config %CONFIGURATION% -- /m /v:minimal diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e08d77..b5e9bb2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,10 @@ else() add_custom_target(catch) endif() +if (MSVC AND (GSL_CXX_STANDARD EQUAL 17)) + set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus) +endif() + # this interface adds compile options to how the tests are run # please try to keep entries ordered =) add_library(gsl_tests_config INTERFACE) @@ -35,6 +39,7 @@ target_compile_options(gsl_tests_config INTERFACE /W4 /WX > + ${GSL_CPLUSPLUS_OPT} $<$>: -fno-strict-aliasing -Wall @@ -122,6 +127,7 @@ target_compile_options(gsl_tests_config_noexcept INTERFACE /W4 /WX > + ${GSL_CPLUSPLUS_OPT} $<$>: -fno-strict-aliasing -fno-exceptions