[CMake] Updated FindThreads.cmake in tracker
Marcel Loose
loose at astron.nl
Mon Sep 21 06:07:37 EDT 2009
On Sun, 2009-09-20 at 19:32 -0400, Philip Lowman wrote:
> On Sun, Sep 20, 2009 at 3:02 PM, Hendrik Sattler
> <post at hendrik-sattler.de> wrote:
> Am Sonntag 20 September 2009 17:16:19 schrieb Philip Lowman:
>
> > Hello,
> >
> > I've merged (optional) Pthreads-win32 support into a
> FindThreads.cmake
> > attached in the tracker and added some documentation on how
> to use it.
> > Since FindThreads isn't my module I wanted to throw this up
> on the mailing
> > list for feedback.
> >
> > http://www.cmake.org/Bug/view.php?id=6399
> >
> >
> > Also, in regard to a previous mailing list thread about
> FindThreads...
> >
> > I'm not sure which platform the block "Check if compiler
> accepts -pthread"
> > is executed on. The documentation I attached to the code
> advises calling
> > "target_link_libraries(target ${CMAKE_THREAD_LIBS_INIT})".
> After grokking
> > the code a bit further I'm now guessing this "-pthread"
> argument is
> > technically accepted by the linker and not needed by the
> compiler, but it
> > would be nice to know this for sure to ensure the
> documentation is correct.
>
>
> gcc says:
> -pthread
> Adds support for multithreading with the pthreads
> library. This
> option sets flags for both the preprocessor and
> linker.
>
> So it may work to only use it during linking but this may
> cause subtle failure
> on some platforms.
>
> When writing FindThreads.cmake, it would be better to really
> rewrite it and
> use the common naming standards for cmake modules.
>
> I'm hesitant to rewrite anything that works, especially if it works on
> platforms I don't have access too. :)
>
> Include & library variables probably could be added if it can be done
> in a safe way with the compile checks already in place.
>
> Not sure on -pthread, we've never added it to our gcc command lines
> before. Looking at the man page, it's only a compile flag under
> IA-64, RS-6000, PPC, and SPARC. Would recommending people add it to
> their compiler flags and only rely on the output of
> ${CMAKE_THREAD_LIBS_INIT} for linking be the right thing to do?
>
>
> --
> Philip Lowman
Hmm, don't know if the documentation is correct.
I tested this on Linux x86_64 (gcc 4.3) and on an old i686 (gcc 3.2). On
both systems, when I diff the output of 'gcc -E -dM' and 'gcc -E -dM
-pthread' I get '#define _REENTRANT 1'.
So, -pthread clearly defines an extra preprocessor variable.
Marcel Loose
More information about the CMake
mailing list