forked from Slicer/Slicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitkCheckCXXAcceptsFlags.cmake
56 lines (52 loc) · 2.05 KB
/
itkCheckCXXAcceptsFlags.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
#
# - Test CXX compiler for a flag
# Check if the CXX compiler accepts a flag
#
# itkCHECK_CXX_ACCEPTS_FLAGS(FLAGS VAR)
# - macro which checks if the code compiles with the given flags
# FLAGS - cxx flags to try
# VAR - variable to store whether compiler accepts the FLAGS (TRUE or FALSE)
#
macro(itkCHECK_CXX_ACCEPTS_FLAGS FLAGS VAR)
if(NOT DEFINED ${VAR})
set(_SOURCE "int main() { return 0;}\n")
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx"
"${_SOURCE}")
message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
try_compile(${VAR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
OUTPUT_VARIABLE OUTPUT)
if(${VAR})
set(${VAR} TRUE CACHE INTERNAL "CXX compiler accepts flag ${FLAGS}")
else()
set(${VAR} FALSE CACHE INTERNAL "CXX compiler accepts flag ${FLAGS}")
endif()
set(_UNKNOWN_FLAG_MSGS
"ignoring unknown option"
"unrecognized option"
"Incorrect command line option"
"warning D9002" # MSVC, language independent
)
foreach(MSG ${_UNKNOWN_FLAG_MSGS})
string(REGEX MATCH "${MSG}" _FOUNDIT "${OUTPUT}")
if("${_FOUNDIT}" MATCHES "${MSG}")
set(${VAR} FALSE CACHE INTERNAL "CXX compiler accepts flag ${FLAGS}")
endif()
endforeach()
if(${VAR})
message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - Yes")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
"the following output:\n${OUTPUT}\n"
"Source file was:\n${_SOURCE}\n")
else()
message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - No")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
"the following output:\n${OUTPUT}\n"
"Source file was:\n${_SOURCE}\n")
endif()
endif()
endmacro()