Skip to content

Commit

Permalink
CMake: rename GDAL_FIND_PACKAGE_PROJ_METHOD to GDAL_FIND_PACKAGE_PROJ…
Browse files Browse the repository at this point in the history
…_MODE, and only add find_dependency() in static builds
  • Loading branch information
rouault committed Mar 25, 2024
1 parent 6dd8859 commit d8b4bea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
33 changes: 23 additions & 10 deletions cmake/helpers/CheckDependentLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,36 @@ if (GDAL_USE_CRYPTOPP)
option(CRYPTOPP_USE_ONLY_CRYPTODLL_ALG "Use Only cryptoDLL alg. only work on dynamic DLL" OFF)
endif ()

set(GDAL_FIND_PACKAGE_PROJ_METHOD "CONFIG" CACHE STRING "Method to use for find_package(PROJ): CONFIG or MODULE")
set_property(CACHE GDAL_FIND_PACKAGE_PROJ_METHOD PROPERTY STRINGS "CONFIG" "MODULE")
mark_as_advanced(GDAL_FIND_PACKAGE_PROJ_METHOD)
if(GDAL_FIND_PACKAGE_PROJ_METHOD STREQUAL "MODULE")
find_package(PROJ MODULE REQUIRED)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ MODULE REQUIRED)\n")
set(GDAL_FIND_PACKAGE_PROJ_MODE "CUSTOM" CACHE STRING "Mode to use for find_package(PROJ): CUSTOM, CONFIG, MODULE or empty string")
set_property(CACHE GDAL_FIND_PACKAGE_PROJ_MODE PROPERTY STRINGS "CUSTOM" "CONFIG" "MODULE" "")
if(NOT GDAL_FIND_PACKAGE_PROJ_MODE STREQUAL "CUSTOM")
find_package(PROJ ${GDAL_FIND_PACKAGE_PROJ_MODE} REQUIRED)
if (NOT BUILD_SHARED_LIBS)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ ${GDAL_FIND_PACKAGE_PROJ_MODE})\n")
endif()
else()
# First check with CMake config files, and then fallback to the FindPROJ module.
find_package(PROJ CONFIG)
if (PROJ_FOUND AND PROJ_VERSION VERSION_LESS "8")
message(WARNING "PROJ ${PROJ_VERSION} < 8 found with Config file. As it is not trusted, retrying with module mode")
endif()
if (PROJ_FOUND)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ ${PROJ_VERSION_MAJOR} CONFIG)\n")
if (NOT BUILD_SHARED_LIBS)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ CONFIG)\n")
endif()
else()
find_package(PROJ 6.3 REQUIRED)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ 6.3)\n")
find_package(PROJ REQUIRED)
if (NOT BUILD_SHARED_LIBS)
string(APPEND GDAL_IMPORT_DEPENDENCIES "find_dependency(PROJ)\n")
endif()
endif ()
endif()

if (DEFINED PROJ_VERSION_STRING AND NOT DEFINED PROJ_VERSION)
set(PROJ_VERSION ${PROJ_VERSION_STRING})
endif()
if ("${PROJ_VERSION}" VERSION_LESS "6.3")
message(FATAL_ERROR "PROJ >= 6.3 required. Version ${PROJ_VERSION} found")
endif()

gdal_check_package(TIFF "Support for the Tag Image File Format (TIFF)." VERSION 4.1 CAN_DISABLE)
set_package_properties(
Expand Down
13 changes: 12 additions & 1 deletion doc/source/development/building_from_source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ the :ref:`vector.pg` and :ref:`raster.postgisraster` drivers.
PROJ
****

`PROJ <https://github.com/OSGeo/PROJ/>`_ >= 6 is a *required* dependency for GDAL.
`PROJ <https://github.com/OSGeo/PROJ/>`_ >= 6.3 is a *required* dependency for GDAL.

.. option:: PROJ_INCLUDE_DIR

Expand All @@ -1694,6 +1694,17 @@ PROJ
``PROJ_LIBRARY_DEBUG`` can also be specified to a similar library for
building Debug releases.

.. option:: GDAL_FIND_PACKAGE_PROJ_MODE=CUSTOM/MODULE/CONFIG/empty string

.. versionadded:: 3.9

Control the mode used for find_package(PROJ).
Alters how the default CMake seach logic
(https://cmake.org/cmake/help/latest/command/find_package.html) applies.
Defaults to CUSTOM, where the CONFIG mode is applied for PROJ >= 8, and
fallbacks to default MODULE mode otherwise.
Other values are passed directly to find_package()

QHULL
*****

Expand Down

0 comments on commit d8b4bea

Please sign in to comment.