From aa50cdac439121f9e40ff2638368dc913a0e2361 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 16 Sep 2016 13:21:10 -0400 Subject: [PATCH] Check for availability of unique_ptr and make_unique when building CMake Some code paths may find these useful if available. --- Source/Checks/cm_cxx_features.cmake | 5 +++++ Source/Checks/cm_cxx_make_unique.cxx | 6 ++++++ Source/Checks/cm_cxx_unique_ptr.cxx | 6 ++++++ Source/cmConfigure.cmake.h.in | 2 ++ 4 files changed, 19 insertions(+) create mode 100644 Source/Checks/cm_cxx_make_unique.cxx create mode 100644 Source/Checks/cm_cxx_unique_ptr.cxx diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index 6fde7b67d..c6a532fcc 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -32,8 +32,13 @@ function(cm_check_cxx_feature name) endfunction() if(CMAKE_CXX_STANDARD) + cm_check_cxx_feature(make_unique) + if(CMake_HAVE_CXX_MAKE_UNIQUE) + set(CMake_HAVE_CXX_UNIQUE_PTR 1) + endif() cm_check_cxx_feature(nullptr) cm_check_cxx_feature(override) + cm_check_cxx_feature(unique_ptr) cm_check_cxx_feature(unordered_map) cm_check_cxx_feature(unordered_set) endif() diff --git a/Source/Checks/cm_cxx_make_unique.cxx b/Source/Checks/cm_cxx_make_unique.cxx new file mode 100644 index 000000000..a3ff68f9b --- /dev/null +++ b/Source/Checks/cm_cxx_make_unique.cxx @@ -0,0 +1,6 @@ +#include +int main() +{ + std::unique_ptr u = std::make_unique(0); + return *u; +} diff --git a/Source/Checks/cm_cxx_unique_ptr.cxx b/Source/Checks/cm_cxx_unique_ptr.cxx new file mode 100644 index 000000000..a9d4ce5d1 --- /dev/null +++ b/Source/Checks/cm_cxx_unique_ptr.cxx @@ -0,0 +1,6 @@ +#include +int main() +{ + std::unique_ptr u(new int(0)); + return *u; +} diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in index ccea22d68..8365367a0 100644 --- a/Source/cmConfigure.cmake.h.in +++ b/Source/cmConfigure.cmake.h.in @@ -30,8 +30,10 @@ #cmakedefine CMAKE_USE_MACH_PARSER #cmakedefine CMAKE_USE_LIBUV #cmakedefine CMAKE_ENCODING_UTF8 +#cmakedefine CMake_HAVE_CXX_MAKE_UNIQUE #cmakedefine CMake_HAVE_CXX_NULLPTR #cmakedefine CMake_HAVE_CXX_OVERRIDE +#cmakedefine CMake_HAVE_CXX_UNIQUE_PTR #cmakedefine CMake_HAVE_CXX_UNORDERED_MAP #cmakedefine CMake_HAVE_CXX_UNORDERED_SET #define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@"