FindThreads: the odd one out?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

FindThreads: the odd one out?

Marcel Loose
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?

Best regards,
Marcel Loose.


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: FindThreads: the odd one out?

Philip Lowman
On Fri, Aug 28, 2009 at 4:29 AM, Marcel Loose <[hidden email]> 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

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: FindThreads: the odd one out?

Alexander Neundorf-3
On Sunday 30 August 2009, Philip Lowman wrote:

> On Fri, Aug 28, 2009 at 4:29 AM, Marcel Loose <[hidden email]> 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

This one: http://sourceware.org/pthreads-win32/ ?
3 years ago I was using it (to make that software easily portable).

I also think FindThreads.cmake is somewhat strange, doesn't it basically load
the thread library of the current platform ? That means that you get
different APIs on different platforms and therefor need different code ?

Alex
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: FindThreads: the odd one out?

Marcel Loose
In reply to this post by Marcel Loose
On Fri, 2009-09-04 at 21:55 +0200, Alexander Neundorf wrote:

> On Sunday 30 August 2009, Philip Lowman wrote:
> > On Fri, Aug 28, 2009 at 4:29 AM, Marcel Loose <[hidden email]> 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
>
> This one: http://sourceware.org/pthreads-win32/ ?
> 3 years ago I was using it (to make that software easily portable).
>
> I also think FindThreads.cmake is somewhat strange, doesn't it basically load
> the thread library of the current platform ? That means that you get
> different APIs on different platforms and therefor need different code ?
>
> Alex

It turns out there different versions of the FindPthreads macro lying
around :-(. I was refering to this
http://www.vtk.org/Bug/file_download.php?file_id=2282&type=bug version,
which can be found here http://www.vtk.org/Bug/view.php?id=9074

Best regards,
Marcel Loose.



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake