Skip to content

Commit

Permalink
Merge pull request #54940 from nilason/fix_findpdal_2.6
Browse files Browse the repository at this point in the history
Fix CMake FindPDAL for PDAL version 2.6+
  • Loading branch information
lbartoletti authored Oct 18, 2023
2 parents 066cfa3 + 30462f1 commit 37ccd4a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
46 changes: 41 additions & 5 deletions cmake/FindPDAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# CMake module to search for PDAL library
#
# If it's found it sets PDAL_FOUND to TRUE
# and following variables are set:
# PDAL_INCLUDE_DIR
# and adds the following variable containing library target(s):
# PDAL_LIBRARIES

# FIND_PATH and FIND_LIBRARY normally search standard locations
Expand All @@ -18,6 +17,28 @@
# locations. When an earlier FIND_* succeeds, subsequent FIND_*s
# searching for the same item do nothing.

find_package(PDAL CONFIG)

if(PDAL_FOUND)
if(NOT PDAL_FIND_QUIETLY)
message(STATUS "Found PDAL: ${PDAL_LIBRARIES} (${PDAL_VERSION})")
endif()

if(PDAL_VERSION VERSION_LESS "1.7.0")
message(FATAL_ERROR "PDAL version is too old (${PDAL_VERSION}). Use 1.7 or higher.")
endif()

if(MSVC)
foreach(PDAL_TARG ${PDAL_LIBRARIES})
target_compile_definitions(${PDAL_TARG} INTERFACE WIN32_LEAN_AND_MEAN)
endforeach()
endif()

return()
endif()

# Fallback for systems where PDAL's config-file package is not present.
# It is not adapted for PDAL 2.6+ (where pdal_util library is removed).
FIND_PATH(PDAL_INCLUDE_DIR pdal/pdal.hpp
"$ENV{LIB_DIR}/include"
"/usr/include"
Expand Down Expand Up @@ -50,7 +71,7 @@ FIND_PROGRAM(PDAL_BIN pdal)

IF (PDAL_INCLUDE_DIR AND PDAL_CPP_LIBRARY AND PDAL_UTIL_LIBRARY AND PDAL_BIN)
SET(PDAL_FOUND TRUE)
SET(PDAL_LIBRARIES ${PDAL_CPP_LIBRARY} ${PDAL_UTIL_LIBRARY})
SET(PDAL_LIBRARIES pdalcpp pdal_util)
ENDIF (PDAL_INCLUDE_DIR AND PDAL_CPP_LIBRARY AND PDAL_UTIL_LIBRARY AND PDAL_BIN)

IF (PDAL_FOUND)
Expand All @@ -60,8 +81,8 @@ IF (PDAL_FOUND)
OUTPUT_VARIABLE PDAL_VERSION_OUT )
STRING(REGEX REPLACE "^.*([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\1" PDAL_VERSION_MAJOR "${PDAL_VERSION_OUT}")
STRING(REGEX REPLACE "^.*([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\2" PDAL_VERSION_MINOR "${PDAL_VERSION_OUT}")
STRING(REGEX REPLACE "^.*([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3" PDAL_VERSION_MICRO "${PDAL_VERSION_OUT}")
STRING(CONCAT PDAL_VERSION ${PDAL_VERSION_MAJOR} "." ${PDAL_VERSION_MINOR} "." ${PDAL_VERSION_MICRO})
STRING(REGEX REPLACE "^.*([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3" PDAL_VERSION_PATCH "${PDAL_VERSION_OUT}")
STRING(CONCAT PDAL_VERSION ${PDAL_VERSION_MAJOR} "." ${PDAL_VERSION_MINOR} "." ${PDAL_VERSION_PATCH})

IF (NOT PDAL_FIND_QUIETLY)
MESSAGE(STATUS "Found PDAL: ${PDAL_LIBRARIES} (${PDAL_VERSION})")
Expand All @@ -71,6 +92,21 @@ IF (PDAL_FOUND)
MESSAGE (FATAL_ERROR "PDAL version is too old (${PDAL_VERSION}). Use 1.7 or higher.")
ENDIF()

add_library(pdalcpp UNKNOWN IMPORTED)
target_link_libraries(pdalcpp INTERFACE ${PDAL_CPP_LIBRARY})
target_include_directories(pdalcpp INTERFACE ${PDAL_INCLUDE_DIR})
set_target_properties(pdalcpp PROPERTIES IMPORTED_LOCATION ${PDAL_CPP_LIBRARY})

add_library(pdal_util UNKNOWN IMPORTED)
target_link_libraries(pdal_util INTERFACE ${PDAL_UTIL_LIBRARY})
target_include_directories(pdal_util INTERFACE ${PDAL_INCLUDE_DIR})
set_target_properties(pdal_util PROPERTIES IMPORTED_LOCATION ${PDAL_UTIL_LIBRARY})

if(MSVC)
target_compile_definitions(pdalcpp INTERFACE WIN32_LEAN_AND_MEAN)
target_compile_definitions(pdal_util INTERFACE WIN32_LEAN_AND_MEAN)
endif()

ELSE (PDAL_FOUND)
IF (PDAL_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find PDAL")
Expand Down
2 changes: 1 addition & 1 deletion cmake_templates/qgsconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#define PDAL_VERSION_MINOR_INT ${PDAL_VERSION_MINOR}
#define PDAL_VERSION_MAJOR "${PDAL_VERSION_MAJOR}"
#define PDAL_VERSION_MINOR "${PDAL_VERSION_MINOR}"
#define PDAL_VERSION_MICRO "${PDAL_VERSION_MICRO}"
#define PDAL_VERSION_MICRO "${PDAL_VERSION_PATCH}"

#cmakedefine HAVE_DRACO

Expand Down
4 changes: 0 additions & 4 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ if (WITH_GUI)
)
endif()

if (WITH_PDAL)
include_directories(SYSTEM "${PDAL_INCLUDE_DIR}")
endif()

if(NOT ENABLE_TESTS)
set(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} TESTS)
endif()
Expand Down
7 changes: 0 additions & 7 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,6 @@ if(HAVE_OPENCL)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
endif()

if (WITH_PDAL)
include_directories(SYSTEM ${PDAL_INCLUDE_DIR})
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
endif()
endif()

if(ENABLE_MODELTEST)
include_directories(../../tests/qt_modeltest)
endif()
Expand Down
9 changes: 0 additions & 9 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2093,15 +2093,6 @@ if (${QT_VERSION_BASE}Positioning_FOUND)
)
endif()

if (WITH_PDAL)
include_directories(SYSTEM
${PDAL_INCLUDE_DIR}
)
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
endif()
endif()

if (HAVE_OPENCL)
set(QGIS_CORE_SRCS ${QGIS_CORE_SRCS}
qgsopenclutils.cpp
Expand Down
7 changes: 0 additions & 7 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1599,13 +1599,6 @@ if (BUILD_WITH_QT6)
)
endif()

if (WITH_PDAL)
include_directories(SYSTEM ${PDAL_INCLUDE_DIR})
if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
endif()
endif()

target_include_directories(qgis_gui PUBLIC
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/actions
Expand Down
6 changes: 0 additions & 6 deletions src/providers/pdal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Files

if(MSVC)
add_definitions(-DWIN32_LEAN_AND_MEAN)
set(PDAL_LIBRARIES ${PDAL_LIBRARIES} ws2_32)
endif(MSVC)

Expand Down Expand Up @@ -149,10 +148,6 @@ include_directories(
${CMAKE_SOURCE_DIR}/external/untwine/api
)

include_directories(SYSTEM
${PDAL_INCLUDE_DIR}
)

add_executable(untwine ${UNTWINE_SRCS} ${UNTWINE_HDRS})
target_compile_features(untwine PRIVATE cxx_std_17)

Expand Down Expand Up @@ -182,7 +177,6 @@ if (PDAL_2_5_OR_HIGHER)
)

target_include_directories(pdal_wrench PRIVATE
${PDAL_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/external
)

Expand Down
4 changes: 0 additions & 4 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ if(HAVE_OPENCL)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
endif()

if (WITH_PDAL)
include_directories(SYSTEM "${PDAL_INCLUDE_DIR}")
endif()

#############################################################
# Tests:

Expand Down

0 comments on commit 37ccd4a

Please sign in to comment.