Parcourir la source

CMake: Streamline THREADS configuration

In particular this uses Threads::Threads (when available)
to let CMake figure out how to link against pthread/etc.
Sam Edwards il y a 7 ans
Parent
commit
a585dcf9ad
3 fichiers modifiés avec 119 ajouts et 229 suppressions
  1. 9 24
      dtool/Config.cmake
  2. 1 1
      dtool/src/dtoolbase/CMakeLists.txt
  3. 109 204
      panda/src/pipeline/CMakeLists.txt

+ 9 - 24
dtool/Config.cmake

@@ -631,25 +631,21 @@ set(HAVE_FLEX ${FLEX_FOUND})
 #
 #
 
 
 ### Configure threading support ###
 ### Configure threading support ###
+set(CMAKE_THREAD_PREFER_PTHREAD ON)
+set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads QUIET)
 find_package(Threads QUIET)
 
 
+set(THREADS_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
+set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})
+
 # Add basic use flag for threading
 # Add basic use flag for threading
-if(THREADS_FOUND)
-  option(HAVE_THREADS
-    "If on, compile Panda3D with threading support.
-Building in support for threading will enable Panda to take
-advantage of multiple CPU's if you have them (and if the OS
-supports kernel threads running on different CPU's), but it will
-slightly slow down Panda for the single CPU case." ON)
-else()
-  option(HAVE_THREADS
-    "If on, compile Panda3D with threading support.
+package_option(THREADS
+  "If on, compile Panda3D with threading support.
 Building in support for threading will enable Panda to take
 Building in support for threading will enable Panda to take
 advantage of multiple CPU's if you have them (and if the OS
 advantage of multiple CPU's if you have them (and if the OS
 supports kernel threads running on different CPU's), but it will
 supports kernel threads running on different CPU's), but it will
-slightly slow down Panda for the single CPU case." OFF)
-endif()
-
+slightly slow down Panda for the single CPU case."
+  IMPORTED_AS Threads::Threads)
 
 
 # Configure debug threads
 # Configure debug threads
 if(CMAKE_BUILD_TYPE MATCHES "Debug")
 if(CMAKE_BUILD_TYPE MATCHES "Debug")
@@ -658,17 +654,6 @@ else()
   option(DEBUG_THREADS "If on, enables debugging of thread and sync operations (i.e. mutexes, deadlocks)" OFF)
   option(DEBUG_THREADS "If on, enables debugging of thread and sync operations (i.e. mutexes, deadlocks)" OFF)
 endif()
 endif()
 
 
-if(HAVE_THREADS)
-  set(HAVE_POSIX_THREADS ${CMAKE_USE_PTHREADS_INIT})
-  if(HAVE_POSIX_THREADS)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
-    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pthread")
-    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pthread")
-    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -pthread")
-    set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -pthread")
-  endif()
-endif()
-
 option(SIMPLE_THREADS
 option(SIMPLE_THREADS
   "If on, compile with simulated threads.  Threads, by default, use
   "If on, compile with simulated threads.  Threads, by default, use
 OS-provided threading constructs, which usually allows for full
 OS-provided threading constructs, which usually allows for full

+ 1 - 1
dtool/src/dtoolbase/CMakeLists.txt

@@ -89,7 +89,7 @@ add_component_library(p3dtoolbase NOINIT SYMBOL BUILDING_DTOOL_DTOOLBASE
 target_include_directories(p3dtoolbase PUBLIC
 target_include_directories(p3dtoolbase PUBLIC
   $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
   $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
   $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/${CMAKE_CFG_INTDIR}>)
   $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/${CMAKE_CFG_INTDIR}>)
-target_link_libraries(p3dtoolbase PKG::EIGEN)
+target_link_libraries(p3dtoolbase PKG::EIGEN PKG::THREADS)
 target_interrogate(p3dtoolbase ${P3DTOOLBASE_SOURCES} EXTENSIONS ${P3DTOOLBASE_IGATEEXT})
 target_interrogate(p3dtoolbase ${P3DTOOLBASE_SOURCES} EXTENSIONS ${P3DTOOLBASE_IGATEEXT})
 
 
 if(NOT BUILD_METALIBS)
 if(NOT BUILD_METALIBS)

+ 109 - 204
panda/src/pipeline/CMakeLists.txt

@@ -1,230 +1,135 @@
 set(P3PIPELINE_HEADERS
 set(P3PIPELINE_HEADERS
-    contextSwitch.h
-    blockerSimple.h blockerSimple.I
-    conditionVar.h conditionVar.I
-    conditionVarDebug.h conditionVarDebug.I
-    conditionVarDirect.h conditionVarDirect.I
-    conditionVarDummyImpl.h conditionVarDummyImpl.I
-    conditionVarFull.h conditionVarFull.I
-    conditionVarFullDebug.h conditionVarFullDebug.I
-    conditionVarFullDirect.h conditionVarFullDirect.I
-    conditionVarImpl.h
-    conditionVarSimpleImpl.h conditionVarSimpleImpl.I
-    conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I
-    conditionVarPosixImpl.h conditionVarPosixImpl.I
-    config_pipeline.h
-    cycleData.h cycleData.I
-    cycleDataLockedReader.h cycleDataLockedReader.I
-    cycleDataLockedStageReader.h cycleDataLockedStageReader.I
-    cycleDataReader.h cycleDataReader.I
-    cycleDataStageReader.h cycleDataStageReader.I
-    cycleDataStageWriter.h cycleDataStageWriter.I
-    cycleDataWriter.h cycleDataWriter.I
-    cyclerHolder.h cyclerHolder.I
-    externalThread.h
-    genericThread.h genericThread.I
-    lightMutex.I lightMutex.h
-    lightMutexDirect.h lightMutexDirect.I
-    lightMutexHolder.I lightMutexHolder.h
-    lightReMutex.I lightReMutex.h
-    lightReMutexDirect.h lightReMutexDirect.I
-    lightReMutexHolder.I lightReMutexHolder.h
-    mainThread.h
-    mutexDebug.h mutexDebug.I
-    mutexDirect.h mutexDirect.I
-    mutexHolder.h mutexHolder.I
-    mutexSimpleImpl.h mutexSimpleImpl.I
-    mutexTrueImpl.h
-    pipeline.h pipeline.I
-    pipelineCycler.h pipelineCycler.I
-    pipelineCyclerLinks.h pipelineCyclerLinks.I
-    pipelineCyclerBase.h
-    pipelineCyclerDummyImpl.h pipelineCyclerDummyImpl.I
-    pipelineCyclerTrivialImpl.h pipelineCyclerTrivialImpl.I
-    pipelineCyclerTrueImpl.h pipelineCyclerTrueImpl.I
-    pmutex.h pmutex.I
-    reMutex.I reMutex.h
-    reMutexDirect.h reMutexDirect.I
-    reMutexHolder.I reMutexHolder.h
-    psemaphore.h psemaphore.I
-    thread.h thread.I threadImpl.h
-    threadDummyImpl.h threadDummyImpl.I
-    threadSimpleImpl.h threadSimpleImpl.I
-    threadPosixImpl.h threadPosixImpl.I
-    threadSimpleManager.h threadSimpleManager.I
-    threadPriority.h
-)
+  contextSwitch.h
+  blockerSimple.h blockerSimple.I
+  conditionVar.h conditionVar.I
+  conditionVarDebug.h conditionVarDebug.I
+  conditionVarDirect.h conditionVarDirect.I
+  conditionVarDummyImpl.h conditionVarDummyImpl.I
+  conditionVarFull.h conditionVarFull.I
+  conditionVarFullDebug.h conditionVarFullDebug.I
+  conditionVarFullDirect.h conditionVarFullDirect.I
+  conditionVarImpl.h
+  conditionVarSimpleImpl.h conditionVarSimpleImpl.I
+  conditionVarSpinlockImpl.h conditionVarSpinlockImpl.I
+  conditionVarPosixImpl.h conditionVarPosixImpl.I
+  config_pipeline.h
+  cycleData.h cycleData.I
+  cycleDataLockedReader.h cycleDataLockedReader.I
+  cycleDataLockedStageReader.h cycleDataLockedStageReader.I
+  cycleDataReader.h cycleDataReader.I
+  cycleDataStageReader.h cycleDataStageReader.I
+  cycleDataStageWriter.h cycleDataStageWriter.I
+  cycleDataWriter.h cycleDataWriter.I
+  cyclerHolder.h cyclerHolder.I
+  externalThread.h
+  genericThread.h genericThread.I
+  lightMutex.I lightMutex.h
+  lightMutexDirect.h lightMutexDirect.I
+  lightMutexHolder.I lightMutexHolder.h
+  lightReMutex.I lightReMutex.h
+  lightReMutexDirect.h lightReMutexDirect.I
+  lightReMutexHolder.I lightReMutexHolder.h
+  mainThread.h
+  mutexDebug.h mutexDebug.I
+  mutexDirect.h mutexDirect.I
+  mutexHolder.h mutexHolder.I
+  mutexSimpleImpl.h mutexSimpleImpl.I
+  mutexTrueImpl.h
+  pipeline.h pipeline.I
+  pipelineCycler.h pipelineCycler.I
+  pipelineCyclerLinks.h pipelineCyclerLinks.I
+  pipelineCyclerBase.h
+  pipelineCyclerDummyImpl.h pipelineCyclerDummyImpl.I
+  pipelineCyclerTrivialImpl.h pipelineCyclerTrivialImpl.I
+  pipelineCyclerTrueImpl.h pipelineCyclerTrueImpl.I
+  pmutex.h pmutex.I
+  reMutex.I reMutex.h
+  reMutexDirect.h reMutexDirect.I
+  reMutexHolder.I reMutexHolder.h
+  psemaphore.h psemaphore.I
+  thread.h thread.I threadImpl.h
+  threadDummyImpl.h threadDummyImpl.I
+  threadSimpleImpl.h threadSimpleImpl.I
+  threadPosixImpl.h threadPosixImpl.I
+  threadSimpleManager.h threadSimpleManager.I
+  threadPriority.h)
 
 
 set(P3PIPELINE_SOURCES
 set(P3PIPELINE_SOURCES
-    contextSwitch.c
-    conditionVar.cxx
-    conditionVarDebug.cxx
-    conditionVarDirect.cxx
-    conditionVarDummyImpl.cxx
-    conditionVarFull.cxx
-    conditionVarFullDebug.cxx
-    conditionVarFullDirect.cxx
-    conditionVarSimpleImpl.cxx
-    conditionVarSpinlockImpl.cxx
-    conditionVarPosixImpl.cxx
-    config_pipeline.cxx
-    cycleData.cxx
-    cycleDataLockedReader.cxx
-    cycleDataLockedStageReader.cxx
-    cycleDataReader.cxx
-    cycleDataStageReader.cxx
-    cycleDataStageWriter.cxx
-    cycleDataWriter.cxx
-    cyclerHolder.cxx
-    externalThread.cxx
-    genericThread.cxx
-    lightMutex.cxx
-    lightMutexDirect.cxx
-    lightMutexHolder.cxx
-    lightReMutex.cxx
-    lightReMutexDirect.cxx
-    lightReMutexHolder.cxx
-    mainThread.cxx
-    mutexDebug.cxx
-    mutexDirect.cxx
-    mutexHolder.cxx
-    mutexSimpleImpl.cxx
-    pipeline.cxx
-    pipelineCycler.cxx
-    pipelineCyclerDummyImpl.cxx
-    pipelineCyclerTrivialImpl.cxx
-    pipelineCyclerTrueImpl.cxx
-    pmutex.cxx
-    reMutex.cxx
-    reMutexDirect.cxx
-    reMutexHolder.cxx
-    psemaphore.cxx
-    thread.cxx
-    threadDummyImpl.cxx
-    threadPosixImpl.cxx
-    threadSimpleImpl.cxx
-    threadSimpleManager.cxx
-    threadPriority.cxx
-)
+  contextSwitch.c
+  conditionVar.cxx
+  conditionVarDebug.cxx
+  conditionVarDirect.cxx
+  conditionVarDummyImpl.cxx
+  conditionVarFull.cxx
+  conditionVarFullDebug.cxx
+  conditionVarFullDirect.cxx
+  conditionVarSimpleImpl.cxx
+  conditionVarSpinlockImpl.cxx
+  conditionVarPosixImpl.cxx
+  config_pipeline.cxx
+  cycleData.cxx
+  cycleDataLockedReader.cxx
+  cycleDataLockedStageReader.cxx
+  cycleDataReader.cxx
+  cycleDataStageReader.cxx
+  cycleDataStageWriter.cxx
+  cycleDataWriter.cxx
+  cyclerHolder.cxx
+  externalThread.cxx
+  genericThread.cxx
+  lightMutex.cxx
+  lightMutexDirect.cxx
+  lightMutexHolder.cxx
+  lightReMutex.cxx
+  lightReMutexDirect.cxx
+  lightReMutexHolder.cxx
+  mainThread.cxx
+  mutexDebug.cxx
+  mutexDirect.cxx
+  mutexHolder.cxx
+  mutexSimpleImpl.cxx
+  pipeline.cxx
+  pipelineCycler.cxx
+  pipelineCyclerDummyImpl.cxx
+  pipelineCyclerTrivialImpl.cxx
+  pipelineCyclerTrueImpl.cxx
+  pmutex.cxx
+  reMutex.cxx
+  reMutexDirect.cxx
+  reMutexHolder.cxx
+  psemaphore.cxx
+  thread.cxx
+  threadDummyImpl.cxx
+  threadPosixImpl.cxx
+  threadSimpleImpl.cxx
+  threadSimpleManager.cxx
+  threadPriority.cxx)
 
 
 if(WIN32)
 if(WIN32)
   set(P3PIPELINE_HEADERS
   set(P3PIPELINE_HEADERS
     ${P3PIPELINE_HEADERS}
     ${P3PIPELINE_HEADERS}
     conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I
     conditionVarFullWin32Impl.h conditionVarFullWin32Impl.I
     conditionVarWin32Impl.h conditionVarWin32Impl.I
     conditionVarWin32Impl.h conditionVarWin32Impl.I
-    threadWin32Impl.h threadWin32Impl.I
-  )
+    threadWin32Impl.h threadWin32Impl.I)
   set(P3PIPELINE_SOURCES
   set(P3PIPELINE_SOURCES
     ${P3PIPELINE_SOURCES}
     ${P3PIPELINE_SOURCES}
     conditionVarFullWin32Impl.cxx
     conditionVarFullWin32Impl.cxx
     conditionVarWin32Impl.cxx
     conditionVarWin32Impl.cxx
-    threadWin32Impl.cxx
-  )
+    threadWin32Impl.cxx)
 endif()
 endif()
 
 
 set(P3PIPELINE_IGATEEXT
 set(P3PIPELINE_IGATEEXT
-    pythonThread.cxx
-    pythonThread.h
-)
+  pythonThread.cxx
+  pythonThread.h)
 
 
 composite_sources(p3pipeline P3PIPELINE_SOURCES)
 composite_sources(p3pipeline P3PIPELINE_SOURCES)
 add_component_library(p3pipeline SYMBOL BUILDING_PANDA_PIPELINE
 add_component_library(p3pipeline SYMBOL BUILDING_PANDA_PIPELINE
   ${P3PIPELINE_HEADERS} ${P3PIPELINE_SOURCES})
   ${P3PIPELINE_HEADERS} ${P3PIPELINE_SOURCES})
-target_link_libraries(p3pipeline pandaexpress)
+target_link_libraries(p3pipeline pandaexpress
+  PKG::THREADS)
 target_interrogate(p3pipeline ALL EXTENSIONS ${P3PIPELINE_IGATEEXT})
 target_interrogate(p3pipeline ALL EXTENSIONS ${P3PIPELINE_IGATEEXT})
 
 
 if(NOT BUILD_METALIBS)
 if(NOT BUILD_METALIBS)
   install(TARGETS p3pipeline DESTINATION lib RUNTIME DESTINATION bin)
   install(TARGETS p3pipeline DESTINATION lib RUNTIME DESTINATION bin)
 endif()
 endif()
 install(FILES ${P3PIPELINE_HEADERS} DESTINATION include/panda3d)
 install(FILES ${P3PIPELINE_HEADERS} DESTINATION include/panda3d)
-
-#begin test_bin_target
-  #define TARGET test_threaddata
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
- #  p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
- #  p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-  #  test_threaddata.cxx
-
-#end test_bin_target
-
-
-#begin test_bin_target
-  #define TARGET test_diners
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
- #  p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
-  # p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-  #  test_diners.cxx
-
-#end test_bin_target
-
-
-#begin test_bin_target
-  #define TARGET test_mutex
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
- #  p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
- #  p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-  #  test_mutex.cxx
-
-#end test_bin_target
-
-
-#begin test_bin_target
-  #define TARGET test_concurrency
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
-#   p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
-#   p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
- #   test_concurrency.cxx
-
-#end test_bin_target
-
-
-#begin test_bin_target
-  #define TARGET test_delete
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
- #  p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
-  # p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-   # test_delete.cxx
-
-#end test_bin_target
-
-
-#begin test_bin_target
-  #define TARGET test_atomic
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
-  # p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
-  # p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-   # test_atomic.cxx
-
-#end test_bin_target
-
-
-
-#begin test_bin_target
-  #define TARGET test_setjmp
-  #define LOCAL_LIBS $[LOCAL_LIBS] p3pipeline
-  #define OTHER_LIBS \
-   #p3interrogatedb:c p3dconfig:c p3dtoolbase:c p3prc:c \
-  # p3dtoolutil:c p3dtool:m p3dtoolconfig:m p3pystub
-
-  #define SOURCES \
-    #test_setjmp.cxx
-
-#end test_bin_target