GSL/cmake/gsl_install.cmake
jpr42 c52bad36aa
CMake cleanup (#1060)
- Move all install logic inside gsl_install.cmake
  - This makes reading the logic easier, and avoids the enable language
    issue with `GNUInstallDirs` by having it included after the project
    call
- Have all functions inside gsl_functions.cmake
- Use CMake idiom PROJECT_IS_TOP_LEVEL
- Update README.md
2022-10-18 11:05:09 -07:00

27 lines
1.1 KiB
CMake

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Install header files
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)
# Add find_package() support
target_include_directories(GSL INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(TARGETS GSL EXPORT ${export_name})
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")
# Add find_package() versioning support
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
write_basic_package_version_file(${gls_config_version} COMPATIBILITY SameMajorVersion)
else()
write_basic_package_version_file(${gls_config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
endif()
install(FILES ${gls_config_version} DESTINATION ${cmake_files_install_dir})