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

Revision 9949, 3.4 kB (checked in by robert, 6 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")
"

Line 
1# This file should only be included when using Pthreads
2
3INCLUDE (CheckFunctionExists)
4INCLUDE (CheckLibraryExists)
5INCLUDE (CheckSymbolExists)
6INCLUDE (CheckCXXSourceCompiles)
7
8SET(LIB_NAME OpenThreads)
9SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})
10
11ADD_LIBRARY(${LIB_NAME}
12    ${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
13    ${LIB_PUBLIC_HEADERS}
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
23    ../common/Atomic.cpp
24)
25
26IF(OPENTHREADS_SONAMES)
27  SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
28ENDIF()
29
30SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
31SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
32
33CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)
34IF(HAVE_PTHREAD_YIELD)
35  ADD_DEFINITIONS(-DHAVE_PTHREAD_YIELD)
36ELSE()
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")
43    ENDIF()
44  ENDIF()
45  IF(HAVE_SCHED_YIELD)
46    ADD_DEFINITIONS(-DHAVE_SCHED_YIELD)
47  ENDIF()
48ENDIF()
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")
54ENDIF()
55
56CHECK_FUNCTION_EXISTS(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
57IF(HAVE_PTHREAD_SETCONCURRENCY)
58  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCONCURRENCY)
59ENDIF()
60
61CHECK_FUNCTION_EXISTS(pthread_getconcurrency HAVE_PTHREAD_GETCONCURRENCY)
62IF(HAVE_PTHREAD_GETCONCURRENCY)
63  ADD_DEFINITIONS(-DHAVE_PTHREAD_GETCONCURRENCY)
64ENDIF()
65
66CHECK_FUNCTION_EXISTS(pthread_setaffinity_np HAVE_PTHREAD_SETAFFINITY_NP)
67IF(HAVE_PTHREAD_SETAFFINITY_NP)
68  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETAFFINITY_NP)
69ELSE()
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)
79  ELSE()
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)
89    ENDIF()
90  ENDIF()
91ENDIF()
92
93SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}")
94
95TARGET_LINK_LIBRARIES(${LIB_NAME}
96    ${CMAKE_THREAD_LIBS_INIT}
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(
103    ${CMAKE_CURRENT_BINARY_DIR}
104)
105
106INSTALL(
107    TARGETS OpenThreads
108    ARCHIVE DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads-dev
109    LIBRARY DESTINATION lib${LIB_POSTFIX} COMPONENT libopenthreads
110    RUNTIME DESTINATION bin COMPONENT libopenthreads
111)
112INSTALL(
113    FILES ${OpenThreads_PUBLIC_HEADERS}
114    DESTINATION include/OpenThreads
115    COMPONENT libopenthreads-dev
116)
117
118#commented out# INCLUDE(ModuleInstall OPTIONAL)
Note: See TracBrowser for help on using the browser.