mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge pull request #784 from hanst99/hunterization
Update "Make library importable by CMake using find_package"
This commit is contained in:
commit
4b643918a1
@ -5,6 +5,9 @@ project(GSL CXX)
|
|||||||
include(ExternalProject)
|
include(ExternalProject)
|
||||||
find_package(Git)
|
find_package(Git)
|
||||||
|
|
||||||
|
# Use GNUInstallDirs to provide the right locations on all platforms
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
# creates a library GSL which is an interface (header files only)
|
# creates a library GSL which is an interface (header files only)
|
||||||
add_library(GSL INTERFACE)
|
add_library(GSL INTERFACE)
|
||||||
|
|
||||||
@ -54,15 +57,13 @@ target_compile_definitions(GSL INTERFACE
|
|||||||
# the SYSTEM keyword suppresses warnings for users of the library
|
# the SYSTEM keyword suppresses warnings for users of the library
|
||||||
if(GSL_STANDALONE_PROJECT)
|
if(GSL_STANDALONE_PROJECT)
|
||||||
target_include_directories(GSL INTERFACE
|
target_include_directories(GSL INTERFACE
|
||||||
$<BUILD_INTERFACE:
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
>
|
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
target_include_directories(GSL SYSTEM INTERFACE
|
target_include_directories(GSL SYSTEM INTERFACE
|
||||||
$<BUILD_INTERFACE:
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
>
|
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -77,15 +78,23 @@ if (CMAKE_VERSION VERSION_GREATER 3.7.8)
|
|||||||
# add natvis file to the library so it will automatically be loaded into Visual Studio
|
# add natvis file to the library so it will automatically be loaded into Visual Studio
|
||||||
if(VS_ADD_NATIVE_VISUALIZERS)
|
if(VS_ADD_NATIVE_VISUALIZERS)
|
||||||
target_sources(GSL INTERFACE
|
target_sources(GSL INTERFACE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
install(TARGETS GSL EXPORT Microsoft.GSLConfig)
|
||||||
install(
|
install(
|
||||||
DIRECTORY include/gsl
|
DIRECTORY include/gsl
|
||||||
DESTINATION include
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
|
# Make library importable by other projects
|
||||||
|
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION share/Microsoft.GSL/cmake)
|
||||||
|
export(TARGETS GSL NAMESPACE Microsoft.GSL:: FILE Microsoft.GSLConfig.cmake)
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
||||||
if (GSL_TEST)
|
if (GSL_TEST)
|
||||||
|
@ -109,5 +109,14 @@ Include the library using:
|
|||||||
|
|
||||||
#include <gsl/gsl>
|
#include <gsl/gsl>
|
||||||
|
|
||||||
|
## Usage in CMake
|
||||||
|
|
||||||
|
The library provides a Config file for CMake, once installed it can be found via
|
||||||
|
|
||||||
|
find_package(Microsoft.GSL CONFIG)
|
||||||
|
|
||||||
|
Which, when successful, will add library target called `Microsoft.GSL::GSL` which you can use via the usual
|
||||||
|
`target_link_libraries` mechanism.
|
||||||
|
|
||||||
## Debugging visualization support
|
## Debugging visualization support
|
||||||
For Visual Studio users, the file [GSL.natvis](./GSL.natvis) in the root directory of the repository can be added to your project if you would like more helpful visualization of GSL types in the Visual Studio debugger than would be offered by default.
|
For Visual Studio users, the file [GSL.natvis](./GSL.natvis) in the root directory of the repository can be added to your project if you would like more helpful visualization of GSL types in the Visual Studio debugger than would be offered by default.
|
||||||
|
Loading…
Reference in New Issue
Block a user