root/OpenSceneGraph/trunk/src/OpenThreads/pthreads/CMakeLists.txt @ 9949

Revision 9949, 3.4 kB (checked in by robert, 5 years ago)

From Philip Lowman, "Here's the promised cleanup of the OSG's CMakeLists.txt files for the src/ folder. I'll submit the others separately.

Also, there was also a small bug in osgDB's CMakeLists.txt that was causing an error when I tested with CMake 2.4.4.

IF(${OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX} STREQUAL "quicktime")
was changed to
IF(OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX STREQUAL "quicktime")
"

RevLine 
[6326]1# This file should only be included when using Pthreads
2
[7493]3INCLUDE (CheckFunctionExists)
4INCLUDE (CheckLibraryExists)
5INCLUDE (CheckSymbolExists)
6INCLUDE (CheckCXXSourceCompiles)
7
[6326]8SET(LIB_NAME OpenThreads)
9SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})
10
11ADD_LIBRARY(${LIB_NAME}
12    ${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
[8211]13    ${LIB_PUBLIC_HEADERS}
[8358]14    PThread.c++
15    PThreadBarrier.c++
16    PThreadBarrierPrivateData.h
17    PThreadCondition.c++
18    PThreadConditionPrivateData.h
19    PThreadMutex.c++
20    PThreadMutexPrivateData.h
21    PThreadPrivateData.h
22    ../common/Version.cpp
[8493]23    ../common/Atomic.cpp
[6326]24)
25
[6707]26IF(OPENTHREADS_SONAMES)
27  SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
[9949]28ENDIF()
[6707]29
[7493]30SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
[8358]31SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
[7493]32
33CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)
34IF(HAVE_PTHREAD_YIELD)
35  ADD_DEFINITIONS(-DHAVE_PTHREAD_YIELD)
[9949]36ELSE()
[7493]37  # sched_yield appears not in libc, pthreads or whatever on some systems
38  CHECK_FUNCTION_EXISTS(sched_yield HAVE_SCHED_YIELD)
39  IF(NOT HAVE_SCHED_YIELD)
40    CHECK_LIBRARY_EXISTS(rt sched_yield "" HAVE_SCHED_YIELD)
41    IF(HAVE_SCHED_YIELD)
42      SET(CMAKE_THREAD_LIBS_INIT "${CMAKE_THREAD_LIBS_INIT} -lrt")
[9949]43    ENDIF()
44  ENDIF()
[7493]45  IF(HAVE_SCHED_YIELD)
46    ADD_DEFINITIONS(-DHAVE_SCHED_YIELD)
[9949]47  ENDIF()
48ENDIF()
[7493]49
50IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
51  # need to have that for pthread_setaffinity_np on linux
52  ADD_DEFINITIONS(-D_GNU_SOURCE)
53  SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
[9949]54ENDIF()
[7493]55
56CHECK_FUNCTION_EXISTS(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
57IF(HAVE_PTHREAD_SETCONCURRENCY)
58  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCONCURRENCY)
[9949]59ENDIF()
[7493]60
61CHECK_FUNCTION_EXISTS(pthread_getconcurrency HAVE_PTHREAD_GETCONCURRENCY)
62IF(HAVE_PTHREAD_GETCONCURRENCY)
63  ADD_DEFINITIONS(-DHAVE_PTHREAD_GETCONCURRENCY)
[9949]64ENDIF()
[7493]65
66CHECK_FUNCTION_EXISTS(pthread_setaffinity_np HAVE_PTHREAD_SETAFFINITY_NP)
67IF(HAVE_PTHREAD_SETAFFINITY_NP)
68  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETAFFINITY_NP)
[9949]69ELSE()
[7493]70  CHECK_CXX_SOURCE_COMPILES("
71#include <sched.h>
72int main() {
73  cpu_set_t cpumask;
74  sched_setaffinity( 0, sizeof(cpumask), &cpumask );
75  return 0;
76}" HAVE_THREE_PARAM_SCHED_SETAFFINITY)
77  IF(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
78    ADD_DEFINITIONS(-DHAVE_THREE_PARAM_SCHED_SETAFFINITY)
[9949]79  ELSE()
[7493]80    CHECK_CXX_SOURCE_COMPILES("
81#include <sched.h>
82int main() {
83  cpu_set_t cpumask;
84  sched_setaffinity( 0, &cpumask );
85  return 0;
86}" HAVE_TWO_PARAM_SCHED_SETAFFINITY)
87    IF(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
88      ADD_DEFINITIONS(-DHAVE_TWO_PARAM_SCHED_SETAFFINITY)
[9949]89    ENDIF()
90  ENDIF()
91ENDIF()
[7493]92
93SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}")
94
[6326]95TARGET_LINK_LIBRARIES(${LIB_NAME}
[8358]96    ${CMAKE_THREAD_LIBS_INIT}
[6326]97)
98
99# Since we're building different platforms binaries in
100# their respective directories, we need to set the
101# link directory so it can find this location.
102LINK_DIRECTORIES(
[8358]103    ${CMAKE_CURRENT_BINARY_DIR}
[6326]104)
105
106INSTALL(
[8358]107    TARGETS OpenThreads
[9359]108    ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
[9339]109    LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
110    RUNTIME DESTINATION bin COMPONENT libopenthreads
[6326]111)
112INSTALL(
[8358]113    FILES ${OpenThreads_PUBLIC_HEADERS}
114    DESTINATION include/OpenThreads
[9339]115    COMPONENT libopenthreads-dev
[6326]116)
117
118#commented out# INCLUDE(ModuleInstall OPTIONAL)
Note: See TracBrowser for help on using the browser.