2023-02-06 14:16:37 -05:00
|
|
|
cmake_minimum_required(VERSION 3.14...3.16)
|
2020-11-16 17:05:33 -05:00
|
|
|
|
2024-10-21 11:19:37 -04:00
|
|
|
project(GSL VERSION 4.1.0 LANGUAGES CXX)
|
2021-01-04 17:17:03 -05:00
|
|
|
|
2017-04-25 20:08:36 -04:00
|
|
|
add_library(GSL INTERFACE)
|
2020-11-16 17:05:33 -05:00
|
|
|
add_library(Microsoft.GSL::GSL ALIAS GSL)
|
|
|
|
|
2022-10-18 14:05:09 -04:00
|
|
|
# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html
|
|
|
|
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL)
|
2018-06-07 16:36:56 -04:00
|
|
|
|
2022-10-18 14:05:09 -04:00
|
|
|
option(GSL_INSTALL "Generate and install GSL target" ${PROJECT_IS_TOP_LEVEL})
|
|
|
|
option(GSL_TEST "Build and perform GSL tests" ${PROJECT_IS_TOP_LEVEL})
|
2021-01-05 14:55:13 -05:00
|
|
|
|
2022-10-29 15:31:23 -04:00
|
|
|
# The implementation generally assumes a platform that implements C++14 support
|
|
|
|
target_compile_features(GSL INTERFACE "cxx_std_14")
|
2017-04-25 20:08:36 -04:00
|
|
|
|
2021-01-08 12:56:04 -05:00
|
|
|
# Setup include directory
|
|
|
|
add_subdirectory(include)
|
2018-11-28 18:37:59 -05:00
|
|
|
|
2023-05-10 20:02:44 -04:00
|
|
|
target_sources(GSL INTERFACE $<BUILD_INTERFACE:${GSL_SOURCE_DIR}/GSL.natvis>)
|
2017-04-25 20:08:36 -04:00
|
|
|
|
2017-09-06 20:50:30 -04:00
|
|
|
if (GSL_TEST)
|
2020-05-04 16:31:08 -04:00
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
2020-12-15 13:06:46 -05:00
|
|
|
endif()
|
2023-02-06 14:16:37 -05:00
|
|
|
|
|
|
|
if (GSL_INSTALL)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
|
|
|
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/gsl" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
|
|
|
|
set(export_name "Microsoft.GSLConfig")
|
|
|
|
set(namespace "Microsoft.GSL::")
|
|
|
|
set(cmake_files_install_dir ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
|
|
|
|
|
|
|
install(TARGETS GSL EXPORT ${export_name} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
|
|
install(EXPORT ${export_name} NAMESPACE ${namespace} DESTINATION ${cmake_files_install_dir})
|
|
|
|
export(TARGETS GSL NAMESPACE ${namespace} FILE ${export_name}.cmake)
|
|
|
|
|
|
|
|
set(gls_config_version "${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake")
|
|
|
|
|
|
|
|
write_basic_package_version_file(${gls_config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
|
|
|
|
|
|
|
|
install(FILES ${gls_config_version} DESTINATION ${cmake_files_install_dir})
|
2023-05-10 20:02:44 -04:00
|
|
|
|
|
|
|
install(FILES GSL.natvis DESTINATION ${cmake_files_install_dir})
|
2023-02-06 14:16:37 -05:00
|
|
|
endif()
|