2020-01-13 17:11:20 -05:00
|
|
|
cmake_minimum_required(VERSION 3.1.3...3.16)
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2015-09-23 11:43:36 -04:00
|
|
|
project(GSL CXX)
|
2015-08-20 21:09:14 -04:00
|
|
|
|
2017-07-13 16:53:56 -04:00
|
|
|
include(ExternalProject)
|
2017-08-16 22:00:30 -04:00
|
|
|
find_package(Git)
|
2017-07-13 16:53:56 -04:00
|
|
|
|
2017-04-25 20:08:36 -04:00
|
|
|
# creates a library GSL which is an interface (header files only)
|
|
|
|
add_library(GSL INTERFACE)
|
|
|
|
|
2017-09-06 20:50:30 -04:00
|
|
|
# determine whether this is a standalone project or included by other projects
|
|
|
|
set(GSL_STANDALONE_PROJECT OFF)
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
|
|
set(GSL_STANDALONE_PROJECT ON)
|
|
|
|
endif ()
|
|
|
|
|
2018-06-15 13:13:11 -04:00
|
|
|
set(GSL_CXX_STANDARD "14" CACHE STRING "Use c++ standard")
|
|
|
|
set(GSL_CXX_STD "cxx_std_${GSL_CXX_STANDARD}")
|
2018-06-07 16:36:56 -04:00
|
|
|
|
2018-06-15 13:13:11 -04:00
|
|
|
if (MSVC)
|
|
|
|
set(GSL_CXX_STD_OPT "-std:c++${GSL_CXX_STANDARD}")
|
2018-06-07 16:36:56 -04:00
|
|
|
else()
|
2018-06-15 13:13:11 -04:00
|
|
|
set(GSL_CXX_STD_OPT "-std=c++${GSL_CXX_STANDARD}")
|
2018-06-07 16:36:56 -04:00
|
|
|
endif()
|
|
|
|
|
2017-04-25 20:08:36 -04:00
|
|
|
# when minimum version required is 3.8.0 remove if below
|
|
|
|
# both branches do exactly the same thing
|
2018-02-13 20:26:44 -05:00
|
|
|
if (CMAKE_VERSION VERSION_LESS 3.7.9)
|
2018-06-15 13:13:11 -04:00
|
|
|
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}")
|
2018-06-07 16:36:56 -04:00
|
|
|
else()
|
2018-06-15 13:13:11 -04:00
|
|
|
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no c++${GSL_CXX_STANDARD} support. Please use a different C++ compiler.")
|
2017-04-25 20:08:36 -04:00
|
|
|
endif()
|
|
|
|
else ()
|
2018-06-15 13:13:11 -04:00
|
|
|
target_compile_features(GSL INTERFACE "${GSL_CXX_STD}")
|
2017-04-25 20:08:36 -04:00
|
|
|
# on *nix systems force the use of -std=c++XX instead of -std=gnu++XX (default)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# add definitions to the library and targets that consume it
|
|
|
|
target_compile_definitions(GSL INTERFACE
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:
|
|
|
|
# remove unnecessary warnings about unchecked iterators
|
|
|
|
_SCL_SECURE_NO_WARNINGS
|
2018-06-15 13:13:11 -04:00
|
|
|
# remove deprecation warnings about std::uncaught_exception() (from catch)
|
|
|
|
_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING
|
2017-04-25 20:08:36 -04:00
|
|
|
>
|
|
|
|
)
|
|
|
|
|
|
|
|
# add include folders to the library and targets that consume it
|
2018-11-28 18:37:59 -05:00
|
|
|
# the SYSTEM keyword suppresses warnings for users of the library
|
|
|
|
if(GSL_STANDALONE_PROJECT)
|
|
|
|
target_include_directories(GSL INTERFACE
|
|
|
|
$<BUILD_INTERFACE:
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
>
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
target_include_directories(GSL SYSTEM INTERFACE
|
|
|
|
$<BUILD_INTERFACE:
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-04-25 20:08:36 -04:00
|
|
|
|
2019-01-14 19:43:17 -05:00
|
|
|
if (CMAKE_VERSION VERSION_GREATER 3.7.8)
|
2018-04-27 15:56:25 -04:00
|
|
|
if (MSVC_IDE)
|
|
|
|
option(VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE)
|
|
|
|
else()
|
|
|
|
set(VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE)
|
|
|
|
endif()
|
2017-11-28 10:31:06 -05:00
|
|
|
|
2018-04-27 15:56:25 -04:00
|
|
|
# add natvis file to the library so it will automatically be loaded into Visual Studio
|
|
|
|
if(VS_ADD_NATIVE_VISUALIZERS)
|
|
|
|
target_sources(GSL INTERFACE
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis
|
|
|
|
)
|
|
|
|
endif()
|
2017-11-28 10:31:06 -05:00
|
|
|
endif()
|
2017-04-25 20:08:36 -04:00
|
|
|
|
2017-02-07 18:59:37 -05:00
|
|
|
install(
|
|
|
|
DIRECTORY include/gsl
|
|
|
|
DESTINATION include
|
2015-11-21 14:13:21 -05:00
|
|
|
)
|
|
|
|
|
2017-09-06 20:50:30 -04:00
|
|
|
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
|
|
|
if (GSL_TEST)
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif ()
|