FindOpenThreads.cmake 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # FindOpenThreads
  5. # ---------------
  6. #
  7. #
  8. #
  9. # OpenThreads is a C++ based threading library. Its largest userbase
  10. # seems to OpenSceneGraph so you might notice I accept OSGDIR as an
  11. # environment path. I consider this part of the Findosg* suite used to
  12. # find OpenSceneGraph components. Each component is separate and you
  13. # must opt in to each module.
  14. #
  15. # Locate OpenThreads This module defines OPENTHREADS_LIBRARY
  16. # OPENTHREADS_FOUND, if false, do not try to link to OpenThreads
  17. # OPENTHREADS_INCLUDE_DIR, where to find the headers
  18. #
  19. # $OPENTHREADS_DIR is an environment variable that would correspond to
  20. # the ./configure --prefix=$OPENTHREADS_DIR used in building osg.
  21. #
  22. # [CMake 2.8.10]: The CMake variables OPENTHREADS_DIR or OSG_DIR can now
  23. # be used as well to influence detection, instead of needing to specify
  24. # an environment variable.
  25. #
  26. # Created by Eric Wing.
  27. # Header files are presumed to be included like
  28. # #include <OpenThreads/Thread>
  29. # To make it easier for one-step automated configuration/builds,
  30. # we leverage environmental paths. This is preferable
  31. # to the -DVAR=value switches because it insulates the
  32. # users from changes we may make in this script.
  33. # It also offers a little more flexibility than setting
  34. # the CMAKE_*_PATH since we can target specific components.
  35. # However, the default CMake behavior will search system paths
  36. # before anything else. This is problematic in the cases
  37. # where you have an older (stable) version installed, but
  38. # are trying to build a newer version.
  39. # CMake doesn't offer a nice way to globally control this behavior
  40. # so we have to do a nasty "double FIND_" in this module.
  41. # The first FIND disables the CMAKE_ search paths and only checks
  42. # the environmental paths.
  43. # If nothing is found, then the second find will search the
  44. # standard install paths.
  45. # Explicit -DVAR=value arguments should still be able to override everything.
  46. find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
  47. HINTS
  48. ENV OPENTHREADS_INCLUDE_DIR
  49. ENV OPENTHREADS_DIR
  50. ENV OSG_INCLUDE_DIR
  51. ENV OSG_DIR
  52. ENV OSGDIR
  53. ENV OpenThreads_ROOT
  54. ENV OSG_ROOT
  55. ${OPENTHREADS_DIR}
  56. ${OSG_DIR}
  57. PATH_SUFFIXES include
  58. )
  59. find_library(OPENTHREADS_LIBRARY
  60. NAMES OpenThreads OpenThreadsWin32
  61. HINTS
  62. ENV OPENTHREADS_LIBRARY_DIR
  63. ENV OPENTHREADS_DIR
  64. ENV OSG_LIBRARY_DIR
  65. ENV OSG_DIR
  66. ENV OSGDIR
  67. ENV OpenThreads_ROOT
  68. ENV OSG_ROOT
  69. ${OPENTHREADS_DIR}
  70. ${OSG_DIR}
  71. PATH_SUFFIXES lib
  72. )
  73. find_library(OPENTHREADS_LIBRARY_DEBUG
  74. NAMES OpenThreadsd OpenThreadsWin32d
  75. HINTS
  76. ENV OPENTHREADS_DEBUG_LIBRARY_DIR
  77. ENV OPENTHREADS_LIBRARY_DIR
  78. ENV OPENTHREADS_DIR
  79. ENV OSG_LIBRARY_DIR
  80. ENV OSG_DIR
  81. ENV OSGDIR
  82. ENV OpenThreads_ROOT
  83. ENV OSG_ROOT
  84. ${OPENTHREADS_DIR}
  85. ${OSG_DIR}
  86. PATH_SUFFIXES lib
  87. )
  88. if(OPENTHREADS_LIBRARY_DEBUG)
  89. set(OPENTHREADS_LIBRARIES
  90. optimized ${OPENTHREADS_LIBRARY}
  91. debug ${OPENTHREADS_LIBRARY_DEBUG})
  92. else()
  93. set(OPENTHREADS_LIBRARIES ${OPENTHREADS_LIBRARY})
  94. endif()
  95. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  96. FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG
  97. OPENTHREADS_LIBRARY OPENTHREADS_INCLUDE_DIR)