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
|
|
|
|
2020-11-16 17:05:33 -05:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
|
|
|
include(guidelineSupportLibrary)
|
|
|
|
|
2020-06-03 19:52:20 -04:00
|
|
|
project(GSL VERSION 3.1.0 LANGUAGES 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
|
|
|
|
2018-07-17 04:23:44 -04:00
|
|
|
# Use GNUInstallDirs to provide the right locations on all platforms
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2020-11-16 17:05:33 -05:00
|
|
|
# Creates a library GSL which is an interface (header files only)
|
2017-04-25 20:08:36 -04:00
|
|
|
add_library(GSL INTERFACE)
|
|
|
|
|
2020-11-16 17:05:33 -05:00
|
|
|
# NOTE: If you want to use GSL prefer to link against GSL using this alias target
|
|
|
|
# EX:
|
|
|
|
# target_link_libraries(foobar PRIVATE Microsoft.GSL::GSL)
|
|
|
|
#
|
|
|
|
# Add Microsoft.GSL::GSL alias for GSL so that dependents can be agnostic about
|
|
|
|
# whether GSL was added via `add_subdirectory` or `find_package`
|
|
|
|
add_library(Microsoft.GSL::GSL ALIAS GSL)
|
|
|
|
|
|
|
|
# Determine whether this is a standalone project or included by other projects
|
2017-09-06 20:50:30 -04:00
|
|
|
set(GSL_STANDALONE_PROJECT OFF)
|
|
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
2020-05-04 16:31:08 -04:00
|
|
|
set(GSL_STANDALONE_PROJECT ON)
|
2018-06-07 16:36:56 -04:00
|
|
|
endif()
|
|
|
|
|
2020-11-16 17:05:33 -05:00
|
|
|
# This GSL implementation generally assumes a platform that implements C++14 support.
|
|
|
|
set(gsl_min_cxx_standard "14")
|
2018-06-15 13:13:11 -04:00
|
|
|
|
2020-11-16 17:05:33 -05:00
|
|
|
if (GSL_STANDALONE_PROJECT)
|
|
|
|
gsl_set_default_cxx_standard(${gsl_min_cxx_standard})
|
|
|
|
else()
|
|
|
|
gsl_client_set_cxx_standard(${gsl_min_cxx_standard})
|
2017-04-25 20:08:36 -04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# 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
|
2019-05-09 13:09:21 -04:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
2020-02-08 07:49:43 -05:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
2018-11-28 18:37:59 -05:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
target_include_directories(GSL SYSTEM INTERFACE
|
2019-05-09 13:09:21 -04:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
2020-02-08 07:49:43 -05:00
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
2018-11-28 18:37:59 -05:00
|
|
|
)
|
|
|
|
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)
|
2020-10-22 18:40:27 -04:00
|
|
|
option(GSL_VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE)
|
2018-04-27 15:56:25 -04:00
|
|
|
else()
|
2020-10-22 18:40:27 -04:00
|
|
|
set(GSL_VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE)
|
2018-04-27 15:56:25 -04:00
|
|
|
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
|
2020-10-22 18:40:27 -04:00
|
|
|
if(GSL_VS_ADD_NATIVE_VISUALIZERS)
|
2018-04-27 15:56:25 -04:00
|
|
|
target_sources(GSL INTERFACE
|
2018-07-17 07:07:27 -04:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis>
|
2018-04-27 15:56:25 -04:00
|
|
|
)
|
|
|
|
endif()
|
2017-11-28 10:31:06 -05:00
|
|
|
endif()
|
2017-04-25 20:08:36 -04:00
|
|
|
|
2020-02-08 07:55:19 -05:00
|
|
|
install(TARGETS GSL EXPORT Microsoft.GSLConfig)
|
2017-02-07 18:59:37 -05:00
|
|
|
install(
|
|
|
|
DIRECTORY include/gsl
|
2018-07-17 04:23:44 -04:00
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
2015-11-21 14:13:21 -05:00
|
|
|
)
|
2018-07-17 04:23:44 -04:00
|
|
|
# Make library importable by other projects
|
2020-04-17 05:47:23 -04:00
|
|
|
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
2018-07-17 11:56:11 -04:00
|
|
|
export(TARGETS GSL NAMESPACE Microsoft.GSL:: FILE Microsoft.GSLConfig.cmake)
|
2015-11-21 14:13:21 -05:00
|
|
|
|
2020-04-26 07:37:54 -04:00
|
|
|
# Add find_package() versioning support. The version for
|
|
|
|
# generated Microsoft.GSLConfigVersion.cmake will be used from
|
|
|
|
# last project() command. The version's compatibility is set between all
|
|
|
|
# minor versions (as it was in prev. GSL releases).
|
|
|
|
include(CMakePackageConfigHelpers)
|
2020-06-06 14:42:51 -04:00
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake
|
|
|
|
COMPATIBILITY SameMajorVersion
|
|
|
|
ARCH_INDEPENDENT
|
|
|
|
)
|
|
|
|
endif()
|
2020-04-26 07:37:54 -04:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
|
|
|
|
2017-09-06 20:50:30 -04:00
|
|
|
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
|
|
|
if (GSL_TEST)
|
2020-05-04 16:31:08 -04:00
|
|
|
enable_testing()
|
|
|
|
if(IOS)
|
|
|
|
add_compile_definitions(
|
|
|
|
GTEST_HAS_DEATH_TEST=1
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
add_subdirectory(tests)
|
2017-09-06 20:50:30 -04:00
|
|
|
endif ()
|