rlm@0: # - Check if the C source code provided in the SOURCE argument compiles. rlm@0: # CHECK_C_SOURCE_COMPILES(SOURCE VAR) rlm@0: # rlm@0: # FLAG - compiler flag to check rlm@0: # VAR - variable to store whether the source code compiled rlm@0: # rlm@0: # The following variables may be set before calling this macro to rlm@0: # modify the way the check is run: rlm@0: # rlm@0: # CMAKE_REQUIRED_FLAGS = string of compile command line flags rlm@0: # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) rlm@0: # CMAKE_REQUIRED_INCLUDES = list of include directories rlm@0: # CMAKE_REQUIRED_LIBRARIES = list of libraries to link rlm@0: rlm@0: MACRO(CHECK_C_COMPILER_FLAG FLAG VAR) rlm@0: IF("${VAR}" MATCHES "^${VAR}$") rlm@0: SET(MACRO_CHECK_FUNCTION_DEFINITIONS rlm@0: "${FLAG} ${CMAKE_REQUIRED_FLAGS}") rlm@0: IF(CMAKE_REQUIRED_LIBRARIES) rlm@0: SET(CHECK_C_COMPILER_FLAG_ADD_LIBRARIES rlm@0: "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") rlm@0: ELSE(CMAKE_REQUIRED_LIBRARIES) rlm@0: SET(CHECK_C_COMPILER_FLAG_ADD_LIBRARIES) rlm@0: ENDIF(CMAKE_REQUIRED_LIBRARIES) rlm@0: IF(CMAKE_REQUIRED_INCLUDES) rlm@0: SET(CHECK_C_COMPILER_FLAG_ADD_INCLUDES rlm@0: "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}") rlm@0: ELSE(CMAKE_REQUIRED_INCLUDES) rlm@0: SET(CHECK_C_COMPILER_FLAG_ADD_INCLUDES) rlm@0: ENDIF(CMAKE_REQUIRED_INCLUDES) rlm@0: FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c" rlm@0: "int main() {return 0;}\n") rlm@0: rlm@0: MESSAGE(STATUS "Checking if C compiler supports ${FLAG}") rlm@0: TRY_COMPILE(${VAR} rlm@0: ${CMAKE_BINARY_DIR} rlm@0: ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c rlm@0: COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} rlm@0: CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} rlm@0: "${CHECK_C_COMPILER_FLAG_ADD_LIBRARIES}" rlm@0: "${CHECK_C_COMPILER_FLAG_ADD_INCLUDES}" rlm@0: OUTPUT_VARIABLE OUTPUT) rlm@0: IF(${VAR}) rlm@0: SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}") rlm@0: MESSAGE(STATUS "Checking if C compiler supports ${FLAG} - Success") rlm@0: FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log rlm@0: "Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n" rlm@0: "${OUTPUT}\n" rlm@0: "Source file was:\n${SOURCE}\n") rlm@0: ELSE(${VAR}) rlm@0: MESSAGE(STATUS "Checking if C compiler supports ${FLAG} - Failed") rlm@0: SET(${VAR} "" CACHE INTERNAL "Test ${VAR}") rlm@0: FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log rlm@0: "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n" rlm@0: "${OUTPUT}\n" rlm@0: "Source file was:\n${SOURCE}\n") rlm@0: ENDIF(${VAR}) rlm@0: ENDIF("${VAR}" MATCHES "^${VAR}$") rlm@0: ENDMACRO(CHECK_C_COMPILER_FLAG)