Skip to content

Commit

Permalink
lib_proj.cmake: add a PROJ::proj alias and add BUILD_INTERFACE includ…
Browse files Browse the repository at this point in the history
…e directories, so that proj can be used as a subdirectory of a larger project (fixes #2905)
  • Loading branch information
rouault committed Oct 25, 2021
1 parent 9817fe7 commit a49e3b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ add_library(proj
${ALL_LIBPROJ_HEADERS}
${PROJ_RESOURCES}
)
add_library(PROJ::proj ALIAS proj)

target_compile_options(proj
PRIVATE $<$<COMPILE_LANGUAGE:C>:${PROJ_C_WARN_FLAGS}>
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${PROJ_CXX_WARN_FLAGS}>
Expand Down Expand Up @@ -402,6 +404,8 @@ if(ENABLE_IPO)
endif()

target_include_directories(proj INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJ_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDEDIR}>)

if(WIN32)
Expand Down
17 changes: 16 additions & 1 deletion travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ fi
if [ "$BUILD_NAME" != "linux_gcc8" -a "$BUILD_NAME" != "linux_gcc_32bit" ]; then

# cmake build from generated tarball
mkdir proj_as_subproject
cd proj_as_subproject
mkdir external
ln -s $PWD/.. external/PROJ

echo '#include "proj.h"' > mytest.c
echo 'int main() { proj_info(); return 0; }' >> mytest.c

echo 'cmake_minimum_required(VERSION 3.9)' > CMakeLists.txt
echo 'project(mytest)' >> CMakeLists.txt
echo 'add_subdirectory(external/PROJ)' >> CMakeLists.txt
echo 'add_executable(mytest mytest.c)' >> CMakeLists.txt
echo 'target_include_directories(mytest PRIVATE $<TARGET_PROPERTY:PROJ::proj,INTERFACE_INCLUDE_DIRECTORIES>)' >> CMakeLists.txt
echo 'target_link_libraries(mytest PRIVATE PROJ::proj)' >> CMakeLists.txt

mkdir build_cmake
cd build_cmake
cmake --version
Expand All @@ -130,7 +145,7 @@ if [ "$BUILD_NAME" != "linux_gcc8" -a "$BUILD_NAME" != "linux_gcc_32bit" ]; then
else
echo "Skipping test_cmake.sh test for $BUILD_NAME"
fi
cd ..
cd ../..

if [ $TRAVIS_OS_NAME != "osx" ]; then
# Check that we can retrieve the resource directory in a relative way after renaming the installation prefix
Expand Down

0 comments on commit a49e3b1

Please sign in to comment.