forked from Eyescale/CMake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCPP11.cmake
113 lines (95 loc) · 2.45 KB
/
TestCPP11.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright (c) 2013-2015 [email protected]
# OPT: do this only once, included by Common.cmake, don't do if C++03
if(TESTS_CPP11_DONE OR COMMON_USE_CXX03)
return()
endif()
set(TESTS_CPP11_DONE ON)
if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
message(WARNING "For better performance, include TestCPP11 in the top-level "
"project so that it is run only once.")
endif()
set(TESTS_CPP11 sharedptr tuple auto nullptr array final_override noexcept
unordered_map template_alias)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_sharedptr.cpp
"#include <memory>
int main()
{
std::shared_ptr< int > a( new int );
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_tuple.cpp
"#include <tuple>
int main()
{
std::tuple< int, char> foo(10,'x');
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_auto.cpp
"int main()
{
int a = 2;
auto foo = a;
foo++;
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_nullptr.cpp
"int main()
{
int *ptr = nullptr;
ptr++;
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_array.cpp
"#include <array>
int main()
{
std::array<int, 3> a2 = {{1, 2, 3}};
a2[ 0 ] = 1;
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_final_override.cpp
"class Foo
{
public:
virtual void one();
virtual void two() final;
virtual ~Foo();
};
class Bar : public Foo
{
virtual void one() override;
virtual ~Bar();
};
int main() {}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_noexcept.cpp
"bool foo() noexcept { return false; }
int main() {}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_unordered_map.cpp
"#include <unordered_map>
int main()
{
std::unordered_map< int, int > test;
test[ 42 ] = 17;
return 0;
}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cpp11_template_alias.cpp
"#include <vector>
template <typename T> using FooVector = std::vector< T >;
int main()
{
FooVector< int > foo;
return 0;
}")
while(TESTS_CPP11)
list(GET TESTS_CPP11 0 TEST_CPP11_name)
list(REMOVE_AT TESTS_CPP11 0)
string(TOUPPER ${TEST_CPP11_name} TEST_CPP11_NAME)
try_compile(CXX_${TEST_CPP11_NAME}_SUPPORTED
${CMAKE_CURRENT_BINARY_DIR}/cpp11_${TEST_CPP11_name}
${CMAKE_CURRENT_BINARY_DIR}/cpp11_${TEST_CPP11_name}.cpp OUTPUT_VARIABLE output)
if(CXX_${TEST_CPP11_NAME}_SUPPORTED)
add_definitions(-DCXX_${TEST_CPP11_NAME}_SUPPORTED)
endif()
endwhile()