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
|
#
# - 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(${VAR})
SET(${VAR} FALSE CACHE INTERNAL "CXX compiler accepts flag ${FLAGS}")
ENDIF(${VAR})
SET(_UNKNOWN_FLAG_MSGS
"ignoring unknown option"
"unrecognized option"
"Incorrect command line option"
)
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("${_FOUNDIT}" MATCHES "${MSG}")
ENDFOREACH(MSG ${_UNKNOWN_FLAG_MSGS})
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(${VAR})
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(${VAR})
ENDIF(NOT DEFINED ${VAR})
ENDMACRO(itkCHECK_CXX_ACCEPTS_FLAGS)
|