blob: 89be4b8853daf28b24aadead036083837b813b67 (
plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing#kwsys for details.
set(KWSYS_PLATFORM_TEST_FILE_C kwsysPlatformTestsC.c)
set(KWSYS_PLATFORM_TEST_FILE_CXX kwsysPlatformTestsCXX.cxx)
macro(KWSYS_PLATFORM_TEST lang var description invert)
if(NOT DEFINED ${var}_COMPILED)
message(STATUS "${description}")
set(maybe_cxx_standard "")
if(CMAKE_VERSION VERSION_LESS 3.8 AND CMAKE_CXX_STANDARD)
set(maybe_cxx_standard "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
endif()
try_compile(${var}_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS}
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${KWSYS_PLATFORM_TEST_LINK_LIBRARIES}"
${maybe_cxx_standard}
OUTPUT_VARIABLE OUTPUT)
if(${var}_COMPILED)
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"${description} compiled with the following output:\n${OUTPUT}\n\n")
else()
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${description} failed to compile with the following output:\n${OUTPUT}\n\n")
endif()
if(${invert} MATCHES INVERT)
if(${var}_COMPILED)
message(STATUS "${description} - no")
else()
message(STATUS "${description} - yes")
endif()
else()
if(${var}_COMPILED)
message(STATUS "${description} - yes")
else()
message(STATUS "${description} - no")
endif()
endif()
endif()
if(${invert} MATCHES INVERT)
if(${var}_COMPILED)
set(${var} 0)
else()
set(${var} 1)
endif()
else()
if(${var}_COMPILED)
set(${var} 1)
else()
set(${var} 0)
endif()
endif()
endmacro()
macro(KWSYS_PLATFORM_TEST_RUN lang var description invert)
if(NOT DEFINED ${var})
message(STATUS "${description}")
try_run(${var} ${var}_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS}
OUTPUT_VARIABLE OUTPUT)
# Note that ${var} will be a 0 return value on success.
if(${var}_COMPILED)
if(${var})
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${description} compiled but failed to run with the following output:\n${OUTPUT}\n\n")
else()
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"${description} compiled and ran with the following output:\n${OUTPUT}\n\n")
endif()
else()
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${description} failed to compile with the following output:\n${OUTPUT}\n\n")
set(${var} -1 CACHE INTERNAL "${description} failed to compile.")
endif()
if(${invert} MATCHES INVERT)
if(${var}_COMPILED)
if(${var})
message(STATUS "${description} - yes")
else()
message(STATUS "${description} - no")
endif()
else()
message(STATUS "${description} - failed to compile")
endif()
else()
if(${var}_COMPILED)
if(${var})
message(STATUS "${description} - no")
else()
message(STATUS "${description} - yes")
endif()
else()
message(STATUS "${description} - failed to compile")
endif()
endif()
endif()
if(${invert} MATCHES INVERT)
if(${var}_COMPILED)
if(${var})
set(${var} 1)
else()
set(${var} 0)
endif()
else()
set(${var} 1)
endif()
else()
if(${var}_COMPILED)
if(${var})
set(${var} 0)
else()
set(${var} 1)
endif()
else()
set(${var} 0)
endif()
endif()
endmacro()
macro(KWSYS_PLATFORM_C_TEST var description invert)
set(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_C_TEST_DEFINES})
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_C_TEST_EXTRA_FLAGS})
KWSYS_PLATFORM_TEST(C "${var}" "${description}" "${invert}")
set(KWSYS_PLATFORM_TEST_DEFINES)
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
endmacro()
macro(KWSYS_PLATFORM_C_TEST_RUN var description invert)
set(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_C_TEST_DEFINES})
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_C_TEST_EXTRA_FLAGS})
KWSYS_PLATFORM_TEST_RUN(C "${var}" "${description}" "${invert}")
set(KWSYS_PLATFORM_TEST_DEFINES)
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
endmacro()
macro(KWSYS_PLATFORM_CXX_TEST var description invert)
set(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES})
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS})
set(KWSYS_PLATFORM_TEST_LINK_LIBRARIES ${KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES})
KWSYS_PLATFORM_TEST(CXX "${var}" "${description}" "${invert}")
set(KWSYS_PLATFORM_TEST_DEFINES)
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
set(KWSYS_PLATFORM_TEST_LINK_LIBRARIES)
endmacro()
macro(KWSYS_PLATFORM_CXX_TEST_RUN var description invert)
set(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES})
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS})
KWSYS_PLATFORM_TEST_RUN(CXX "${var}" "${description}" "${invert}")
set(KWSYS_PLATFORM_TEST_DEFINES)
set(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
endmacro()
#-----------------------------------------------------------------------------
# KWSYS_PLATFORM_INFO_TEST(lang var description)
#
# Compile test named by ${var} and store INFO strings extracted from binary.
macro(KWSYS_PLATFORM_INFO_TEST lang var description)
# We can implement this macro on CMake 2.6 and above.
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)
set(${var} "")
else()
# Choose a location for the result binary.
set(KWSYS_PLATFORM_INFO_FILE
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${var}.bin)
# Compile the test binary.
if(NOT EXISTS ${KWSYS_PLATFORM_INFO_FILE})
message(STATUS "${description}")
try_compile(${var}_COMPILED
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
COMPILE_DEFINITIONS -DTEST_${var}
${KWSYS_PLATFORM_${lang}_TEST_DEFINES}
${KWSYS_PLATFORM_${lang}_TEST_EXTRA_FLAGS}
OUTPUT_VARIABLE OUTPUT
COPY_FILE ${KWSYS_PLATFORM_INFO_FILE}
)
if(${var}_COMPILED)
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"${description} compiled with the following output:\n${OUTPUT}\n\n")
else()
file(APPEND
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${description} failed to compile with the following output:\n${OUTPUT}\n\n")
endif()
if(${var}_COMPILED)
message(STATUS "${description} - compiled")
else()
message(STATUS "${description} - failed")
endif()
endif()
# Parse info strings out of the compiled binary.
if(${var}_COMPILED)
file(STRINGS ${KWSYS_PLATFORM_INFO_FILE} ${var} REGEX "INFO:[A-Za-z0-9]+\\[[^]]*\\]")
else()
set(${var} "")
endif()
set(KWSYS_PLATFORM_INFO_FILE)
endif()
endmacro()
|