Check(Function|Library|Symbol)Exists: make it work if only C++ is enabled
This commit is contained in:
parent
7279f2939e
commit
a27bc0ccac
|
@ -0,0 +1,6 @@
|
|||
Threads-CXX
|
||||
------------
|
||||
|
||||
* The :module:`CheckFunctionExists`, :module:`CheckLibraryExists`, and
|
||||
:module:`CheckSymbolExists` modules learned to work in environments where
|
||||
only CXX is enabled.
|
|
@ -1,5 +1,8 @@
|
|||
#ifdef CHECK_FUNCTION_EXISTS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char CHECK_FUNCTION_EXISTS();
|
||||
#ifdef __CLASSIC_C__
|
||||
int main(){
|
||||
|
|
|
@ -57,14 +57,26 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
|
|||
else()
|
||||
set(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
set(_cfe_source ${CMAKE_ROOT}/Modules/CheckFunctionExists.c)
|
||||
elseif(CMAKE_CXX_COMPILER_LOADED)
|
||||
set(_cfe_source ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists/CheckFunctionExists.cxx)
|
||||
configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c "${_cfe_source}" COPYONLY)
|
||||
else()
|
||||
message(FATAL_ERROR "CHECK_FUNCTION_EXISTS needs either C or CXX language enabled")
|
||||
endif()
|
||||
|
||||
try_compile(${VARIABLE}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_ROOT}/Modules/CheckFunctionExists.c
|
||||
${_cfe_source}
|
||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
|
||||
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
||||
"${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
unset(_cfe_source)
|
||||
|
||||
if(${VARIABLE})
|
||||
set(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
|
|
|
@ -53,15 +53,26 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
|
|||
set(CHECK_LIBRARY_EXISTS_LIBRARIES
|
||||
${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
set(_cle_source ${CMAKE_ROOT}/Modules/CheckFunctionExists.c)
|
||||
elseif(CMAKE_CXX_COMPILER_LOADED)
|
||||
set(_cle_source ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckLibraryExists/CheckFunctionExists.cxx)
|
||||
configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c "${_cle_source}" COPYONLY)
|
||||
else()
|
||||
message(FATAL_ERROR "CHECK_FUNCTION_EXISTS needs either C or CXX language enabled")
|
||||
endif()
|
||||
|
||||
try_compile(${VARIABLE}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_ROOT}/Modules/CheckFunctionExists.c
|
||||
${_cle_source}
|
||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
|
||||
CMAKE_FLAGS
|
||||
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
|
||||
-DLINK_DIRECTORIES:STRING=${LOCATION}
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
unset(_cle_source)
|
||||
|
||||
if(${VARIABLE})
|
||||
if(NOT CMAKE_REQUIRED_QUIET)
|
||||
|
|
|
@ -44,10 +44,14 @@
|
|||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
|
||||
|
||||
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
||||
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||
elseif(CMAKE_CXX_COMPILER_LOADED)
|
||||
_CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
|
||||
else()
|
||||
message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
|
||||
|
|
Loading…
Reference in New Issue