FindLibHaru.cmake 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. find_path(LibHaru_INCLUDE_DIR
  2. NAMES hpdf.h
  3. DOC "libharu include directory")
  4. mark_as_advanced(LibHaru_INCLUDE_DIR)
  5. find_library(LibHaru_LIBRARY_RELEASE
  6. NAMES hpdf hpdfs libhpdf libhpdfs
  7. DOC "libharu release library")
  8. mark_as_advanced(LibHaru_LIBRARY_RELEASE)
  9. find_library(LibHaru_LIBRARY_DEBUG
  10. NAMES hpdfd hpdfsd libhpdfd libhpdfsd
  11. DOC "libharu debug library")
  12. mark_as_advanced(LibHaru_LIBRARY_DEBUG)
  13. if (LibHaru_INCLUDE_DIR)
  14. file(STRINGS "${LibHaru_INCLUDE_DIR}/hpdf_version.h" _libharu_version_lines
  15. REGEX "#define HPDF_(MAJOR|MINOR|BUGFIX|EXTRA)_VERSION")
  16. string(REGEX REPLACE ".*HPDF_MAJOR_VERSION *\([0-9]*\).*" "\\1" _libharu_version_major "${_libharu_version_lines}")
  17. string(REGEX REPLACE ".*HPDF_MINOR_VERSION *\([0-9]*\).*" "\\1" _libharu_version_minor "${_libharu_version_lines}")
  18. string(REGEX REPLACE ".*HPDF_BUGFIX_VERSION *\([0-9]*\).*" "\\1" _libharu_version_bugfix "${_libharu_version_lines}")
  19. string(REGEX REPLACE ".*HPDF_EXTRA_VERSION *\"\([^\"]*\)\".*" "\\1" _libharu_version_extra "${_libharu_version_lines}")
  20. set(LibHaru_VERSION "${_libharu_version_major}.${_libharu_version_minor}.${_libharu_version_bugfix}")
  21. if (_libharu_version_extra)
  22. string(APPEND LibHaru_VERSION
  23. "-${_libharu_version_extra}")
  24. endif ()
  25. unset(_libharu_version_major)
  26. unset(_libharu_version_minor)
  27. unset(_libharu_version_bugfix)
  28. unset(_libharu_version_extra)
  29. unset(_libharu_version_lines)
  30. endif ()
  31. include(SelectLibraryConfigurations)
  32. select_library_configurations(LibHaru)
  33. include(FindPackageHandleStandardArgs)
  34. find_package_handle_standard_args(LibHaru
  35. REQUIRED_VARS LibHaru_LIBRARY LibHaru_INCLUDE_DIR
  36. VERSION_VAR LibHaru_VERSION)
  37. if (LibHaru_FOUND)
  38. set(LibHaru_INCLUDE_DIRS "${LibHaru_INCLUDE_DIR}")
  39. set(LibHaru_LIBRARIES "${LibHaru_LIBRARY}")
  40. if (NOT TARGET LibHaru::LibHaru)
  41. include(vtkDetectLibraryType)
  42. set(libharu_library_type UNKNOWN)
  43. if (LibHaru_LIBRARY_RELEASE)
  44. vtk_detect_library_type(libharu_release_library_type
  45. PATH "${LibHaru_LIBRARY_RELEASE}")
  46. endif ()
  47. if (LibHaru_LIBRARY_DEBUG)
  48. vtk_detect_library_type(libharu_debug_library_type
  49. PATH "${LibHaru_LIBRARY_DEBUG}")
  50. endif ()
  51. if (libharu_release_library_type AND libharu_debug_library_type)
  52. if (libharu_release_library_type STREQUAL libharu_debug_library_type)
  53. set(libharu_library_type "${libharu_release_library_type}")
  54. endif ()
  55. elseif (libharu_release_library_type)
  56. set(libharu_library_type "${libharu_release_library_type}")
  57. elseif (libharu_debug_library_type)
  58. set(libharu_library_type "${libharu_debug_library_type}")
  59. endif ()
  60. add_library(LibHaru::LibHaru "${libharu_library_type}" IMPORTED)
  61. unset(libharu_release_library_type)
  62. unset(libharu_debug_library_type)
  63. unset(libharu_library_type)
  64. set_target_properties(LibHaru::LibHaru PROPERTIES
  65. INTERFACE_INCLUDE_DIRECTORIES "${LibHaru_INCLUDE_DIR}")
  66. if (LibHaru_LIBRARY_RELEASE)
  67. set_property(TARGET LibHaru::LibHaru APPEND PROPERTY
  68. IMPORTED_CONFIGURATIONS RELEASE)
  69. set_target_properties(LibHaru::LibHaru PROPERTIES
  70. IMPORTED_LOCATION_RELEASE "${LibHaru_LIBRARY_RELEASE}"
  71. IMPORTED_IMPLIB_RELEASE "${LibHaru_LIBRARY_RELEASE}")
  72. endif ()
  73. if (LibHaru_LIBRARY_DEBUG)
  74. set_property(TARGET LibHaru::LibHaru APPEND PROPERTY
  75. IMPORTED_CONFIGURATIONS DEBUG)
  76. set_target_properties(LibHaru::LibHaru PROPERTIES
  77. IMPORTED_LOCATION_DEBUG "${LibHaru_LIBRARY_DEBUG}"
  78. IMPORTED_IMPLIB_DEBUG "${LibHaru_LIBRARY_DEBUG}")
  79. endif ()
  80. endif ()
  81. endif ()