diff options
author | Brad King <brad.king@kitware.com> | 2015-09-25 14:12:37 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2015-09-25 14:12:37 (GMT) |
commit | 910ea2100425289ec4f13327141b5c45ede320bd (patch) | |
tree | e4f0baf8c87443cf77e882bee7b6c3f9c670d76b /Modules | |
parent | ede54544f1cbaa623628317887ffc34fce4bc89b (diff) | |
parent | fff9434d455600320be1809c6d64577eeb21d6aa (diff) | |
download | CMake-910ea2100425289ec4f13327141b5c45ede320bd.zip CMake-910ea2100425289ec4f13327141b5c45ede320bd.tar.gz CMake-910ea2100425289ec4f13327141b5c45ede320bd.tar.bz2 |
Merge topic 'Threads-CXX'
fff9434d FindThreads: officially announce it works with only C++ enabled
66db914a FindThreads: fix printing a pointer value in test code
0b38424c FindThreads: make the call to try_run() work also if only C++ is enabled
9924a212 FindThreads: replace CheckIncludeFiles by CheckIncludeFile
a27bc0cc Check(Function|Library|Symbol)Exists: make it work if only C++ is enabled
7279f293 FindThreads: add simple testcase
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CheckForPthreads.c | 2 | ||||
-rw-r--r-- | Modules/CheckFunctionExists.c | 3 | ||||
-rw-r--r-- | Modules/CheckFunctionExists.cmake | 14 | ||||
-rw-r--r-- | Modules/CheckLibraryExists.cmake | 13 | ||||
-rw-r--r-- | Modules/CheckSymbolExists.cmake | 10 | ||||
-rw-r--r-- | Modules/FindThreads.cmake | 27 |
6 files changed, 59 insertions, 10 deletions
diff --git a/Modules/CheckForPthreads.c b/Modules/CheckForPthreads.c index 7250fbf..2732957 100644 --- a/Modules/CheckForPthreads.c +++ b/Modules/CheckForPthreads.c @@ -31,7 +31,7 @@ void* runner(void* args) int cc; for ( cc = 0; cc < 10; cc ++ ) { - printf("%d CC: %d\n", (int)args, cc); + printf("%p CC: %d\n", args, cc); } res ++; return 0; diff --git a/Modules/CheckFunctionExists.c b/Modules/CheckFunctionExists.c index 607b3e8..fd29618 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 d277c32..5dd3751 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 95c595a..6b53823 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 79c5ba7..c4dff3f 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) diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index a0bc4d1..c607923 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -39,7 +39,7 @@ #============================================================================= # Copyright 2002-2009 Kitware, Inc. -# Copyright 2011-2014 Rolf Eike Beer <eike@sf-mail.de> +# Copyright 2011-2015 Rolf Eike Beer <eike@sf-mail.de> # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -51,15 +51,23 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -include (CheckIncludeFiles) include (CheckLibraryExists) include (CheckSymbolExists) set(Threads_FOUND FALSE) set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET}) set(CMAKE_REQUIRED_QUIET ${Threads_FIND_QUIETLY}) +if(CMAKE_C_COMPILER_LOADED) + include (CheckIncludeFile) +elseif(CMAKE_CXX_COMPILER_LOADED) + include (CheckIncludeFileCXX) +else() + message(FATAL_ERROR "FindThreads only works if either C or CXX language is enabled") +endif() + # Do we have sproc? if(CMAKE_SYSTEM_NAME MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD) + include (CheckIncludeFiles) CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H) endif() @@ -83,11 +91,18 @@ macro(_check_pthreads_flag) # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread if(NOT DEFINED THREADS_HAVE_PTHREAD_ARG) message(STATUS "Check if compiler accepts -pthread") + if(CMAKE_C_COMPILER_LOADED) + set(_threads_src ${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.c) + elseif(CMAKE_CXX_COMPILER_LOADED) + set(_threads_src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindThreads/CheckForPthreads.cxx) + configure_file(${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.c "${_threads_src}" COPYONLY) + endif() try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG ${CMAKE_BINARY_DIR} - ${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.c + ${_threads_src} CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread COMPILE_OUTPUT_VARIABLE OUTPUT) + unset(_threads_src) if(THREADS_HAVE_PTHREAD_ARG) if(THREADS_PTHREAD_ARG STREQUAL "2") @@ -120,7 +135,11 @@ if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD) set(CMAKE_USE_SPROC_INIT 1) else() # Do we have pthreads? - CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H) + if(CMAKE_C_COMPILER_LOADED) + CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H) + else() + CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H) + endif() if(CMAKE_HAVE_PTHREAD_H) # |