Files
2026-08-20 10:23:47 +08:00

97 lines
3.9 KiB
CMake

include_guard(GLOBAL)
# Self-contained PThreads4W discovery used both by the source tree and by the
# installed Renderive package. The build infrastructure may define
# PTHREADS4W_ROOT, but consumers only need to provide PThreads4W_ROOT,
# PTHREADS4W_ROOT, the corresponding environment variable, or CMAKE_PREFIX_PATH.
set(_PThreads4W_roots)
foreach(_root IN ITEMS "${PThreads4W_ROOT}" "${PTHREADS4W_ROOT}" "$ENV{PThreads4W_ROOT}" "$ENV{PTHREADS4W_ROOT}")
if (_root)
list(APPEND _PThreads4W_roots "${_root}")
endif ()
endforeach()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64)$")
set(PThreads4W_ARCH "x86_64")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM64|arm64|aarch64)$")
set(PThreads4W_ARCH "ARM64")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3-6]86)$")
set(PThreads4W_ARCH "x86")
else ()
set(PThreads4W_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
endif ()
find_path(PThreads4W_INCLUDE_DIR
NAMES pthread.h
HINTS ${_PThreads4W_roots}
PATH_SUFFIXES
"${PThreads4W_ARCH}/Debug/include"
"${PThreads4W_ARCH}/Release/include"
"${PThreads4W_ARCH}/RelWithDebInfo/include"
"${PThreads4W_ARCH}/MinSizeRel/include"
include)
find_library(PThreads4W_LIBRARY_DEBUG
NAMES pthreadVC3d
HINTS ${_PThreads4W_roots}
PATH_SUFFIXES "${PThreads4W_ARCH}/Debug/lib" Debug/lib lib)
find_library(PThreads4W_LIBRARY_RELEASE
NAMES pthreadVC3
HINTS ${_PThreads4W_roots}
PATH_SUFFIXES
"${PThreads4W_ARCH}/Release/lib"
"${PThreads4W_ARCH}/RelWithDebInfo/lib"
"${PThreads4W_ARCH}/MinSizeRel/lib"
Release/lib RelWithDebInfo/lib MinSizeRel/lib lib)
# Keep the conventional singular variable available for callers that inspect it.
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND PThreads4W_LIBRARY_DEBUG)
set(PThreads4W_LIBRARY "${PThreads4W_LIBRARY_DEBUG}")
elseif (PThreads4W_LIBRARY_RELEASE)
set(PThreads4W_LIBRARY "${PThreads4W_LIBRARY_RELEASE}")
else ()
set(PThreads4W_LIBRARY "${PThreads4W_LIBRARY_DEBUG}")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PThreads4W
REQUIRED_VARS PThreads4W_INCLUDE_DIR PThreads4W_LIBRARY)
if (PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W)
add_library(PThreads4W::PThreads4W UNKNOWN IMPORTED)
set_target_properties(PThreads4W::PThreads4W PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}")
if (PThreads4W_LIBRARY_DEBUG)
set_property(TARGET PThreads4W::PThreads4W APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(PThreads4W::PThreads4W PROPERTIES
IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG}")
endif ()
if (PThreads4W_LIBRARY_RELEASE)
set_property(TARGET PThreads4W::PThreads4W APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE RELWITHDEBINFO MINSIZEREL)
set_target_properties(PThreads4W::PThreads4W PROPERTIES
IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE}"
IMPORTED_LOCATION_RELWITHDEBINFO "${PThreads4W_LIBRARY_RELEASE}"
IMPORTED_LOCATION_MINSIZEREL "${PThreads4W_LIBRARY_RELEASE}")
endif ()
# A single available configuration remains usable for the other build types.
if (NOT PThreads4W_LIBRARY_RELEASE AND PThreads4W_LIBRARY_DEBUG)
set_target_properties(PThreads4W::PThreads4W PROPERTIES
MAP_IMPORTED_CONFIG_RELEASE DEBUG
MAP_IMPORTED_CONFIG_RELWITHDEBINFO DEBUG
MAP_IMPORTED_CONFIG_MINSIZEREL DEBUG)
elseif (NOT PThreads4W_LIBRARY_DEBUG AND PThreads4W_LIBRARY_RELEASE)
set_target_properties(PThreads4W::PThreads4W PROPERTIES
MAP_IMPORTED_CONFIG_DEBUG RELEASE)
endif ()
endif ()
mark_as_advanced(
PThreads4W_INCLUDE_DIR
PThreads4W_LIBRARY
PThreads4W_LIBRARY_DEBUG
PThreads4W_LIBRARY_RELEASE)
unset(_PThreads4W_roots)
unset(_root)