blob: e62a1d60b626a94acd25f85af636a15f61bd79a8 [file] [log] [blame]
Neil MacIntoshb2ee4842017-07-13 13:53:56 -07001cmake_minimum_required(VERSION 3.1.3)
Neil MacIntosha9dcbe02015-08-20 18:09:14 -07002
Tamas Kenez9b454b72015-09-23 17:43:36 +02003project(GSL CXX)
Neil MacIntosha9dcbe02015-08-20 18:09:14 -07004
Neil MacIntoshb2ee4842017-07-13 13:53:56 -07005include(ExternalProject)
6find_package(Git REQUIRED)
7
Tiago8b320e32017-04-25 17:08:36 -07008# creates a library GSL which is an interface (header files only)
9add_library(GSL INTERFACE)
10
11# when minimum version required is 3.8.0 remove if below
12# both branches do exactly the same thing
Neil MacIntoshb2ee4842017-07-13 13:53:56 -070013if (CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9)
Tiago8b320e32017-04-25 17:08:36 -070014 if (NOT MSVC)
15 include(CheckCXXCompilerFlag)
16 CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
17 if(COMPILER_SUPPORTS_CXX14)
18 target_compile_options(GSL INTERFACE "-std=c++14")
19 else()
20 message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
21 endif()
Neil MacIntoshb2ee4842017-07-13 13:53:56 -070022
Tiago8b320e32017-04-25 17:08:36 -070023 endif()
24else ()
25 # set the GSL library to be compiled only with c++14
26 target_compile_features(GSL INTERFACE cxx_std_14)
27 # on *nix systems force the use of -std=c++XX instead of -std=gnu++XX (default)
28 set(CMAKE_CXX_EXTENSIONS OFF)
29endif()
30
31# add definitions to the library and targets that consume it
32target_compile_definitions(GSL INTERFACE
33 $<$<CXX_COMPILER_ID:MSVC>:
34 # remove unnecessary warnings about unchecked iterators
35 _SCL_SECURE_NO_WARNINGS
36 >
37)
38
39# add include folders to the library and targets that consume it
40target_include_directories(GSL INTERFACE
41 $<BUILD_INTERFACE:
42 ${CMAKE_CURRENT_SOURCE_DIR}/include
43 >
44)
45
46# add natvis file to the library so it will automatically be loaded into Visual Studio
Neil MacIntoshb2ee4842017-07-13 13:53:56 -070047target_sources(GSL INTERFACE
Tiago8b320e32017-04-25 17:08:36 -070048 ${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis
49)
50
Casey Carter4e8f95b2017-02-07 15:59:37 -080051install(
52 DIRECTORY include/gsl
53 DESTINATION include
Jason Horsburgh75051112015-11-21 19:13:21 +000054)
55
Neil MacIntosha9dcbe02015-08-20 18:09:14 -070056enable_testing()
Tamas Kenez9b454b72015-09-23 17:43:36 +020057add_subdirectory(tests)