Skip to content

Commit

Permalink
Cleanup cmake thread detection
Browse files Browse the repository at this point in the history
Remove old variables, prepare for glibc 2.34+ where pthread moves into
libc to detect semaphores.
Force enable C11 for core library to turn on atomics for older compilers
Fix error messages

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Sep 7, 2021
1 parent 88a1f40 commit ee35a19
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
23 changes: 13 additions & 10 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ endif()
###check_include_files(pthread.h ILMTHREAD_HAVE_PTHREAD)
if(OPENEXR_ENABLE_THREADING AND Threads_FOUND)
set(ILMTHREAD_THREADING_ENABLED ON)
if(CMAKE_HAVE_PTHREAD_H OR CMAKE_USE_PTHREADS_INIT OR CMAKE_HP_PTHREAD_INIT)
set(ILMTHREAD_HAVE_PTHREAD ON)
endif()

# we have threads, but do we have posix semaphores for sem_init?
# should be in pthreads
Expand All @@ -112,11 +109,15 @@ if(OPENEXR_ENABLE_THREADING AND Threads_FOUND)
else()
check_include_files(semaphore.h ILMTHREAD_HAVE_SEMAPHORE_H)
endif()
if(ILMTHREAD_HAVE_SEMAPHORE_H AND ILMTHREAD_HAVE_PTHREAD)
if(ILMTHREAD_HAVE_SEMAPHORE_H)
# should just be in libc, so no need for check_library_exists
set(CMAKE_REQUIRED_FLAGS ${CMAKE_THREAD_LIBS_INIT})
check_library_exists(pthread sem_init "" ILMTHREAD_HAVE_POSIX_SEMAPHORES)
set(CMAKE_REQUIRED_FLAGS)
if(CMAKE_HAVE_LIBC_PTHREAD)
set(ILMTHREAD_HAVE_POSIX_SEMAPHORES ON)
else()
set(CMAKE_REQUIRED_FLAGS ${CMAKE_THREAD_LIBS_INIT})
check_library_exists(pthread sem_init "" ILMTHREAD_HAVE_POSIX_SEMAPHORES)
set(CMAKE_REQUIRED_FLAGS)
endif()
endif()
endif()
endif()
Expand Down Expand Up @@ -190,10 +191,12 @@ if(OPENEXR_INSTALL_PKG_CONFIG)
if(OPENEXR_ENABLE_THREADING AND TARGET Threads::Threads)
# hrm, can't use properties as they end up as generator expressions
# which don't seem to evaluate
if(THREADS_HAVE_PTHREAD_ARG)
set(PTHREAD_CFLAGS "-pthread")
if(THREADS_HAVE_PTHREAD_ARG OR CMAKE_HAVE_LIBC_PTHREAD)
set(exr_pthread_cflags "-pthread")
else()
set(exr_pthread_cflags "")
endif()
set(PTHREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
set(exr_pthread_libs ${CMAKE_THREAD_LIBS_INIT})
endif()
if(NOT zlib_INTERNAL_DIR)
set(zlib_link "-lz")
Expand Down
4 changes: 2 additions & 2 deletions cmake/OpenEXR.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Name: OpenEXR
Description: OpenEXR image library
Version: @OPENEXR_VERSION@

Libs: -L${libdir} -lOpenEXR${libsuffix} -lOpenEXRUtil${libsuffix} -lOpenEXRCore${libsuffix} -lIex${libsuffix} -lIlmThread${libsuffix}
Cflags: -I${includedir} -I${OpenEXR_includedir}
Libs: @exr_pthread_libs@ -L${libdir} -lOpenEXR${libsuffix} -lOpenEXRUtil${libsuffix} -lOpenEXRCore${libsuffix} -lIex${libsuffix} -lIlmThread${libsuffix}
Cflags: -I${includedir} -I${OpenEXR_includedir} @exr_pthread_cflags@
Requires: Imath
Libs.private: @zlib_link@
4 changes: 4 additions & 0 deletions cmake/OpenEXRLibraryDefine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function(OPENEXR_DEFINE_LIBRARY libname)
${OPENEXR_CURLIB_HEADERS}
${OPENEXR_CURLIB_SOURCES})

# we use atomics internally for the core library, so need C11, but
# is only a private requirement
target_compile_features(${objlib} PRIVATE c_std_11)
target_compile_features(${objlib} PUBLIC cxx_std_${OPENEXR_CXX_STANDARD})
if(OPENEXR_CURLIB_PRIV_EXPORT AND BUILD_SHARED_LIBS)
target_compile_definitions(${objlib} PRIVATE ${OPENEXR_CURLIB_PRIV_EXPORT})
Expand All @@ -32,6 +35,7 @@ function(OPENEXR_DEFINE_LIBRARY libname)
target_link_libraries(${objlib} PRIVATE ${OPENEXR_CURLIB_PRIVATE_DEPS})
endif()
set_target_properties(${objlib} PROPERTIES
C_STANDARD_REQUIRED ON
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
POSITION_INDEPENDENT_CODE ON
Expand Down
8 changes: 3 additions & 5 deletions cmake/OpenEXRSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(OPENEXR_CXX_STANDARD "${tmp}" CACHE STRING "C++ standard to compile against"
set(tmp)

set(OPENEXR_NAMESPACE_CUSTOM "0" CACHE STRING "Whether the namespace has been customized (so external users know)")
set(OPENEXR_INTERNAL_IMF_NAMESPACE "Imf_${OPENEXR_VERSION_API}" CACHE STRING "Real namespace for Imath that will end up in compiled symbols")
set(OPENEXR_INTERNAL_IMF_NAMESPACE "Imf_${OPENEXR_VERSION_API}" CACHE STRING "Real namespace for OpenEXR that will end up in compiled symbols")
set(OPENEXR_IMF_NAMESPACE "Imf" CACHE STRING "Public namespace alias for OpenEXR")
set(OPENEXR_PACKAGE_NAME "OpenEXR ${OPENEXR_VERSION}${OPENEXR_VERSION_RELEASE_TYPE}" CACHE STRING "Public string / label for displaying package")

Expand Down Expand Up @@ -148,13 +148,11 @@ endif()
# so we know how to add the thread stuff to the pkg-config package
# which is the only (but good) reason.
if(OPENEXR_ENABLE_THREADING)

if(NOT TARGET Threads::Threads)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(NOT Threads_FOUND)
message(FATAL_ERROR "Unable to find a threading library which is required for OpenEXR")
message(FATAL_ERROR "Unable to find a threading library, disable with OPENEXR_ENABLE_THREADING=OFF")
endif()
endif()
endif()
Expand Down

0 comments on commit ee35a19

Please sign in to comment.