Neil MacIntosh | b2ee484 | 2017-07-13 13:53:56 -0700 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.1.3) |
Neil MacIntosh | a9dcbe0 | 2015-08-20 18:09:14 -0700 | [diff] [blame] | 2 | |
Tamas Kenez | 9b454b7 | 2015-09-23 17:43:36 +0200 | [diff] [blame] | 3 | project(GSL CXX) |
Neil MacIntosh | a9dcbe0 | 2015-08-20 18:09:14 -0700 | [diff] [blame] | 4 | |
Neil MacIntosh | b2ee484 | 2017-07-13 13:53:56 -0700 | [diff] [blame] | 5 | include(ExternalProject) |
| 6 | find_package(Git REQUIRED) |
| 7 | |
Tiago | 8b320e3 | 2017-04-25 17:08:36 -0700 | [diff] [blame] | 8 | # creates a library GSL which is an interface (header files only) |
| 9 | add_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 MacIntosh | b2ee484 | 2017-07-13 13:53:56 -0700 | [diff] [blame] | 13 | if (CMAKE_MAJOR_VERSION VERSION_LESS 3.7.9) |
Tiago | 8b320e3 | 2017-04-25 17:08:36 -0700 | [diff] [blame] | 14 | 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 MacIntosh | b2ee484 | 2017-07-13 13:53:56 -0700 | [diff] [blame] | 22 | |
Tiago | 8b320e3 | 2017-04-25 17:08:36 -0700 | [diff] [blame] | 23 | endif() |
| 24 | else () |
| 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) |
| 29 | endif() |
| 30 | |
| 31 | # add definitions to the library and targets that consume it |
| 32 | target_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 |
| 40 | target_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 MacIntosh | b2ee484 | 2017-07-13 13:53:56 -0700 | [diff] [blame] | 47 | target_sources(GSL INTERFACE |
Tiago | 8b320e3 | 2017-04-25 17:08:36 -0700 | [diff] [blame] | 48 | ${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis |
| 49 | ) |
| 50 | |
Casey Carter | 4e8f95b | 2017-02-07 15:59:37 -0800 | [diff] [blame] | 51 | install( |
| 52 | DIRECTORY include/gsl |
| 53 | DESTINATION include |
Jason Horsburgh | 7505111 | 2015-11-21 19:13:21 +0000 | [diff] [blame] | 54 | ) |
| 55 | |
Neil MacIntosh | a9dcbe0 | 2015-08-20 18:09:14 -0700 | [diff] [blame] | 56 | enable_testing() |
Tamas Kenez | 9b454b7 | 2015-09-23 17:43:36 +0200 | [diff] [blame] | 57 | add_subdirectory(tests) |