Skip to content

Commit

Permalink
CMake: use TIFF:TIFF and CURL::libcurl targets (refs OSGeo#3316)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 10, 2022
1 parent 06632e1 commit dec26c1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ if(ENABLE_CURL)
find_package(CURL REQUIRED)
if(CURL_FOUND)
set(CURL_ENABLED TRUE)

# Target CURL::libcurl only defined since CMake 3.12
# TODO: remove this when CMake >= 3.12 required
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE IMPORTED)
set_target_properties(CURL::libcurl PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${CURL_LIBRARIES}"
)
endif()
else()
message(SEND_ERROR "curl dependency not found!")
endif()
Expand Down
17 changes: 16 additions & 1 deletion cmake/project-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ if(@PROJECT_VARIANT_NAME@ STREQUAL "PROJ4")
endif()

include(CMakeFindDependencyMacro)
if("@CURL_ENABLED@" STREQUAL "TRUE")

cmake_policy(PUSH)
cmake_policy(SET CMP0012 NEW)
if("@ENABLE_TIFF@")
find_dependency(TIFF)
endif()
if("@CURL_ENABLED@")
# Chainload CURL usage requirements
find_dependency(CURL)
# Target CURL::libcurl only defined since CMake 3.12
if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE IMPORTED)
set_target_properties(CURL::libcurl PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${CURL_LIBRARIES}"
)
endif()
endif()
cmake_policy(POP)

function(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
if(IS_ABSOLUTE "${rel_or_abs_path}")
Expand Down
20 changes: 16 additions & 4 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,28 @@ endif()

if(TIFF_ENABLED)
target_compile_definitions(proj PRIVATE -DTIFF_ENABLED)
target_include_directories(proj PRIVATE ${TIFF_INCLUDE_DIR})
target_link_libraries(proj PRIVATE ${TIFF_LIBRARY})
if( CMAKE_VERSION VERSION_LESS 3.11 AND CMAKE_CROSSCOMPILING )
# Hack needed for ubuntu:18.04 mingw64 cross compiling to avoid
# -isystem to be emitted (similar to https://discourse.cmake.org/t/use-of-isystem/1574)
target_include_directories(proj PRIVATE ${TIFF_INCLUDE_DIRS})
target_link_libraries(proj PRIVATE ${TIFF_LIBRARIES})
else()
target_link_libraries(proj PRIVATE TIFF::TIFF)
endif()
endif()

if(CURL_ENABLED)
target_compile_definitions(proj PRIVATE -DCURL_ENABLED)
target_include_directories(proj PRIVATE ${CURL_INCLUDE_DIRS})
if( CMAKE_VERSION VERSION_LESS 3.11 AND CMAKE_CROSSCOMPILING )
# Hack needed for ubuntu:18.04 mingw64 cross compiling to avoid
# -isystem to be emitted (similar to https://discourse.cmake.org/t/use-of-isystem/1574)
target_include_directories(proj PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(proj PRIVATE ${CURL_LIBRARIES})
else()
target_link_libraries(proj PRIVATE CURL::libcurl)
endif()
target_link_libraries(proj
PRIVATE
${CURL_LIBRARIES}
$<$<CXX_COMPILER_ID:MSVC>:ws2_32>
$<$<CXX_COMPILER_ID:MSVC>:wldap32>
$<$<CXX_COMPILER_ID:MSVC>:advapi32>
Expand Down
10 changes: 8 additions & 2 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ add_executable(test_network
main.cpp
test_network.cpp)
if(CURL_ENABLED)
include_directories(${CURL_INCLUDE_DIR})
target_compile_definitions(test_network PRIVATE -DCURL_ENABLED)
target_link_libraries(test_network PRIVATE ${CURL_LIBRARY})
if( CMAKE_VERSION VERSION_LESS 3.11 AND CMAKE_CROSSCOMPILING )
# Hack needed for ubuntu:18.04 mingw64 cross compiling to avoid
# -isystem to be emitted (similar to https://discourse.cmake.org/t/use-of-isystem/1574)
target_include_directories(test_network PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(test_network PRIVATE ${CURL_LIBRARIES})
else()
target_link_libraries(test_network PRIVATE CURL::libcurl)
endif()
endif()
target_link_libraries(test_network
PRIVATE GTest::gtest
Expand Down

0 comments on commit dec26c1

Please sign in to comment.