<b><code></code></b>On Thu, Feb 28, 2008 at 9:21 AM, Brantner Matthias &lt;<a href="mailto:brantner@m-brantner.de">brantner@m-brantner.de</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I wanted to write a check whether pthread_mutex_init and<br>
pthread_spin_init exist in pthread.h. Therefore,<br>
I used the following CMake commands:<br>
<br>
INCLUDE(CheckFunctionExists)<br>
CHECK_FUNCTION_EXISTS(&quot;pthread_spin_init&quot;<br>
HAVE_PTHREAD_SPINLOCK)<br>
CHECK_FUNCTION_EXISTS(&quot;pthread_mutex_init&quot; &nbsp; &nbsp; &nbsp; &nbsp;HAVE_PTHREAD_MUTEX)<br>
<br>
The result of running CMake on a Linux system gives me<br>
<br>
-- Looking for pthread_spin_init<br>
-- Looking for pthread_spin_init - not found<br>
-- Looking for pthread_mutex_init<br>
-- Looking for pthread_mutex_init - found.<br>
<br>
Although pthread_spin_init is declared in my pthread.h and my code<br>
compiles and uses it, CMake does not find it.<br>
However, I saw that this function is guarded in an &quot;#ifdef<br>
__USE_XOPEN2K&quot;. Could that be the reason why<br>
CMake doesn&#39;t find it or am I doing something wrong here?<br>
<br></blockquote></div><br clear="all"><br><b><code>CheckFunctionExists</code></b>: macro which checks if the function exists<br>

    
<p>CHECK_FUNCTION_EXISTS(FUNCTION VARIABLE)<br></p>
<pre>  FUNCTION - the name of the function<br>  VARIABLE - variable to store the result<br></pre>

    
<p>The following variables may be set before calling this macro to modify the way the check is run:<br></p>
<pre>  CMAKE_REQUIRED_FLAGS = string of compile command line flags<br>  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)<br>  CMAKE_REQUIRED_INCLUDES = list of include directories<br>  CMAKE_REQUIRED_LIBRARIES = list of libraries to link</pre>

<br><br>The following works for me:<br><br>INCLUDE(CheckFunctionExists)<br>SET(CMAKE_REQUIRED_LIBRARIES &quot;pthread&quot;)<br>CHECK_FUNCTION_EXISTS(pthread_create HAVE_PTHREAD)<br><br><br><br><br>-- <br>Philip Lowman