diff options
author | Andreas Schuh <andreas.schuh.84@gmail.com> | 2014-03-17 13:17:44 +0000 |
---|---|---|
committer | Andreas Schuh <andreas.schuh.84@gmail.com> | 2014-03-17 13:17:44 +0000 |
commit | f1e7b37c48fd13f53884d8552db5ae8a3bb8d5a3 (patch) | |
tree | db6409ea23a63fcbdc7537d0c5bd76b898defd46 /cmake | |
parent | 1b1b61d3056e678154fcd637dfd754761f0780dc (diff) | |
download | gflags-f1e7b37c48fd13f53884d8552db5ae8a3bb8d5a3.tar.gz gflags-f1e7b37c48fd13f53884d8552db5ae8a3bb8d5a3.tar.bz2 gflags-f1e7b37c48fd13f53884d8552db5ae8a3bb8d5a3.zip |
Add CheckCXXLibraryExists.cmake module and use it in FindTreadsCXX.cmake.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/CheckCXXLibraryExists.cmake | 80 | ||||
-rw-r--r-- | cmake/FindThreadsCxx.cmake | 10 |
2 files changed, 85 insertions, 5 deletions
diff --git a/cmake/CheckCXXLibraryExists.cmake b/cmake/CheckCXXLibraryExists.cmake new file mode 100644 index 0000000..eb0885f --- /dev/null +++ b/cmake/CheckCXXLibraryExists.cmake @@ -0,0 +1,80 @@ +#.rst: +# CheckLibraryExists +# ------------------ +# +# Check if the function exists. +# +# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE) +# +# :: +# +# LIBRARY - the name of the library you are looking for +# FUNCTION - the name of the function +# LOCATION - location where the library should be found +# VARIABLE - variable to store the result +# +# +# +# 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 + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + + +macro(CHECK_CXX_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) + if("${VARIABLE}" MATCHES "^${VARIABLE}$") + set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION + "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") + message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}") + set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY}) + if(CMAKE_REQUIRED_LIBRARIES) + set(CHECK_LIBRARY_EXISTS_LIBRARIES + ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}) + endif() + configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c + ${CMAKE_BINARY_DIR}/CheckFunctionExists.cxx COPYONLY) + try_compile(${VARIABLE} + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}/CheckFunctionExists.cxx + 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) + + if(${VARIABLE}) + message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found") + set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " + "passed with the following output:\n" + "${OUTPUT}\n\n") + else() + message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found") + set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " + "failed with the following output:\n" + "${OUTPUT}\n\n") + endif() + endif() +endmacro() diff --git a/cmake/FindThreadsCxx.cmake b/cmake/FindThreadsCxx.cmake index 625b826..cfeb578 100644 --- a/cmake/FindThreadsCxx.cmake +++ b/cmake/FindThreadsCxx.cmake @@ -34,7 +34,7 @@ # License text for the above reference.) include (CheckIncludeFileCXX) -include (CheckLibraryExists) +include (CheckCXXLibraryExists) include (CheckCXXSymbolExists) set(Threads_FOUND FALSE) @@ -67,7 +67,7 @@ else() if(NOT CMAKE_HAVE_THREADS_LIBRARY) # Do we have -lpthreads - CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) + CHECK_CXX_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) if(CMAKE_HAVE_PTHREADS_CREATE) set(CMAKE_THREAD_LIBS_INIT "-lpthreads") set(CMAKE_HAVE_THREADS_LIBRARY 1) @@ -75,7 +75,7 @@ else() endif() # Ok, how about -lpthread - CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) + CHECK_CXX_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) if(CMAKE_HAVE_PTHREAD_CREATE) set(CMAKE_THREAD_LIBS_INIT "-lpthread") set(CMAKE_HAVE_THREADS_LIBRARY 1) @@ -84,7 +84,7 @@ else() if(CMAKE_SYSTEM MATCHES "SunOS.*") # On sun also check for -lthread - CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) + CHECK_CXX_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) if(CMAKE_HAVE_THR_CREATE) set(CMAKE_THREAD_LIBS_INIT "-lthread") set(CMAKE_HAVE_THREADS_LIBRARY 1) @@ -153,7 +153,7 @@ if(CMAKE_USE_PTHREADS_INIT) # but we need to maintain compatibility here. # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads # are available. - CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) + CHECK_CXX_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) if(CMAKE_HAVE_HP_CMA) set(CMAKE_THREAD_LIBS_INIT "-lcma") set(CMAKE_HP_PTHREADS_INIT 1) |