FindLibPROJ.cmake 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. find_path(LibPROJ_INCLUDE_DIR
  2. NAMES proj_api.h proj.h
  3. DOC "libproj include directories")
  4. mark_as_advanced(LibPROJ_INCLUDE_DIR)
  5. find_library(LibPROJ_LIBRARY_RELEASE
  6. NAMES proj
  7. DOC "libproj release library")
  8. mark_as_advanced(LibPROJ_LIBRARY_RELEASE)
  9. find_library(LibPROJ_LIBRARY_DEBUG
  10. NAMES projd
  11. DOC "libproj debug library")
  12. mark_as_advanced(LibPROJ_LIBRARY_DEBUG)
  13. include(SelectLibraryConfigurations)
  14. select_library_configurations(LibPROJ)
  15. if (LibPROJ_INCLUDE_DIR)
  16. if (EXISTS "${LibPROJ_INCLUDE_DIR}/proj.h")
  17. file(STRINGS "${LibPROJ_INCLUDE_DIR}/proj.h" _libproj_version_lines REGEX "#define[ \t]+PROJ_VERSION_(MAJOR|MINOR|PATCH)")
  18. string(REGEX REPLACE ".*PROJ_VERSION_MAJOR *\([0-9]*\).*" "\\1" _libproj_version_major "${_libproj_version_lines}")
  19. string(REGEX REPLACE ".*PROJ_VERSION_MINOR *\([0-9]*\).*" "\\1" _libproj_version_minor "${_libproj_version_lines}")
  20. string(REGEX REPLACE ".*PROJ_VERSION_PATCH *\([0-9]*\).*" "\\1" _libproj_version_patch "${_libproj_version_lines}")
  21. else ()
  22. file(STRINGS "${LibPROJ_INCLUDE_DIR}/proj_api.h" _libproj_version_lines REGEX "#define[ \t]+PJ_VERSION")
  23. string(REGEX REPLACE ".*PJ_VERSION *\([0-9]*\).*" "\\1" _libproj_version "${_libproj_version_lines}")
  24. math(EXPR _libproj_version_major "${_libproj_version} / 100")
  25. math(EXPR _libproj_version_minor "(${_libproj_version} % 100) / 10")
  26. math(EXPR _libproj_version_patch "${_libproj_version} % 10")
  27. endif ()
  28. set(LibPROJ_VERSION "${_libproj_version_major}.${_libproj_version_minor}.${_libproj_version_patch}")
  29. set(LibPROJ_MAJOR_VERSION "${_libproj_version_major}")
  30. unset(_libproj_version_major)
  31. unset(_libproj_version_minor)
  32. unset(_libproj_version_patch)
  33. unset(_libproj_version)
  34. unset(_libproj_version_lines)
  35. endif ()
  36. include(FindPackageHandleStandardArgs)
  37. find_package_handle_standard_args(LibPROJ
  38. REQUIRED_VARS LibPROJ_LIBRARY LibPROJ_INCLUDE_DIR
  39. VERSION_VAR LibPROJ_VERSION)
  40. if (LibPROJ_FOUND)
  41. set(LibPROJ_INCLUDE_DIRS "${LibPROJ_INCLUDE_DIR}")
  42. set(LibPROJ_LIBRARIES "${LibPROJ_LIBRARY}")
  43. if (NOT TARGET LibPROJ::LibPROJ)
  44. add_library(LibPROJ::LibPROJ UNKNOWN IMPORTED)
  45. set_target_properties(LibPROJ::LibPROJ PROPERTIES
  46. INTERFACE_INCLUDE_DIRECTORIES "${LibPROJ_INCLUDE_DIR}")
  47. if (LibPROJ_LIBRARY_RELEASE)
  48. set_property(TARGET LibPROJ::LibPROJ APPEND PROPERTY
  49. IMPORTED_CONFIGURATIONS RELEASE)
  50. set_target_properties(LibPROJ::LibPROJ PROPERTIES
  51. IMPORTED_LOCATION_RELEASE "${LibPROJ_LIBRARY_RELEASE}")
  52. endif ()
  53. if (LibPROJ_LIBRARY_DEBUG)
  54. set_property(TARGET LibPROJ::LibPROJ APPEND PROPERTY
  55. IMPORTED_CONFIGURATIONS DEBUG)
  56. set_target_properties(LibPROJ::LibPROJ PROPERTIES
  57. IMPORTED_LOCATION_DEBUG "${LibPROJ_LIBRARY_DEBUG}")
  58. endif ()
  59. endif ()
  60. endif ()