diff options
author | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-10-11 15:16:57 +0900 |
---|---|---|
committer | MyungJoo Ham <myungjoo.ham@samsung.com> | 2017-10-11 15:16:57 +0900 |
commit | 915c76ded744c0f5f151402b9fa69f3fd8452573 (patch) | |
tree | ca6a387466543248890f346847acaa8343989b22 /Source/Checks | |
parent | 317dbdb79761ef65e45c7358cfc7571c6afa54ad (diff) | |
download | cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.gz cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.tar.bz2 cmake-915c76ded744c0f5f151402b9fa69f3fd8452573.zip |
Imported Upstream version 3.9.4upstream/3.9.4
Diffstat (limited to 'Source/Checks')
-rw-r--r-- | Source/Checks/cm_c11_thread_local.c | 5 | ||||
-rw-r--r-- | Source/Checks/cm_c11_thread_local.cmake | 33 | ||||
-rw-r--r-- | Source/Checks/cm_cxx14_cstdio.cmake | 33 | ||||
-rw-r--r-- | Source/Checks/cm_cxx14_cstdio.cpp | 5 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_attribute_fallthrough.cxx | 11 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_auto_ptr.cxx | 18 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_eq_delete.cxx | 14 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_fallthrough.cxx | 11 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_features.cmake | 58 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_gnu_fallthrough.cxx | 11 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_make_unique.cxx | 6 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_nullptr.cxx | 14 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_override.cxx | 24 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_unique_ptr.cxx | 6 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_unordered_map.cxx | 7 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_unordered_set.cxx | 7 |
16 files changed, 263 insertions, 0 deletions
diff --git a/Source/Checks/cm_c11_thread_local.c b/Source/Checks/cm_c11_thread_local.c new file mode 100644 index 000000000..bdf91aa90 --- /dev/null +++ b/Source/Checks/cm_c11_thread_local.c @@ -0,0 +1,5 @@ +_Thread_local int i = 42; +int main(void) +{ + return 0; +} diff --git a/Source/Checks/cm_c11_thread_local.cmake b/Source/Checks/cm_c11_thread_local.cmake new file mode 100644 index 000000000..6b8d10b2b --- /dev/null +++ b/Source/Checks/cm_c11_thread_local.cmake @@ -0,0 +1,33 @@ +set(CMake_C11_THREAD_LOCAL_BROKEN 0) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_C11_STANDARD_COMPILE_OPTION) + if(NOT DEFINED CMake_C11_THREAD_LOCAL_WORKS) + message(STATUS "Checking if compiler supports C11 _Thread_local") + try_compile(CMake_C11_THREAD_LOCAL_WORKS + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/cm_c11_thread_local.c + CMAKE_FLAGS -DCMAKE_C_STANDARD=11 + OUTPUT_VARIABLE OUTPUT + ) + if(CMake_C11_THREAD_LOCAL_WORKS AND "${OUTPUT}" MATCHES "error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'") + set_property(CACHE CMake_C11_THREAD_LOCAL_WORKS PROPERTY VALUE 0) + endif() + if(CMake_C11_THREAD_LOCAL_WORKS) + message(STATUS "Checking if compiler supports C11 _Thread_local - yes") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if compiler supports C11 _Thread_local passed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + else() + message(STATUS "Checking if compiler supports C11 _Thread_local - no") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler supports C11 _Thread_local failed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + endif() + endif() + if(NOT CMake_C11_THREAD_LOCAL_WORKS) + set(CMake_C11_THREAD_LOCAL_BROKEN 1) + endif() +endif() diff --git a/Source/Checks/cm_cxx14_cstdio.cmake b/Source/Checks/cm_cxx14_cstdio.cmake new file mode 100644 index 000000000..73f7e2ed5 --- /dev/null +++ b/Source/Checks/cm_cxx14_cstdio.cmake @@ -0,0 +1,33 @@ +set(CMake_CXX14_CSTDIO_BROKEN 0) +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND CMAKE_CXX14_STANDARD_COMPILE_OPTION) + if(NOT DEFINED CMake_CXX14_CSTDIO_WORKS) + message(STATUS "Checking if compiler supports C++14 cstdio") + try_compile(CMake_CXX14_CSTDIO_WORKS + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/cm_cxx14_cstdio.cpp + CMAKE_FLAGS -DCMAKE_CXX_STANDARD=14 + OUTPUT_VARIABLE OUTPUT + ) + if(CMake_CXX14_CSTDIO_WORKS AND "${OUTPUT}" MATCHES "error: no member named.*gets.*in the global namespace") + set_property(CACHE CMake_CXX14_CSTDIO_WORKS PROPERTY VALUE 0) + endif() + if(CMake_CXX14_CSTDIO_WORKS) + message(STATUS "Checking if compiler supports C++14 cstdio - yes") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if compiler supports C++14 cstdio passed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + else() + message(STATUS "Checking if compiler supports C++14 cstdio - no") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler supports C++14 cstdio failed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + endif() + endif() + if(NOT CMake_CXX14_CSTDIO_WORKS) + set(CMake_CXX14_CSTDIO_BROKEN 1) + endif() +endif() diff --git a/Source/Checks/cm_cxx14_cstdio.cpp b/Source/Checks/cm_cxx14_cstdio.cpp new file mode 100644 index 000000000..f5806a9c6 --- /dev/null +++ b/Source/Checks/cm_cxx14_cstdio.cpp @@ -0,0 +1,5 @@ +#include <cstdio> +int main() +{ + return 0; +} diff --git a/Source/Checks/cm_cxx_attribute_fallthrough.cxx b/Source/Checks/cm_cxx_attribute_fallthrough.cxx new file mode 100644 index 000000000..df43625a4 --- /dev/null +++ b/Source/Checks/cm_cxx_attribute_fallthrough.cxx @@ -0,0 +1,11 @@ +int main(int argc, char* argv[]) +{ + int i = 3; + switch (argc) { + case 1: + i = 0; + __attribute__((fallthrough)); + default: + return i; + } +} diff --git a/Source/Checks/cm_cxx_auto_ptr.cxx b/Source/Checks/cm_cxx_auto_ptr.cxx new file mode 100644 index 000000000..d3100fdc8 --- /dev/null +++ b/Source/Checks/cm_cxx_auto_ptr.cxx @@ -0,0 +1,18 @@ +#include <memory> + +std::auto_ptr<int> get_auto_ptr() +{ + std::auto_ptr<int> ptr; + ptr = std::auto_ptr<int>(new int(0)); + return ptr; +} + +int use_auto_ptr(std::auto_ptr<int> ptr) +{ + return *ptr; +} + +int main() +{ + return use_auto_ptr(get_auto_ptr()); +} diff --git a/Source/Checks/cm_cxx_eq_delete.cxx b/Source/Checks/cm_cxx_eq_delete.cxx new file mode 100644 index 000000000..809e4cfcf --- /dev/null +++ b/Source/Checks/cm_cxx_eq_delete.cxx @@ -0,0 +1,14 @@ +struct Foo +{ + Foo() {} + ~Foo() {} + Foo(Foo const&) = delete; + Foo& operator=(Foo const&) = delete; + int test() const { return 0; } +}; + +int main() +{ + Foo const foo; + return foo.test(); +} diff --git a/Source/Checks/cm_cxx_fallthrough.cxx b/Source/Checks/cm_cxx_fallthrough.cxx new file mode 100644 index 000000000..7b35a5f29 --- /dev/null +++ b/Source/Checks/cm_cxx_fallthrough.cxx @@ -0,0 +1,11 @@ +int main(int argc, char* argv[]) +{ + int i = 3; + switch (argc) { + case 1: + i = 0; + [[fallthrough]]; + default: + return i; + } +} diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake new file mode 100644 index 000000000..3b0802579 --- /dev/null +++ b/Source/Checks/cm_cxx_features.cmake @@ -0,0 +1,58 @@ + +function(cm_check_cxx_feature name) + string(TOUPPER ${name} FEATURE) + if(NOT DEFINED CMake_HAVE_CXX_${FEATURE}) + message(STATUS "Checking if compiler supports C++ ${name}") + if(CMAKE_CXX_STANDARD) + set(maybe_cxx_standard -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}) + else() + set(maybe_cxx_standard "") + endif() + try_compile(CMake_HAVE_CXX_${FEATURE} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/cm_cxx_${name}.cxx + CMAKE_FLAGS ${maybe_cxx_standard} + OUTPUT_VARIABLE OUTPUT + ) + # Filter out MSBuild output that looks like a warning. + string(REGEX REPLACE " +0 Warning\\(s\\)" "" check_output "${OUTPUT}") + # If using the feature causes warnings, treat it as broken/unavailable. + if(check_output MATCHES "[Ww]arning") + set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE) + endif() + if(CMake_HAVE_CXX_${FEATURE}) + message(STATUS "Checking if compiler supports C++ ${name} - yes") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if compiler supports C++ ${name} passed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + else() + message(STATUS "Checking if compiler supports C++ ${name} - no") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if compiler supports C++ ${name} failed with the following output:\n" + "${OUTPUT}\n" + "\n" + ) + endif() + endif() +endfunction() + +cm_check_cxx_feature(auto_ptr) +cm_check_cxx_feature(eq_delete) +cm_check_cxx_feature(fallthrough) +if(NOT CMake_HAVE_CXX_FALLTHROUGH) + cm_check_cxx_feature(gnu_fallthrough) + if(NOT CMake_HAVE_CXX_GNU_FALLTHROUGH) + cm_check_cxx_feature(attribute_fallthrough) + endif() +endif() +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) diff --git a/Source/Checks/cm_cxx_gnu_fallthrough.cxx b/Source/Checks/cm_cxx_gnu_fallthrough.cxx new file mode 100644 index 000000000..602109405 --- /dev/null +++ b/Source/Checks/cm_cxx_gnu_fallthrough.cxx @@ -0,0 +1,11 @@ +int main(int argc, char* argv[]) +{ + int i = 3; + switch (argc) { + case 1: + i = 0; + [[gnu::fallthrough]]; + default: + return i; + } +} 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 <memory> +int main() +{ + std::unique_ptr<int> u = std::make_unique<int>(0); + return *u; +} diff --git a/Source/Checks/cm_cxx_nullptr.cxx b/Source/Checks/cm_cxx_nullptr.cxx new file mode 100644 index 000000000..500684aee --- /dev/null +++ b/Source/Checks/cm_cxx_nullptr.cxx @@ -0,0 +1,14 @@ +int test(int) +{ + return -1; +} + +int test(int*) +{ + return 0; +} + +int main() +{ + return test(nullptr); +} diff --git a/Source/Checks/cm_cxx_override.cxx b/Source/Checks/cm_cxx_override.cxx new file mode 100644 index 000000000..5a33fbb78 --- /dev/null +++ b/Source/Checks/cm_cxx_override.cxx @@ -0,0 +1,24 @@ +struct Foo +{ + Foo() {} + virtual ~Foo() {} + virtual int test() const = 0; +}; + +struct Bar : Foo +{ + Bar() {} + ~Bar() override {} + int test() const override { return 0; } +}; + +int test(Foo const& foo) +{ + return foo.test(); +} + +int main() +{ + Bar const bar; + return test(bar); +} 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 <memory> +int main() +{ + std::unique_ptr<int> u(new int(0)); + return *u; +} diff --git a/Source/Checks/cm_cxx_unordered_map.cxx b/Source/Checks/cm_cxx_unordered_map.cxx new file mode 100644 index 000000000..be3de252b --- /dev/null +++ b/Source/Checks/cm_cxx_unordered_map.cxx @@ -0,0 +1,7 @@ +#include <unordered_map> +int main() +{ + std::unordered_map<int, int> map; + map[0] = 0; + return 0; +} diff --git a/Source/Checks/cm_cxx_unordered_set.cxx b/Source/Checks/cm_cxx_unordered_set.cxx new file mode 100644 index 000000000..de4bb7765 --- /dev/null +++ b/Source/Checks/cm_cxx_unordered_set.cxx @@ -0,0 +1,7 @@ +#include <unordered_set> +int main() +{ + std::unordered_set<int> set; + set.insert(0); + return 0; +} |