Skip to content

Commit

Permalink
Merge pull request #3324 from rouault/fix_gdal_5646
Browse files Browse the repository at this point in the history
CMake: add a INSTALL_LEGACY_CMAKE_FILES option (fixes OSGeo/gdal#5646)
  • Loading branch information
rouault authored Sep 23, 2022
2 parents f1766c1 + ad660a8 commit a3c8423
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ else ()
set (CMAKE_CROSSCOMPILING_STR "OFF")
endif ()

foreach (PROJECT_VARIANT_NAME ${PROJECT_NAME} ${PROJECT_LEGACY_NAME})
# If this is a regular build (PROJECT_SOURCE_DIR == CMAKE_SOURCE_DIR), export legacy files by default
# Otherwise, this is embedded in another project, only export PROJ target
# cf /~https://github.com/OSGeo/gdal/issues/5646
string(COMPARE EQUAL "${PROJECT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" DEFAULT_VAL)
option(INSTALL_LEGACY_CMAKE_FILES "Install PROJ4 legacy target CMake files" ${DEFAULT_VAL})

set(PROJECT_LIST ${PROJECT_NAME})
if (INSTALL_LEGACY_CMAKE_FILES)
set(PROJECT_LIST "${PROJECT_LIST}" "${PROJECT_LEGACY_NAME}")
endif ()
foreach (PROJECT_VARIANT_NAME IN LISTS PROJECT_LIST)
string (TOLOWER "${PROJECT_VARIANT_NAME}" PROJECT_VARIANT_LOWER)
set (CMAKECONFIGSUBDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_VARIANT_LOWER}")
# proj-config.cmake for the install tree. It's installed in
Expand All @@ -117,9 +127,11 @@ foreach (PROJECT_VARIANT_NAME ${PROJECT_NAME} ${PROJECT_LEGACY_NAME})
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGSUBDIR}")
install(EXPORT targets
NAMESPACE ${PROJECT_LEGACY_NAME}::
FILE ${PROJECT_LEGACY_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGSUBDIR}")
if (INSTALL_LEGACY_CMAKE_FILES)
install(EXPORT targets
NAMESPACE ${PROJECT_LEGACY_NAME}::
FILE ${PROJECT_LEGACY_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGSUBDIR}")
endif()
endforeach ()

0 comments on commit a3c8423

Please sign in to comment.