ENH: Made Check* modules more consistent and well documented. Added CMAKE_REQUIRED_DEFINITIONS option.

This commit is contained in:
Brad King 2006-02-09 19:23:18 -05:00
parent f8a8e88a08
commit f0a1da00c1
9 changed files with 101 additions and 29 deletions

View File

@ -3,10 +3,14 @@
# - macro which checks if the source code compiles # - macro which checks if the source code compiles
# SOURCE - source code to try to compile # SOURCE - source code to try to compile
# VAR - variable to store size if the type exists. # VAR - variable to store size if the type exists.
# Checks the following optional VARIABLES (not arguments)
# CMAKE_REQUIRED_LIBRARIES - Link to extra libraries
# CMAKE_REQUIRED_FLAGS - Extra flags to C compiler
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR) MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR)
IF("${VAR}" MATCHES "^${VAR}$") IF("${VAR}" MATCHES "^${VAR}$")
@ -31,6 +35,7 @@ MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR)
TRY_COMPILE(${VAR} TRY_COMPILE(${VAR}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.c ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
"${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}" "${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}"
"${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}" "${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"

View File

@ -3,10 +3,14 @@
# - macro which checks if the source code compiles\ # - macro which checks if the source code compiles\
# SOURCE - source code to try to compile # SOURCE - source code to try to compile
# VAR - variable to store size if the type exists. # VAR - variable to store size if the type exists.
# Checks the following optional VARIABLES (not arguments)
# CMAKE_REQUIRED_LIBRARIES - Link to extra libraries
# CMAKE_REQUIRED_FLAGS - Extra flags to C compiler
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
IF("${VAR}" MATCHES "^${VAR}$") IF("${VAR}" MATCHES "^${VAR}$")
@ -31,6 +35,7 @@ MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
TRY_COMPILE(${VAR} TRY_COMPILE(${VAR}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.cxx ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/src.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
"${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}" "${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}"
"${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}" "${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"

View File

@ -3,10 +3,14 @@
# - macro which checks if the function exists # - macro which checks if the function exists
# FUNCTION - the name of the function # FUNCTION - the name of the function
# VARIABLE - variable to store the result # VARIABLE - variable to store the result
# If CMAKE_REQUIRED_FLAGS is set then those flags will be passed into the
# compile of the program likewise if CMAKE_REQUIRED_LIBRARIES is set then
# those libraries will be linked against the test program
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE) MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
@ -16,12 +20,22 @@ MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
IF(CMAKE_REQUIRED_LIBRARIES) IF(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
ELSE(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES)
ENDIF(CMAKE_REQUIRED_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES)
IF(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
ELSE(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
ENDIF(CMAKE_REQUIRED_INCLUDES)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckFunctionExists.c ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}"
"${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
IF(${VARIABLE}) IF(${VARIABLE})
SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}") SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")

View File

@ -7,8 +7,20 @@
# an optional third argument is the CFlags to add to the compile line # an optional third argument is the CFlags to add to the compile line
# or you can use CMAKE_REQUIRED_FLAGS # or you can use CMAKE_REQUIRED_FLAGS
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
#
MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE) MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
IF(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
ELSE(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_INCLUDE_FILE_C_INCLUDE_DIRS)
ENDIF(CMAKE_REQUIRED_INCLUDES)
SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS}) SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE}) SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.c.in
@ -22,8 +34,10 @@ MACRO(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.c ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
"${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
IF(${ARGC} EQUAL 3) IF(${ARGC} EQUAL 3)

View File

@ -7,8 +7,20 @@
# An optional third argument is the CFlags to add to the compile line # An optional third argument is the CFlags to add to the compile line
# or you can use CMAKE_REQUIRED_FLAGS. # or you can use CMAKE_REQUIRED_FLAGS.
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
#
MACRO(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE) MACRO(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
IF(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
ELSE(CMAKE_REQUIRED_INCLUDES)
SET(CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS)
ENDIF(CMAKE_REQUIRED_INCLUDES)
SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS}) SET(MACRO_CHECK_INCLUDE_FILE_FLAGS ${CMAKE_REQUIRED_FLAGS})
SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE}) SET(CHECK_INCLUDE_FILE_VAR ${INCLUDE})
CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
@ -22,8 +34,10 @@ MACRO(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFile.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
"${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
IF(${ARGC} EQUAL 3) IF(${ARGC} EQUAL 3)

View File

@ -5,10 +5,12 @@
# INCLUDE - list of files to include # INCLUDE - list of files to include
# VARIABLE - variable to return result # VARIABLE - variable to return result
# #
# If CMAKE_REQUIRED_FLAGS is set then those flags will be passed into the # The following variables may be set before calling this macro to
# compile of the program # modify the way the check is run:
# If CMAKE_REQUIRED_INCLUDES is set then those directories will be passed #
# as include paths to the compiler # CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE) MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
@ -32,6 +34,7 @@ MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFiles.c ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS} -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
"${CHECK_INCLUDE_FILES_INCLUDE_DIRS}" "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"

View File

@ -6,10 +6,12 @@
# LOCATION - location where the library should be found # LOCATION - location where the library should be found
# VARIABLE - variable to store the result # VARIABLE - variable to store the result
# #
# If CMAKE_REQUIRED_FLAGS is set then those flags will be passed into the # The following variables may be set before calling this macro to
# compile of the program likewise if CMAKE_REQUIRED_LIBRARIES is set then # modify the way the check is run:
# those libraries will be linked against the test program #
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
@ -20,10 +22,13 @@ MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
IF(CMAKE_REQUIRED_LIBRARIES) IF(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_LIBRARY_EXISTS_LIBRARIES SET(CHECK_LIBRARY_EXISTS_LIBRARIES
${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}) ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
ELSE(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_LIBRARY_EXISTS_LIBRARIES)
ENDIF(CMAKE_REQUIRED_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckFunctionExists.c ${CMAKE_ROOT}/Modules/CheckFunctionExists.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION} -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
-DLINK_DIRECTORIES:STRING=${LOCATION} -DLINK_DIRECTORIES:STRING=${LOCATION}

View File

@ -5,10 +5,13 @@
# FILES - include files to check # FILES - include files to check
# VARIABLE - variable to return result # VARIABLE - variable to return result
# #
# If CMAKE_REQUIRED_FLAGS is set then those flags will be passed into the # The following variables may be set before calling this macro to
# compile of the program likewise if CMAKE_REQUIRED_LIBRARIES is set then # modify the way the check is run:
# those libraries will be linked against the test program #
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE) MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
@ -40,6 +43,7 @@ MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckSymbolExists.c ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeTmp/CheckSymbolExists.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS} -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
"${CHECK_SYMBOL_EXISTS_LIBS}" "${CHECK_SYMBOL_EXISTS_LIBS}"

View File

@ -3,11 +3,16 @@
# #
# VAR - the name of the variable # VAR - the name of the variable
# VARIABLE - variable to store the result # VARIABLE - variable to store the result
# If CMAKE_REQUIRED_FLAGS is set then those flags will be passed into the #
# compile of the program likewise if CMAKE_REQUIRED_LIBRARIES is set then
# those libraries will be linked against the test program.
# This macro is only for C variables. # This macro is only for C variables.
# #
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE) MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE)
IF("${VARIABLE}" MATCHES "^${VARIABLE}$") IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
SET(MACRO_CHECK_VARIABLE_DEFINITIONS SET(MACRO_CHECK_VARIABLE_DEFINITIONS
@ -16,10 +21,13 @@ MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE)
IF(CMAKE_REQUIRED_LIBRARIES) IF(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
ELSE(CMAKE_REQUIRED_LIBRARIES)
SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES)
ENDIF(CMAKE_REQUIRED_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES)
TRY_COMPILE(${VARIABLE} TRY_COMPILE(${VARIABLE}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckVariableExists.c ${CMAKE_ROOT}/Modules/CheckVariableExists.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS}
"${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES}" "${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)