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 CHECK_FUNCTION_EXISTS
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
#endif
|
||||||
char CHECK_FUNCTION_EXISTS();
|
char CHECK_FUNCTION_EXISTS();
|
||||||
#ifdef __CLASSIC_C__
|
#ifdef __CLASSIC_C__
|
||||||
int main(){
|
int main(){
|
||||||
|
|
|
@ -57,14 +57,26 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
|
||||||
else()
|
else()
|
||||||
set(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
|
set(CHECK_FUNCTION_EXISTS_ADD_INCLUDES)
|
||||||
endif()
|
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}
|
try_compile(${VARIABLE}
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
${CMAKE_ROOT}/Modules/CheckFunctionExists.c
|
${_cfe_source}
|
||||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||||
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
|
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
|
||||||
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
|
||||||
"${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
|
"${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
|
||||||
OUTPUT_VARIABLE OUTPUT)
|
OUTPUT_VARIABLE OUTPUT)
|
||||||
|
unset(_cfe_source)
|
||||||
|
|
||||||
if(${VARIABLE})
|
if(${VARIABLE})
|
||||||
set(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
|
set(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}")
|
||||||
if(NOT CMAKE_REQUIRED_QUIET)
|
if(NOT CMAKE_REQUIRED_QUIET)
|
||||||
|
|
|
@ -53,15 +53,26 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
|
||||||
set(CHECK_LIBRARY_EXISTS_LIBRARIES
|
set(CHECK_LIBRARY_EXISTS_LIBRARIES
|
||||||
${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
|
${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
|
||||||
endif()
|
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}
|
try_compile(${VARIABLE}
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
${CMAKE_ROOT}/Modules/CheckFunctionExists.c
|
${_cle_source}
|
||||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||||
LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
|
LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
|
||||||
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}
|
||||||
OUTPUT_VARIABLE OUTPUT)
|
OUTPUT_VARIABLE OUTPUT)
|
||||||
|
unset(_cle_source)
|
||||||
|
|
||||||
if(${VARIABLE})
|
if(${VARIABLE})
|
||||||
if(NOT CMAKE_REQUIRED_QUIET)
|
if(NOT CMAKE_REQUIRED_QUIET)
|
||||||
|
|
|
@ -44,10 +44,14 @@
|
||||||
# (To distribute this file outside of CMake, substitute the full
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
# License text for the above reference.)
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
|
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()
|
endmacro()
|
||||||
|
|
||||||
macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
|
macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
|
||||||
|
|
Loading…
Reference in New Issue