[CMake] CHECK_FUNCTION_EXISTS for pthread_spin_init
Philip Lowman
philip at yhbt.com
Fri Feb 29 14:42:41 EST 2008
**On Thu, Feb 28, 2008 at 9:21 AM, Brantner Matthias <brantner at m-brantner.de>
wrote:
> Hi,
>
> I wanted to write a check whether pthread_mutex_init and
> pthread_spin_init exist in pthread.h. Therefore,
> I used the following CMake commands:
>
> INCLUDE(CheckFunctionExists)
> CHECK_FUNCTION_EXISTS("pthread_spin_init"
> HAVE_PTHREAD_SPINLOCK)
> CHECK_FUNCTION_EXISTS("pthread_mutex_init" HAVE_PTHREAD_MUTEX)
>
> The result of running CMake on a Linux system gives me
>
> -- Looking for pthread_spin_init
> -- Looking for pthread_spin_init - not found
> -- Looking for pthread_mutex_init
> -- Looking for pthread_mutex_init - found.
>
> Although pthread_spin_init is declared in my pthread.h and my code
> compiles and uses it, CMake does not find it.
> However, I saw that this function is guarded in an "#ifdef
> __USE_XOPEN2K". Could that be the reason why
> CMake doesn't find it or am I doing something wrong here?
>
>
*CheckFunctionExists*: macro which checks if the function exists
CHECK_FUNCTION_EXISTS(FUNCTION VARIABLE)
FUNCTION - the name of the function
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_INCLUDES = list of include directories
CMAKE_REQUIRED_LIBRARIES = list of libraries to link
The following works for me:
INCLUDE(CheckFunctionExists)
SET(CMAKE_REQUIRED_LIBRARIES "pthread")
CHECK_FUNCTION_EXISTS(pthread_create HAVE_PTHREAD)
--
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20080229/a19d5b99/attachment.htm
More information about the CMake
mailing list