[CMake] FindThreads: the odd one out?

Philip Lowman philip at yhbt.com
Sat Aug 29 22:36:15 EDT 2009


On Fri, Aug 28, 2009 at 4:29 AM, Marcel Loose <loose at astron.nl> wrote:

> Hi all,
>
> Up till now I've been using the not officially supported and released
> FindPthreads.cmake macro to check for the presence of pthreads. However,
> the maintainer of that macro wrote (a comment in Mantis) that he would
> drop support for FindPthreads in favor of the more general and
> officially supported FindThreads.cmake macro.
>
> However, I have some difficulty understandig how to properly use
> FindThreads.cmake. Contrary to most FindXXX macros it does not set
> THREADS_INCLUDE_DIR and THREADS_LIBRARY. It does set some *_INIT
> variables, but I thought that *_INIT variables were only used by CMake
> itself to preset compiler and linker flags, and that these were not to
> be used outside.
>
> Could someone shed a light on this?


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?

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.

i.e.

set(Threads_SEARCH_PTHREADS_WIN32 true)
find_package(Threads REQUIRED)
  # if(WIN32) creates Threads_INCLUDE_DIR, Threads_PTHREADWIN32_LIBRARY
cache vars, sets CMAKE_THREAD_LIBS_INIT accordingly
  # else, do nothing
include_directories(${Threads_INCLUDE_DIR})
target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090829/3c81bbf6/attachment.htm>


More information about the CMake mailing list