[Cmake] How to Include standard libraries...

Brad King brad . king at kitware . com
Mon, 8 Sep 2003 16:18:25 -0400 (EDT)


> I am trying to find a way to add libraries such as pthread and math
> libraries to my executable. What command should I use?

Unfortunately this isn't very clean yet.  There is no notion of "standard"
libraries.

For the math library, just do this:

IF(UNIX)
  TARGET_LINK_LIBRARYES(myexe m)
ENDIF(UNIX)

Windows compilers include it automatically.

For threads:

On Visual Studio, the multi-threaded runtime library is used by default.
For UNIX/Cygwin, use

FIND_PACKAGE(Threads)

The following variables will be set:

# CMAKE_THREAD_LIBS_INIT        - the thread library to link into an application (-lpthread )
# CMAKE_USE_SPROC_INIT          - are we using sproc?
# CMAKE_USE_WIN32_THREADS_INIT  - are we using WIN32 threads
# CMAKE_USE_PTHREADS_INIT       - are we using pthreads
# CMAKE_HP_PTHREADS_INIT        - are we using hp pthreads

The first can be used directly for linking:

TARGET_LINK_LIBRARIES(myexe ${CMAKE_THREAD_LIBS_INIT})

The others can be used to help configure your sources to include the right
headers.

-Brad