-
Notifications
You must be signed in to change notification settings - Fork 72
/
check_configuration.cmake
141 lines (136 loc) · 5.14 KB
/
check_configuration.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
macro(check_stdcxx)
# Check C++11
include(CheckCXXCompilerFlag)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
check_cxx_compiler_flag(-std=c++14 SUPPORTS_CXX14)
set(HAVE_CXX14 0)
set(HAVE_CXX1Y 0)
set(HAVE_CXX11 0)
set(HAVE_CXX0X 0)
if(SUPPORTS_CXX14)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++14>)
set(HAVE_CXX14 1)
set(HAVE_CXX1Y 1)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
check_cxx_compiler_flag(-std=c++1y SUPPORTS_CXX1Y)
if(SUPPORTS_CXX1Y)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++1y>)
set(HAVE_CXX1Y 1)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11)
if(SUPPORTS_CXX11)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X)
if(SUPPORTS_CXX0X)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>)
set(HAVE_CXX0X 1)
else()
set(HAVE_CXX0X 0)
endif()
endif()
endif()
endif()
elseif(MSVC OR MSVC_IDE)
set(HAVE_CXX11 1)
set(HAVE_CXX0X 1)
else()
set(HAVE_CXX11 0)
set(HAVE_CXX0X 0)
endif()
endmacro()
macro(check_compile_feature)
# Check constexpr
list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_constexpr" CXX_CONSTEXPR_SUPPORTED)
if(${CXX_CONSTEXPR_SUPPORTED} GREATER -1)
set(HAVE_CXX_CONSTEXPR 1)
else()
set(HAVE_CXX_CONSTEXPR 0)
endif()
endmacro()
macro(check_endianness)
# Test endianness
include(TestBigEndian)
test_big_endian(BIG_ENDIAN)
set(__BIG_ENDIAN__ ${BIG_ENDIAN})
endmacro()
macro(check_msvc_arch)
if(MSVC_VERSION EQUAL 1700)
if(CMAKE_CL_64)
set(MSVC_ARCH "x64Win64VS2012")
else()
set(MSVC_ARCH "i86Win32VS2012")
endif()
elseif(MSVC_VERSION EQUAL 1800)
if(CMAKE_CL_64)
set(MSVC_ARCH "x64Win64VS2013")
else()
set(MSVC_ARCH "i86Win32VS2013")
endif()
elseif(MSVC_VERSION EQUAL 1900)
if(CMAKE_CL_64)
set(MSVC_ARCH "x64Win64VS2015")
else()
set(MSVC_ARCH "i86Win32VS2015")
endif()
elseif(MSVC_VERSION GREATER 1900)
if(CMAKE_CL_64)
set(MSVC_ARCH "x64Win64VS2017")
else()
set(MSVC_ARCH "i86Win32VS2017")
endif()
else()
if(CMAKE_CL_64)
set(MSVC_ARCH "x64Win64VSUnknown")
else()
set(MSVC_ARCH "i86Win32VSUnknown")
endif()
endif()
endmacro()
function(set_common_compile_options target)
enable_language(C)
enable_language(CXX)
if(MSVC OR MSVC_IDE)
target_compile_options(${target} PRIVATE /W4)
else()
target_compile_options(${target} PRIVATE -Wall
-Wextra
-Wshadow
$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>
-pedantic
-Wcast-align
-Wunused
$<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual>
-Wconversion
-Wsign-conversion
$<$<CXX_COMPILER_ID:GNU>:-Wlogical-op>
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:CXX>>:-Wuseless-cast>
-Wdouble-promotion
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast>
$<$<OR:$<AND:$<CXX_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6.0.0>>>,$<AND:$<C_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<C_COMPILER_VERSION>,6.0.0>>>>:-Wnull-dereference>
$<$<OR:$<AND:$<CXX_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,7.0.0>>>,$<AND:$<C_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<C_COMPILER_VERSION>,7.0.0>>>>:-Wduplicated-branches>
$<$<OR:$<AND:$<CXX_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,6.0.0>>>,$<AND:$<C_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<C_COMPILER_VERSION>,6.0.0>>>>:-Wduplicated-cond>
$<$<OR:$<AND:$<CXX_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<CXX_COMPILER_VERSION>,7.0.0>>>,$<AND:$<C_COMPILER_ID:GNU>,$<NOT:$<VERSION_LESS:$<C_COMPILER_VERSION>,7.0.0>>>>:-Wrestrict>
)
endif()
endfunction()