I encountered [this issue](https://github.com/OSGeo/gdal/issues/5646) where PROJ and GDAL cannot be put in the same CMake project.
I am currently migrating an algorithm from CPU to GPU (CUDA) and want to use GDAL (with its dependency on PROJ) to load raster data in pinned memory directly, which I then transfer to CUDA context and process it respectively.
My project currently has the following top level dependencies:
SQLite3 (due to PROJ)
PROJ (due to GDAL)
GDAL
Argparse
CUDA
The CMake block that handles the first 3 (for Argparse I use the single-header version and CUDA is obviously there) looks like this:
if(BUILD_DEPS)
# SQLite3
include(ExternalProject)
ExternalProject_Add(sqlite3
SOURCE_DIR "${DEPS_DIR}/sqlite"
CONFIGURE_COMMAND ${DEPS_DIR}/sqlite/configure --all --prefix=${CMAKE_BINARY_DIR} CFLAGS="-Os" CXXFLAGS="-Os" SQLITE_THREADSAFE=2 SQLITE_OMIT_COMPLETE=1 SQLITE_OMIT_CHECK=1 SQLITE_OMIT_DEPRECATED=1 --disable-debug
BUILD_COMMAND ${MAKE})
# PROJ
# Source: https://proj.org/en/stable/install.html#cmake-configure-options
set(PROJ_BINARY_DIR "${CMAKE_BINARY_DIR}")
set(EXE_SQLITE3 "${CMAKE_BINARY_DIR}/bin/sqlite3")
#set(SQLITE3_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/")
set(SQLite3_LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/")
#set(nlohmann_json_DIR "${DEPS_DIR}/json/single_include/")
set(BUILD_APPS 0)
#set(BUILD_SHARED_LIBS 0)
set(BUILD_TESTING 0)
add_subdirectory("${DEPS_DIR}/proj")
# GDAL
set(SQLite3_HAS_MUTEX_ALLOC 1)
#set(ACCEPT_MISSING_SQLITE3_MUTEX_ALLOC 1)
set(BUILD_SHARED_LIBS 0)
set(BUILD_TESTING 0)
set(BUILD_APPS 0)
set(GDAL_BUILD_OPTIONAL_DRIVERS 0)
set(OGR_BUILD_OPTIONAL_DRIVERS 0)
set(GDAL_USE_TIFF_INTERNAL 1)
set(GDAL_USE_TIFF 0)
set(GDAL_USE_GEOTIFF_INTERNAL 1)
set(GDAL_USE_GEOTIFF 0)
add_subdirectory("${DEPS_DIR}/gdal")
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_BINARY_DIR}/bin/lib/cmake/gdal)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_BINARY_DIR}/bin/lib/cmake/gdal)
find_package(GDAL CONFIG)
if(NOT GDAL_FOUND)
find_package(GDAL REQUIRED)
endif()
During the configuration stage CMake gives me
CMake Error in deps/gdal/CMakeLists.txt:
export called with target "GDAL" which requires target "proj" that is not
in any export set.
Adding an install(EXPORT ...) call
install(TARGETS proj
EXPORT EXPORTED_PROJECT_TARGETS
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include)
install(EXPORT EXPORTED_PROJECT_TARGETS DESTINATION "${CMAKE_BINARY_DIR}/install/")
leads to the same error plus extra multiple entries in the log such as this one:
CMake Error: install(EXPORT "gdal-export" ...) includes target "GDAL" which requires target "proj" that is not in this export set, but in multiple other export sets: /home/user/Projects/Alg_CUDA/build/release/install/EXPORTED_PROJECT_TARGETS.cmake, lib/cmake/proj/proj-targets.cmake.
An exported target cannot depend upon another target which is exported multiple times. Consider consolidating the exports of the "proj" target to a single export.
I also tried adding both PROJ and GDAL to the exported targets but the result is the same.
I have been thinking of adding these dependencies as external projects, which should solve the issue. Currently I include all externals dependencies as Git submodules.