Skip to content

Commit

Permalink
cmake refactor: move HP-UX specific logic into its own function
Browse files Browse the repository at this point in the history
reduce visual clutter of corner case configuration.
  • Loading branch information
Cyan4973 committed Mar 11, 2024
1 parent a4db145 commit 870ad90
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions build/cmake/CMakeLists.txt
Expand Up @@ -114,20 +114,29 @@ endif ()
#-----------------------------------------------------------------------------
# External dependencies
#-----------------------------------------------------------------------------
if (ZSTD_MULTITHREAD_SUPPORT AND UNIX)
# Define a function to handle special thread settings for HP-UX
# See https://github.com/facebook/zstd/pull/3862 for details.
function(setup_hpux_threads)
find_package(Threads)
if (NOT Threads_FOUND)
set(CMAKE_USE_PTHREADS_INIT 1 PARENT_SCOPE)
set(CMAKE_THREAD_LIBS_INIT -lpthread PARENT_SCOPE)
set(CMAKE_HAVE_THREADS_LIBRARY 1 PARENT_SCOPE)
set(Threads_FOUND TRUE PARENT_SCOPE)
endif()
endfunction()

function(setup_pthreads)
if (CMAKE_SYSTEM_NAME MATCHES "HP-UX")
find_package(Threads)
if (NOT Threads_FOUND)
set(CMAKE_USE_PTHREADS_INIT 1)
set(CMAKE_THREAD_LIBS_INIT -lpthread)
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif ()
else ()
setup_hpux_threads()
else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif ()
endif()
endfunction()

if (ZSTD_MULTITHREAD_SUPPORT AND UNIX)
setup_pthreads()
if (CMAKE_USE_PTHREADS_INIT)
set(THREADS_LIBS "${CMAKE_THREAD_LIBS_INIT}")
else()
Expand Down

0 comments on commit 870ad90

Please sign in to comment.