<div class="gmail_quote">On Fri, Aug 28, 2009 at 4:29 AM, Marcel Loose <span dir="ltr"><<a href="mailto:loose@astron.nl">loose@astron.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
Up till now I've been using the not officially supported and released<br>
FindPthreads.cmake macro to check for the presence of pthreads. However,<br>
the maintainer of that macro wrote (a comment in Mantis) that he would<br>
drop support for FindPthreads in favor of the more general and<br>
officially supported FindThreads.cmake macro.<br>
<br>
However, I have some difficulty understandig how to properly use<br>
FindThreads.cmake. Contrary to most FindXXX macros it does not set<br>
THREADS_INCLUDE_DIR and THREADS_LIBRARY. It does set some *_INIT<br>
variables, but I thought that *_INIT variables were only used by CMake<br>
itself to preset compiler and linker flags, and that these were not to<br>
be used outside.<br>
<br>
Could someone shed a light on this?</blockquote><div><br>I could also use some illumination on this. I get that you're supposed to use CMAKE_THREAD_LIBS_INIT with target_link_libraries() because libpthread isn't always called "libpthread", but it also looks like CMAKE_THREAD_LIBS_INIT can also be set to "-pthread" in the event the system doesn't have a pthread library and it's supposed to be a compile definition thing...??? If so, why one variable instead of two? Also what systems does this happen on?<br>
<br>I'm not sure if anyone is actually using the pthreads-win32 stuff I wrote aside from us at work, but I could probably merge it into FindThreads by just setting CMAKE_THREAD_LIBS_INIT to the location of the pthreads-win32 library detected (obviously searching for pthreads-win32 would require a new option so existing behavior of FindThreads would be maintained). I would still need an additional variable for the include directory since pthreads-win32 is not a system include, but this additional variable could simply be left empty if pthreads-win32 is not being searched for.<br>
<br>i.e.<br><br>set(Threads_SEARCH_PTHREADS_WIN32 true)<br>find_package(Threads REQUIRED)<br> # if(WIN32) creates Threads_INCLUDE_DIR, Threads_PTHREADWIN32_LIBRARY cache vars, sets CMAKE_THREAD_LIBS_INIT accordingly<br> # else, do nothing<br>
include_directories(${Threads_INCLUDE_DIR})<br>target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})<br><br></div></div>-- <br>Philip Lowman<br>