mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Raise CMake min to 3.14 (#1083)
- Explicitly test package manager support with CMake 3.14 and Ninja - Remove gsl_install.cmake - Simplify installation code
This commit is contained in:
parent
cbf5e664fc
commit
f7da2e41f0
25
.github/workflows/cmake_find_package.yml
vendored
Normal file
25
.github/workflows/cmake_find_package.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
name: cmake_find_package
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
cmake-find-package:
|
||||
name: Build ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest, macos-latest ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: 3.14.0
|
||||
- name: Configure GSL
|
||||
run: cmake -S . -B build -G "Ninja" -D GSL_TEST=OFF -D CMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/build/install
|
||||
- name: Install GSL
|
||||
run: cmake --build build --target install
|
||||
- name: Test GSL find_package support
|
||||
run: cmake -S tests/ -B build/tests_find_package -G "Ninja" -D CMAKE_PREFIX_PATH=${GITHUB_WORKSPACE}/build/install -D CMAKE_BUILD_TYPE=Release
|
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.8...3.16)
|
||||
cmake_minimum_required(VERSION 3.14...3.16)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
||||
include(gsl_functions)
|
||||
|
||||
@ -22,11 +22,28 @@ add_subdirectory(include)
|
||||
# Add natvis file
|
||||
gsl_add_native_visualizer_support()
|
||||
|
||||
if (GSL_INSTALL)
|
||||
include(gsl_install)
|
||||
endif()
|
||||
|
||||
if (GSL_TEST)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
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})
|
||||
endif()
|
||||
|
@ -1,26 +0,0 @@
|
||||
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})
|
@ -1,13 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
cmake_minimum_required(VERSION 3.14...3.16)
|
||||
|
||||
project(GSLTests LANGUAGES CXX)
|
||||
enable_testing() # again, for support standalone testing
|
||||
|
||||
set(GSL_CXX_STANDARD "14" CACHE STRING "Use c++ standard")
|
||||
|
||||
set(CMAKE_CXX_STANDARD ${GSL_CXX_STANDARD})
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
include(FindPkgConfig)
|
||||
include(ExternalProject)
|
||||
@ -58,10 +57,14 @@ if (NOT GTestMain_FOUND)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
# CMake has been started independently in this directory with tests. Do
|
||||
# import the globally installed Guidelines Support Library and test it
|
||||
# instead of the current version from the include/ folder.
|
||||
find_package(Microsoft.GSL REQUIRED)
|
||||
find_package(Microsoft.GSL CONFIG REQUIRED)
|
||||
enable_testing()
|
||||
|
||||
if (NOT DEFINED Microsoft.GSL_VERSION)
|
||||
message(FATAL_ERROR "Microsoft.GSL_VERSION not defined!")
|
||||
endif()
|
||||
|
||||
message(STATUS "Microsoft.GSL_VERSION = ${Microsoft.GSL_VERSION}")
|
||||
endif()
|
||||
|
||||
if (MSVC AND (GSL_CXX_STANDARD GREATER_EQUAL 17))
|
||||
|
Loading…
Reference in New Issue
Block a user