FindPThreadWin32.cmake 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. include(FindPackageHandleStandardArgs)
  2. set(_root ${PThreadWin32_ROOT})
  3. if (NOT _root)
  4. find_package_handle_standard_args(PThreadWin32
  5. FOUND_VAR PThreadWin32_FOUND
  6. REQUIRED_VARS _root) # 强制搜不到包
  7. unset(_root)
  8. endif()
  9. # PThreadWin32_ROOT 必须是 PThreadWin32的安装目录
  10. # PThreadWin32
  11. find_path(pthread_h NAMES pthread.h HINTS ${_root}/include DOC "PThreadWin32 include directory" NO_DEFAULT_PATH)
  12. find_library(pthread_lib NAMES "libpthreadVC3d.lib" "libpthreadVC3.lib"
  13. libPThreadWin32 HINTS ${_root}/lib DOC "PThreadWin32 library" NO_DEFAULT_PATH)
  14. set(pthread_INCLUDE_DIRS ${pthread_h})
  15. set(pthread_LIBRARIES ${pthread_lib})
  16. unset(pthread_h CACHE)
  17. unset(pthread_lib CACHE)
  18. message(STATUS "pthread_lib = ${pthread_INCLUDE_DIRS}")
  19. find_package_handle_standard_args(PThreadWin32
  20. FOUND_VAR PThreadWin32_FOUND
  21. REQUIRED_VARS
  22. pthread_INCLUDE_DIRS
  23. pthread_LIBRARIES) # 强制搜不到包
  24. if (PThreadWin32_FOUND)
  25. add_library(PThreadWin32::pthread STATIC IMPORTED)
  26. set_target_properties(PThreadWin32::pthread PROPERTIES
  27. IMPORTED_LOCATION "${pthread_LIBRARIES}"
  28. INTERFACE_INCLUDE_DIRECTORIES "${pthread_INCLUDE_DIRS}"
  29. INTERFACE_SOURCES
  30. "${pthread_INCLUDE_DIRS}/pthread.h"
  31. "${pthread_INCLUDE_DIRS}/sched.h"
  32. "${pthread_INCLUDE_DIRS}/semaphore.h"
  33. "${pthread_INCLUDE_DIRS}/_ptw32.h"
  34. PUBLIC_HEADER
  35. "${pthread_INCLUDE_DIRS}/pthread.h"
  36. "${pthread_INCLUDE_DIRS}/sched.h"
  37. "${pthread_INCLUDE_DIRS}/semaphore.h"
  38. "${pthread_INCLUDE_DIRS}/_ptw32.h")
  39. endif()