Minor cmake nitpicks (#969)

It's much nicer and less error prone to just use add_subdirectory to establish the include directory.

Hide the GNUInstallDirs module by placing it in the helper module. The intent being that the main CMakeLists.txt should have a little code as possible. So that readers can quickly understand the project.

Use include_guard() when available in cmake 3.10+

Co-authored-by: Juan Ramos <juanr0911@gmail.com>
This commit is contained in:
hdf89shfdfs 2021-01-08 12:56:04 -05:00 committed by GitHub
parent 3b3478eaf8
commit d0052f6320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 24 deletions

View File

@ -8,9 +8,6 @@ project(GSL
LANGUAGES CXX LANGUAGES CXX
) )
# 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)
@ -41,8 +38,8 @@ else()
gsl_client_set_cxx_standard(${gsl_min_cxx_standard}) gsl_client_set_cxx_standard(${gsl_min_cxx_standard})
endif() endif()
# Setup the include directory # Setup include directory
gsl_target_include_directories(${GSL_STANDALONE_PROJECT}) add_subdirectory(include)
# Add natvis file # Add natvis file
gsl_add_native_visualizer_support() gsl_add_native_visualizer_support()

View File

@ -4,14 +4,21 @@
# for multiple versions of cmake. # for multiple versions of cmake.
# #
# Any functions/macros should have a gsl_* prefix to avoid problems # Any functions/macros should have a gsl_* prefix to avoid problems
if (DEFINED guideline_support_library_include_guard) if (CMAKE_VERSION VERSION_GREATER 3.10 OR CMAKE_VERSION VERSION_EQUAL 3.10)
return() include_guard()
else()
if (DEFINED guideline_support_library_include_guard)
return()
endif()
set(guideline_support_library_include_guard ON)
endif() endif()
set(guideline_support_library_include_guard ON)
# Necessary for 'write_basic_package_version_file' # Necessary for 'write_basic_package_version_file'
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
# Use GNUInstallDirs to provide the right locations on all platforms
include(GNUInstallDirs)
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")
@ -79,22 +86,6 @@ function(gsl_add_native_visualizer_support)
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) function(gsl_install_logic)
install(TARGETS GSL EXPORT Microsoft.GSLConfig) install(TARGETS GSL EXPORT Microsoft.GSLConfig)
install( install(

20
include/CMakeLists.txt Normal file
View File

@ -0,0 +1,20 @@
# Add include folders to the library and targets that consume it
# the SYSTEM keyword suppresses warnings for users of the library
#
# By adding this directory as an include directory the user gets a
# namespace effect.
#
# IE:
# #include <gsl/gsl>
if(GSL_STANDALONE_PROJECT)
target_include_directories(GSL INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
else()
target_include_directories(GSL SYSTEM INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
endif()