From eac5d67e6cb449dec8402ece33f20328b4ffe1c1 Mon Sep 17 00:00:00 2001 From: Peter Petrik Date: Tue, 24 Nov 2020 00:18:51 +0100 Subject: [PATCH] allow use poly2tri from system --- CMakeLists.txt | 9 ++++++++- cmake/FindPoly2Tri.cmake | 24 ++++++++++++++++++++++++ src/core/CMakeLists.txt | 22 ++++++++++++++++------ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 cmake/FindPoly2Tri.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 53d111b069e..3ecce8d6560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,11 +217,14 @@ if(WITH_CORE) endif() # try to configure and build MDAL support - set (WITH_INTERNAL_MDAL TRUE CACHE BOOL "Determines whether MDAL support should be built") + set (WITH_INTERNAL_MDAL TRUE CACHE BOOL "Determines whether MDAL should be built from internal copy") if (NOT WITH_INTERNAL_MDAL) set (MDAL_PREFIX "" CACHE PATH "Path to MDAL base directory") endif() + # try to configure and build POLY2TRI support + set (WITH_INTERNAL_POLY2TRI TRUE CACHE BOOL "Determines whether POLY2TRI should be built from internal copy") + # try to configure and build POSTGRESQL support set (WITH_POSTGRESQL TRUE CACHE BOOL "Determines whether POSTGRESQL support should be built") if (WITH_POSTGRESQL) @@ -369,6 +372,10 @@ if(WITH_CORE) find_package(MDAL REQUIRED) # MDAL provider endif() + if (NOT WITH_INTERNAL_POLY2TRI) + find_package(Poly2Tri REQUIRED) + endif() + find_package(SpatiaLite REQUIRED) if (NOT PROJ_FOUND OR NOT GEOS_FOUND OR NOT GDAL_FOUND) diff --git a/cmake/FindPoly2Tri.cmake b/cmake/FindPoly2Tri.cmake new file mode 100644 index 00000000000..87fb34f3475 --- /dev/null +++ b/cmake/FindPoly2Tri.cmake @@ -0,0 +1,24 @@ +# Find Poly2Tri +# ~~~~~~~~~ +# Copyright (c) 2020, Peter Petrik +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# +# Once run this will define: +# Poly2Tri_FOUND - System has Poly2Tri +# Poly2Tri_INCLUDE_DIR - The Poly2Tri include directory +# Poly2Tri_LIBRARY - The library needed to use Poly2Tri + +find_path(Poly2Tri_INCLUDE_DIR poly2tri.h + HINTS $ENV{LIB_DIR}/include) + +find_library(Poly2Tri_LIBRARY NAMES poly2tri libpoly2tri + HINTS $ENV{LIB_DIR}/lib) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Poly2Tri DEFAULT_MSG + Poly2Tri_LIBRARY Poly2Tri_INCLUDE_DIR) + +mark_as_advanced( Poly2Tri_INCLUDE_DIR Poly2Tri_LIBRARY ) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 87b3e61d019..f2a35195e87 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -11,11 +11,6 @@ set(QGIS_CORE_SRCS ${CMAKE_SOURCE_DIR}/external/nmea/time.c ${CMAKE_SOURCE_DIR}/external/nmea/tok.c - ${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc - ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc - ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc - ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc - ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc ${CMAKE_SOURCE_DIR}/external/meshOptimizer/simplifier.cpp callouts/qgscallout.cpp @@ -734,6 +729,19 @@ set(QGIS_CORE_SRCS qgsuserprofilemanager.cpp ) +if (WITH_INTERNAL_POLY2TRI) + set(QGIS_CORE_SRCS ${QGIS_CORE_SRCS} + ${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc + ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc + ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc + ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc + ${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc + ) + include_directories(${CMAKE_SOURCE_DIR}/external/poly2tri) +else () + include_directories(${Poly2Tri_INCLUDE_DIR}) +endif () + file(GLOB JSON_HELP_FILES "${CMAKE_SOURCE_DIR}/resources/function_help/json/*") if(CMAKE_VERSION VERSION_LESS "3.18" AND NOT USING_NINJA) string(REPLACE "$" "$$" JSON_HELP_FILES "${JSON_HELP_FILES}") @@ -1624,7 +1632,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/external/nlohmann ${CMAKE_SOURCE_DIR}/external/kdbush/include ${CMAKE_SOURCE_DIR}/external/nmea - ${CMAKE_SOURCE_DIR}/external/poly2tri ${CMAKE_SOURCE_DIR}/external/rtree/include ${CMAKE_SOURCE_DIR}/external/meshOptimizer ) @@ -1730,6 +1737,9 @@ if(ENABLE_MODELTEST) target_link_libraries(qgis_core ${Qt5Test_LIBRARIES}) endif() +if (NOT WITH_INTERNAL_POLY2TRI) + target_link_libraries(qgis_core ${Poly2Tri_LIBRARY}) +endif() if(HAVE_OPENCL) target_link_libraries(qgis_core ${OpenCL_LIBRARY})