mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
* [cmake] Adding options for INSTALL and TEST (#964) * [cmake] Adding GSL_INSTALL option Not all consumers of GSL automatically want to have this install logic. It's good practice to gate install logic behind an option. For an example look at magic_enum: https://github.com/Neargye/magic_enum/blob/master/CMakeLists.txt If the client wants to install GSL they still can. But they should ask for it by overriding GSL_INSTALL. * Update cmake/guidelineSupportLibrary.cmake added nl@eof * Update CMakeLists.txt * Update CMakeLists.txt Co-authored-by: Juan Ramos <juanr0911@gmail.com> Co-authored-by: Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> * missing config line restored by moving GNUInstallDirs back to main file Co-authored-by: hdf89shfdfs <31327577+hdf89shfdfs@users.noreply.github.com> Co-authored-by: Juan Ramos <juanr0911@gmail.com>
This commit is contained in:
parent
25bb4bd948
commit
e427b02c89
@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.1.3...3.16)
|
|||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
||||||
include(guidelineSupportLibrary)
|
include(guidelineSupportLibrary)
|
||||||
|
|
||||||
project(GSL VERSION 3.1.0 LANGUAGES CXX)
|
project(GSL
|
||||||
|
VERSION 3.1.0
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
|
||||||
# Use GNUInstallDirs to provide the right locations on all platforms
|
# Use GNUInstallDirs to provide the right locations on all platforms
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
@ -25,6 +28,10 @@ if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|||||||
set(GSL_STANDALONE_PROJECT ON)
|
set(GSL_STANDALONE_PROJECT ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
### Project options
|
||||||
|
option(GSL_INSTALL "Generate and install GSL target" ${GSL_STANDALONE_PROJECT})
|
||||||
|
option(GSL_TEST "Build and perform GSL tests" ${GSL_STANDALONE_PROJECT})
|
||||||
|
|
||||||
# This GSL implementation generally assumes a platform that implements C++14 support.
|
# This GSL implementation generally assumes a platform that implements C++14 support.
|
||||||
set(gsl_min_cxx_standard "14")
|
set(gsl_min_cxx_standard "14")
|
||||||
|
|
||||||
@ -34,58 +41,21 @@ else()
|
|||||||
gsl_client_set_cxx_standard(${gsl_min_cxx_standard})
|
gsl_client_set_cxx_standard(${gsl_min_cxx_standard})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add include folders to the library and targets that consume it
|
# Setup the include directory
|
||||||
# the SYSTEM keyword suppresses warnings for users of the library
|
gsl_target_include_directories(${GSL_STANDALONE_PROJECT})
|
||||||
if(GSL_STANDALONE_PROJECT)
|
|
||||||
target_include_directories(GSL INTERFACE
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
target_include_directories(GSL SYSTEM INTERFACE
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Add natvis file
|
# Add natvis file
|
||||||
gsl_add_native_visualizer_support()
|
gsl_add_native_visualizer_support()
|
||||||
|
|
||||||
install(TARGETS GSL EXPORT Microsoft.GSLConfig)
|
# Add packaging support
|
||||||
install(
|
gsl_create_packaging_file()
|
||||||
DIRECTORY include/gsl
|
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
# Make library importable by other projects
|
|
||||||
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
|
||||||
export(TARGETS GSL NAMESPACE Microsoft.GSL:: FILE Microsoft.GSLConfig.cmake)
|
|
||||||
|
|
||||||
# Add find_package() versioning support. The version for
|
if (GSL_INSTALL)
|
||||||
# generated Microsoft.GSLConfigVersion.cmake will be used from
|
# Setup install/export logic
|
||||||
# last project() command. The version's compatibility is set between all
|
gsl_install_logic()
|
||||||
# minor versions (as it was in prev. GSL releases).
|
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
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()
|
endif()
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
|
||||||
|
|
||||||
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
|
||||||
if (GSL_TEST)
|
if (GSL_TEST)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
if(IOS)
|
|
||||||
add_compile_definitions(
|
|
||||||
GTEST_HAS_DEATH_TEST=1
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
@ -9,6 +9,9 @@ if (DEFINED guideline_support_library_include_guard)
|
|||||||
endif()
|
endif()
|
||||||
set(guideline_support_library_include_guard ON)
|
set(guideline_support_library_include_guard ON)
|
||||||
|
|
||||||
|
# Necessary for 'write_basic_package_version_file'
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
function(gsl_set_default_cxx_standard min_cxx_standard)
|
function(gsl_set_default_cxx_standard min_cxx_standard)
|
||||||
set(GSL_CXX_STANDARD "${min_cxx_standard}" CACHE STRING "Use c++ standard")
|
set(GSL_CXX_STANDARD "${min_cxx_standard}" CACHE STRING "Use c++ standard")
|
||||||
|
|
||||||
@ -75,3 +78,51 @@ function(gsl_add_native_visualizer_support)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
function(gsl_target_include_directories is_standalone)
|
||||||
|
# Add include folders to the library and targets that consume it
|
||||||
|
# the SYSTEM keyword suppresses warnings for users of the library
|
||||||
|
if(${is_standalone})
|
||||||
|
target_include_directories(GSL INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
target_include_directories(GSL SYSTEM INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(gsl_install_logic)
|
||||||
|
install(TARGETS GSL EXPORT Microsoft.GSLConfig)
|
||||||
|
install(
|
||||||
|
DIRECTORY include/gsl
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
# Make library importable by other projects
|
||||||
|
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
||||||
|
export(TARGETS GSL NAMESPACE Microsoft.GSL:: FILE Microsoft.GSLConfig.cmake)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# 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).
|
||||||
|
function(gsl_create_packaging_file)
|
||||||
|
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()
|
||||||
|
endfunction()
|
||||||
|
@ -10,6 +10,10 @@ find_package(Git REQUIRED QUIET)
|
|||||||
# will make visual studio generated project group files
|
# will make visual studio generated project group files
|
||||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
|
||||||
|
if(IOS)
|
||||||
|
add_compile_definitions(GTEST_HAS_DEATH_TEST=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
pkg_search_module(GTestMain gtest_main)
|
pkg_search_module(GTestMain gtest_main)
|
||||||
if (NOT GTestMain_FOUND)
|
if (NOT GTestMain_FOUND)
|
||||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||||
|
Loading…
Reference in New Issue
Block a user