find/FindProj.cmake

49 lines
1.5 KiB
CMake
Raw Normal View History

2023-08-10 08:03:15 +00:00
set(PROJ_PREFIX "" CACHE PATH "The path to the prefix of an Proj installation")
find_path(PROJ_INCLUDE_DIR NAMES proj.h proj_api.h
PATHS
${PROJ_PREFIX}/include
/opt/local/include
/usr/include
/usr/local/include
)
find_library(PROJ_LIBRARIES NAMES proj
PATHS
${PROJ_PREFIX}/lib
/opt/local/lib
/usr/lib
/usr/local/lib
)
if(PROJ_INCLUDE_DIR AND PROJ_LIBRARIES AND NOT TARGET PROJ)
get_filename_component(PROJ_LIBRARY_DIR ${PROJ_LIBRARIES} PATH)
set(PROJ_FOUND TRUE)
add_library(Proj::Proj INTERFACE IMPORTED)
set_target_properties(Proj::Proj PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${PROJ_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${PROJ_LIBRARIES}"
)
endif()
if(PROJ_FOUND)
if(NOT PROJ_FIND_QUIETLY)
MESSAGE(STATUS "Found Proj: ${PROJ_LIBRARIES}")
endif()
set(HAVE_PROJ 1)
if(EXISTS ${PROJ_INCLUDE_DIR}/proj.h)
file(READ ${PROJ_INCLUDE_DIR}/proj.h proj_version)
string(REGEX REPLACE "^.*PROJ_VERSION_MAJOR +([0-9]+).*$" "\\1" PROJ_VERSION_MAJOR "${proj_version}")
elseif(EXISTS ${PROJ_INCLUDE_DIR}/proj_api.h)
file(READ ${PROJ_INCLUDE_DIR}/proj_api.h proj_version)
string(REGEX REPLACE "^.*PJ_VERSION ([0-9]+).*$" "\\1" PJ_VERSION "${proj_version}")
string(REGEX REPLACE "([0-9])([0-9])([0-9])" "\\1" PROJ_VERSION_MAJOR "${PJ_VERSION}")
endif()
set(PROJ_VERSION_MAJOR "${PROJ_VERSION_MAJOR}" CACHE INTERNAL "")
2023-08-10 08:03:15 +00:00
elseif(PROJ_FOUND)
if(PROJ_FIND_REQUIRED)
message(FATAL_ERROR "Could not find Proj")
endif()
endif()