Make library importable by CMake using find_package

This commit is contained in:
Stefan Reinhold 2018-07-17 10:23:44 +02:00
parent 5778149583
commit d452c3b061

View File

@ -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)
@ -55,6 +58,7 @@ target_include_directories(GSL INTERFACE
$<BUILD_INTERFACE: $<BUILD_INTERFACE:
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include
> >
$<INSTALL_INTERFACE:include>
) )
if ((CMAKE_VERSION GREATER 3.7.9) OR (CMAKE_VERSION EQUAL 3.7.9)) if ((CMAKE_VERSION GREATER 3.7.9) OR (CMAKE_VERSION EQUAL 3.7.9))
@ -72,10 +76,18 @@ if ((CMAKE_VERSION GREATER 3.7.9) OR (CMAKE_VERSION EQUAL 3.7.9))
endif() endif()
endif() endif()
install(TARGETS GSL EXPORT GSLConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install( install(
DIRECTORY include/gsl DIRECTORY include/gsl
DESTINATION include DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) )
# Make library importable by other projects
install(EXPORT GSLConfig DESTINATION share/GSL/cmake)
export(TARGETS GSL FILE GSLConfig.cmake)
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT}) option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
if (GSL_TEST) if (GSL_TEST)