mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
cb2d1af89a
* Added template argument deduction for not_null This allows compilers with c++17 support to infer template instantiation types when calling not_null constructor: int foo(not_null<const int*> x); int main() { int t = 0; not_null x{ &t }; return foo(not_null{ &t }); } * replaced deduction guides by a simple constructor * Updated tests * fixed check for availability of std::byte * testing c++1z on clang * fixed cmakelists extra endif * include cstddef header for clang and gcc in pointers * fixed a typo * fix missing nullptr_t type * fixed typo in CMakeLists.tst * change approach to c++17 testing, step one: revert cmake testing, update clang5.0 package removed using latest c++ due to clang5.0 failing, update clang5.0 travis config to use llvm-toolchain-trusty-5.0 * addressed comments
87 lines
2.6 KiB
CMake
87 lines
2.6 KiB
CMake
cmake_minimum_required(VERSION 3.1.3)
|
|
|
|
project(GSL CXX)
|
|
|
|
include(ExternalProject)
|
|
find_package(Git)
|
|
|
|
# creates a library GSL which is an interface (header files only)
|
|
add_library(GSL INTERFACE)
|
|
|
|
# determine whether this is a standalone project or included by other projects
|
|
set(GSL_STANDALONE_PROJECT OFF)
|
|
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
|
set(GSL_STANDALONE_PROJECT ON)
|
|
endif ()
|
|
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
if (NOT MSVC)
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
|
else()
|
|
CHECK_CXX_COMPILER_FLAG("-std:c++14" COMPILER_SUPPORTS_CXX14)
|
|
endif()
|
|
|
|
# when minimum version required is 3.8.0 remove if below
|
|
# both branches do exactly the same thing
|
|
if (CMAKE_VERSION VERSION_LESS 3.7.9)
|
|
if (NOT MSVC)
|
|
if(COMPILER_SUPPORTS_CXX14)
|
|
target_compile_options(GSL INTERFACE "-std=c++14")
|
|
else()
|
|
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
|
|
endif()
|
|
else()
|
|
if(COMPILER_SUPPORTS_CXX14)
|
|
target_compile_options(GSL INTERFACE "-std:c++14")
|
|
else()
|
|
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
|
|
endif()
|
|
endif()
|
|
else ()
|
|
target_compile_features(GSL INTERFACE cxx_std_14)
|
|
# on *nix systems force the use of -std=c++XX instead of -std=gnu++XX (default)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
endif()
|
|
|
|
# add definitions to the library and targets that consume it
|
|
target_compile_definitions(GSL INTERFACE
|
|
$<$<CXX_COMPILER_ID:MSVC>:
|
|
# remove unnecessary warnings about unchecked iterators
|
|
_SCL_SECURE_NO_WARNINGS
|
|
>
|
|
)
|
|
|
|
# add include folders to the library and targets that consume it
|
|
target_include_directories(GSL INTERFACE
|
|
$<BUILD_INTERFACE:
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
>
|
|
)
|
|
|
|
if ((CMAKE_VERSION GREATER 3.7.9) OR (CMAKE_VERSION EQUAL 3.7.9))
|
|
if (MSVC_IDE)
|
|
option(VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE)
|
|
else()
|
|
set(VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE)
|
|
endif()
|
|
|
|
# add natvis file to the library so it will automatically be loaded into Visual Studio
|
|
if(VS_ADD_NATIVE_VISUALIZERS)
|
|
target_sources(GSL INTERFACE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
install(
|
|
DIRECTORY include/gsl
|
|
DESTINATION include
|
|
)
|
|
|
|
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
|
if (GSL_TEST)
|
|
enable_testing()
|
|
add_subdirectory(tests)
|
|
endif ()
|