diff cmake/CheckCCompilerFlag.cmake @ 0:f9476ff7637e

initial forking of open-al to create multiple listeners
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:02:31 -0700
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cmake/CheckCCompilerFlag.cmake	Tue Oct 25 13:02:31 2011 -0700
     1.3 @@ -0,0 +1,59 @@
     1.4 +# - Check if the C source code provided in the SOURCE argument compiles.
     1.5 +# CHECK_C_SOURCE_COMPILES(SOURCE VAR)
     1.6 +#
     1.7 +#  FLAG   - compiler flag to check
     1.8 +#  VAR    - variable to store whether the source code compiled
     1.9 +#
    1.10 +# The following variables may be set before calling this macro to
    1.11 +# modify the way the check is run:
    1.12 +#
    1.13 +#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
    1.14 +#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
    1.15 +#  CMAKE_REQUIRED_INCLUDES = list of include directories
    1.16 +#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
    1.17 +
    1.18 +MACRO(CHECK_C_COMPILER_FLAG FLAG VAR)
    1.19 +  IF("${VAR}" MATCHES "^${VAR}$")
    1.20 +    SET(MACRO_CHECK_FUNCTION_DEFINITIONS
    1.21 +      "${FLAG} ${CMAKE_REQUIRED_FLAGS}")
    1.22 +    IF(CMAKE_REQUIRED_LIBRARIES)
    1.23 +      SET(CHECK_C_COMPILER_FLAG_ADD_LIBRARIES
    1.24 +        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
    1.25 +    ELSE(CMAKE_REQUIRED_LIBRARIES)
    1.26 +      SET(CHECK_C_COMPILER_FLAG_ADD_LIBRARIES)
    1.27 +    ENDIF(CMAKE_REQUIRED_LIBRARIES)
    1.28 +    IF(CMAKE_REQUIRED_INCLUDES)
    1.29 +      SET(CHECK_C_COMPILER_FLAG_ADD_INCLUDES
    1.30 +        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
    1.31 +    ELSE(CMAKE_REQUIRED_INCLUDES)
    1.32 +      SET(CHECK_C_COMPILER_FLAG_ADD_INCLUDES)
    1.33 +    ENDIF(CMAKE_REQUIRED_INCLUDES)
    1.34 +    FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c"
    1.35 +      "int main() {return 0;}\n")
    1.36 +
    1.37 +    MESSAGE(STATUS "Checking if C compiler supports ${FLAG}")
    1.38 +    TRY_COMPILE(${VAR}
    1.39 +      ${CMAKE_BINARY_DIR}
    1.40 +      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
    1.41 +      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
    1.42 +      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
    1.43 +      "${CHECK_C_COMPILER_FLAG_ADD_LIBRARIES}"
    1.44 +      "${CHECK_C_COMPILER_FLAG_ADD_INCLUDES}"
    1.45 +      OUTPUT_VARIABLE OUTPUT)
    1.46 +    IF(${VAR})
    1.47 +      SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}")
    1.48 +      MESSAGE(STATUS "Checking if C compiler supports ${FLAG} - Success")
    1.49 +      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
    1.50 +        "Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n"
    1.51 +        "${OUTPUT}\n"
    1.52 +        "Source file was:\n${SOURCE}\n")
    1.53 +    ELSE(${VAR})
    1.54 +      MESSAGE(STATUS "Checking if C compiler supports ${FLAG} - Failed")
    1.55 +      SET(${VAR} "" CACHE INTERNAL "Test ${VAR}")
    1.56 +      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
    1.57 +        "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n"
    1.58 +        "${OUTPUT}\n"
    1.59 +        "Source file was:\n${SOURCE}\n")
    1.60 +    ENDIF(${VAR})
    1.61 +  ENDIF("${VAR}" MATCHES "^${VAR}$")
    1.62 +ENDMACRO(CHECK_C_COMPILER_FLAG)