Skip to content

Commit

Permalink
CMake: Cleanup Threads Search
Browse files Browse the repository at this point in the history
Search Threads upfront, because we configure specific options
that are cached and reused by dependencies in superbuilds. This
brings all `find_package` calls in the same central file before
we start including sub-directories.
  • Loading branch information
ax3l committed Aug 21, 2023
1 parent 79a6e96 commit 6fead6b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
15 changes: 6 additions & 9 deletions Blosc2Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules")

# this section stores which configuration options were set
set(HAVE_THREADS @Threads_FOUND@)
set(HAVE_THREADS @HAVE_THREADS@)
set(HAVE_IPP @HAVE_IPP@)
set(HAVE_ZLIB_NG @HAVE_ZLIB_NG@)
set(DEACTIVATE_IPP @DEACTIVATE_IPP@)
Expand All @@ -26,16 +26,13 @@ set(PREFER_EXTERNAL_ZSTD @PREFER_EXTERNAL_ZSTD@)
# additionally, the Blosc2_..._FOUND variables are used to support
# find_package(Blosc2 ... COMPONENTS ... ...)
# this enables downstream projects to express the need for specific features.
if(WIN32)
if(HAVE_THREADS)
find_dependency(Threads)
set(Blosc2_THREADS_FOUND TRUE)
else()
set(Blosc2_THREADS_FOUND FALSE)
endif()
else()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) # pre 3.1
set(THREADS_PREFER_PTHREAD_FLAG TRUE) # CMake 3.1+
if(HAVE_THREADS)
find_dependency(Threads)
set(Blosc2_THREADS_FOUND TRUE)
else()
set(Blosc2_THREADS_FOUND FALSE)
endif()

if(NOT DEACTIVATE_IPP AND HAVE_IPP)
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ if(BUILD_LITE)
set(DEACTIVATE_ZSTD ON)
endif()

# Threads
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) # pre 3.1
set(THREADS_PREFER_PTHREAD_FLAG TRUE) # CMake 3.1+
if(WIN32)
# try to use the system library
find_package(Threads)
else()
find_package(Threads REQUIRED)
endif()
if(Threads_FOUND)
set(HAVE_THREADS ON)
else()
set(HAVE_THREADS OFF)
endif()

if(PREFER_EXTERNAL_LZ4)
find_package(LZ4)
else()
Expand Down
13 changes: 5 additions & 8 deletions blosc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,20 @@ if(NOT DEACTIVATE_ZSTD)
endif()
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE) # pre 3.1
set(THREADS_PREFER_PTHREAD_FLAG TRUE) # CMake 3.1+
# Threads and dlopen/dlclose
if(WIN32)
# try to use the system library
find_package(Threads)
if(NOT Threads_FOUND)
message(STATUS "using the internal pthread library for win32 systems.")
list(APPEND SOURCES blosc/win32/pthread.c)
else()
if(HAVE_THREADS)
if(CMAKE_VERSION VERSION_LESS 3.1)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
else()
set(LIBS ${LIBS} Threads::Threads)
endif()
else()
message(STATUS "using the internal pthread library for win32 systems.")
list(APPEND SOURCES blosc/win32/pthread.c)
endif()
else()
find_package(Threads REQUIRED)
if(CMAKE_VERSION VERSION_LESS 3.1)
set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
else()
Expand Down

0 comments on commit 6fead6b

Please sign in to comment.