FindPThreads_windows.cmake 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Distributed under the OSI-approved BSD 3-Clause License.
  2. # Copyright Stefano Sinigardi
  3. #.rst:
  4. # FindPThreads
  5. # ------------
  6. #
  7. # Find the PThreads includes and library.
  8. #
  9. # Result Variables
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module defines the following variables:
  13. #
  14. # ``PThreads_windows_FOUND``
  15. # True if PThreads_windows library found
  16. #
  17. # ``PThreads_windows_INCLUDE_DIR``
  18. # Location of PThreads_windows headers
  19. #
  20. # ``PThreads_windows_LIBRARY``
  21. # List of libraries to link with when using PThreads_windows
  22. #
  23. include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
  24. include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
  25. if(NOT PThreads_windows_INCLUDE_DIR)
  26. find_path(PThreads_windows_INCLUDE_DIR NAMES pthread.h PATHS ${PThreads_windows_DIR} PATH_SUFFIXES include)
  27. endif()
  28. # Allow libraries to be set manually
  29. if(NOT PThreads_windows_LIBRARY)
  30. find_library(PThreads_windows_LIBRARY_RELEASE NAMES pthreadsVC2 pthreadVC2 PATHS ${PThreads_windows_DIR} PATH_SUFFIXES lib)
  31. find_library(PThreads_windows_LIBRARY_DEBUG NAMES pthreadsVC2d pthreadVC2d PATHS ${PThreads_windows_DIR} PATH_SUFFIXES lib)
  32. select_library_configurations(PThreads_windows)
  33. endif()
  34. find_package_handle_standard_args(PThreads_windows DEFAULT_MSG PThreads_windows_LIBRARY PThreads_windows_INCLUDE_DIR)
  35. mark_as_advanced(PThreads_windows_INCLUDE_DIR PThreads_windows_LIBRARY)
  36. set(PThreads_windows_DLL_DIR ${PThreads_windows_INCLUDE_DIR})
  37. list(TRANSFORM PThreads_windows_DLL_DIR APPEND "/../bin")
  38. message(STATUS "PThreads_windows_DLL_DIR: ${PThreads_windows_DLL_DIR}")
  39. find_file(PThreads_windows_LIBRARY_RELEASE_DLL NAMES pthreadVC2.dll PATHS ${PThreads_windows_DLL_DIR})
  40. find_file(PThreads_windows_LIBRARY_DEBUG_DLL NAMES pthreadVC2d.dll PATHS ${PThreads_windows_DLL_DIR})
  41. # Register imported libraries:
  42. # 1. If we can find a Windows .dll file (or if we can find both Debug and
  43. # Release libraries), we will set appropriate target properties for these.
  44. # 2. However, for most systems, we will only register the import location and
  45. # include directory.
  46. if( PThreads_windows_FOUND AND NOT TARGET PThreads_windows::PThreads_windows )
  47. if( EXISTS "${PThreads_windows_LIBRARY_RELEASE_DLL}" )
  48. add_library( PThreads_windows::PThreads_windows SHARED IMPORTED )
  49. set_target_properties( PThreads_windows::PThreads_windows PROPERTIES
  50. IMPORTED_LOCATION_RELEASE "${PThreads_windows_LIBRARY_RELEASE_DLL}"
  51. IMPORTED_IMPLIB "${PThreads_windows_LIBRARY_RELEASE}"
  52. INTERFACE_INCLUDE_DIRECTORIES "${PThreads_windows_INCLUDE_DIR}"
  53. IMPORTED_CONFIGURATIONS Release
  54. IMPORTED_LINK_INTERFACE_LANGUAGES "C" )
  55. if( EXISTS "${PThreads_windows_LIBRARY_DEBUG_DLL}" )
  56. set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug )
  57. set_target_properties( PThreads_windows::PThreads_windows PROPERTIES
  58. IMPORTED_LOCATION_DEBUG "${PThreads_windows_LIBRARY_DEBUG_DLL}"
  59. IMPORTED_IMPLIB_DEBUG "${PThreads_windows_LIBRARY_DEBUG}" )
  60. endif()
  61. else()
  62. add_library( PThreads_windows::PThreads_windows UNKNOWN IMPORTED )
  63. set_target_properties( PThreads_windows::PThreads_windows PROPERTIES
  64. IMPORTED_LOCATION_RELEASE "${PThreads_windows_LIBRARY_RELEASE}"
  65. INTERFACE_INCLUDE_DIRECTORIES "${PThreads_windows_INCLUDE_DIR}"
  66. IMPORTED_CONFIGURATIONS Release
  67. IMPORTED_LINK_INTERFACE_LANGUAGES "C" )
  68. if( EXISTS "${PThreads_windows_LIBRARY_DEBUG}" )
  69. set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug )
  70. set_target_properties( PThreads_windows::PThreads_windows PROPERTIES
  71. IMPORTED_LOCATION_DEBUG "${PThreads_windows_LIBRARY_DEBUG}" )
  72. endif()
  73. endif()
  74. endif()