summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2015-09-22 06:11:50 +0200
committerBrad King <brad.king@kitware.com>2015-09-25 10:07:54 -0400
commita27bc0ccacff7bc590ace2ce941f0552d05fd14c (patch)
treeb9f4b5e0ce15408cf38aa7db19af5ac4d900c850 /Modules
parent7279f2939e98ae9ecfb8fda2dc82f6b0048b9316 (diff)
downloadcmake-a27bc0ccacff7bc590ace2ce941f0552d05fd14c.tar.gz
Check(Function|Library|Symbol)Exists: make it work if only C++ is enabled
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CheckFunctionExists.c3
-rw-r--r--Modules/CheckFunctionExists.cmake14
-rw-r--r--Modules/CheckLibraryExists.cmake13
-rw-r--r--Modules/CheckSymbolExists.cmake10
4 files changed, 35 insertions, 5 deletions
diff --git a/Modules/CheckFunctionExists.c b/Modules/CheckFunctionExists.c
index 607b3e8c6a..fd29618ce8 100644
--- a/Modules/CheckFunctionExists.c
+++ b/Modules/CheckFunctionExists.c
@@ -1,5 +1,8 @@
#ifdef CHECK_FUNCTION_EXISTS
+#ifdef __cplusplus
+extern "C"
+#endif
char CHECK_FUNCTION_EXISTS();
#ifdef __CLASSIC_C__
int main(){
diff --git a/Modules/CheckFunctionExists.cmake b/Modules/CheckFunctionExists.cmake
index d277c32822..5dd37517a8 100644
--- a/Modules/CheckFunctionExists.cmake
+++ b/Modules/CheckFunctionExists.cmake
@@ -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)
diff --git a/Modules/CheckLibraryExists.cmake b/Modules/CheckLibraryExists.cmake
index 95c595a21d..6b538233e3 100644
--- a/Modules/CheckLibraryExists.cmake
+++ b/Modules/CheckLibraryExists.cmake
@@ -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)
diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake
index 79c5ba78ee..c4dff3faaf 100644
--- a/Modules/CheckSymbolExists.cmake
+++ b/Modules/CheckSymbolExists.cmake
@@ -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)