FindDetours.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #[=======================================================================[.rst
  2. FindDetours
  3. -----------
  4. FindModule for Detours and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``Detours::Detours``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Detours_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Detours_VERSION``
  17. Detected version of found Detours libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Detours_LIBRARY``
  22. Path to the library component of Detours.
  23. ``Detours_INCLUDE_DIR``
  24. Directory containing ``detours.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_check_modules(PC_Detours QUIET detours)
  30. endif()
  31. find_path(Detours_INCLUDE_DIR NAMES detours.h HINTS ${PC_Detours_INCLUDE_DIRS} DOC "Detours include directory")
  32. find_library(Detours_IMPLIB NAMES detours HINTS ${PC_Detours_LIBRARY_DIRS} DOC "Detours location")
  33. cmake_path(GET Detours_IMPLIB PARENT_PATH _implib_path)
  34. cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin")
  35. find_program(Detours_LIBRARY NAMES detours.dll HINTS ${_implib_path} ${_bin_path} DOC "Detours DLL location")
  36. if(NOT Detours_LIBRARY)
  37. set(Detours_LIBRARY "${Detours_IMPLIB}")
  38. endif()
  39. unset(_implib_path)
  40. unset(_bin_path)
  41. if(PC_Detours_VERSION VERSION_GREATER 0)
  42. set(Detours_VERSION ${PC_Detours_VERSION})
  43. else()
  44. if(NOT Detours_FIND_QUIETLY)
  45. message(AUTHOR_WARNING "Failed to find detours version.")
  46. endif()
  47. set(Detours_VERSION 0.0.0)
  48. endif()
  49. find_package_handle_standard_args(
  50. Detours
  51. REQUIRED_VARS Detours_LIBRARY Detours_INCLUDE_DIR
  52. VERSION_VAR Detours_VERSION
  53. REASON_FAILURE_MESSAGE "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH."
  54. )
  55. mark_as_advanced(Detours_INCLUDE_DIR Detours_LIBRARY)
  56. if(Detours_FOUND)
  57. if(NOT TARGET Detours::Detours)
  58. if(IS_ABSOLUTE "${Detours_LIBRARY}")
  59. if(DEFINED Detours_IMPLIB)
  60. if(Detours_IMPLIB STREQUAL Detours_LIBRARY)
  61. add_library(Detours::Detours STATIC IMPORTED)
  62. else()
  63. add_library(Detours::Detours SHARED IMPORTED)
  64. set_property(TARGET Detours::Detours PROPERTY IMPORTED_IMPLIB "${Detours_IMPLIB}")
  65. endif()
  66. else()
  67. add_library(Detours::Detours UNKNOWN IMPORTED)
  68. endif()
  69. set_property(TARGET Detours::Detours PROPERTY IMPORTED_LOCATION "${Detours_LIBRARY}")
  70. else()
  71. add_library(Detours::Detours INTERFACE IMPORTED)
  72. set_property(TARGET Detours::Detours PROPERTY IMPORTED_LIBNAME "${Detours_LIBRARY}")
  73. endif()
  74. set_target_properties(
  75. Detours::Detours
  76. PROPERTIES
  77. INTERFACE_COMPILE_OPTIONS "${PC_Detours_CFLAGS_OTHER}"
  78. INTERFACE_INCLUDE_DIRECTORIES "${Detours_INCLUDE_DIR}"
  79. VERSION ${Detours_VERSION}
  80. )
  81. endif()
  82. endif()
  83. include(FeatureSummary)
  84. set_package_properties(
  85. Detours
  86. PROPERTIES
  87. URL "https://github.com/microsoft/detours"
  88. DESCRIPTION "Detours is a software package for monitoring and instrumenting API calls on Windows."
  89. )