Skip to content

Commit

Permalink
allow use poly2tri from system
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Nov 23, 2020
1 parent 3240f78 commit eac5d67
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions cmake/FindPoly2Tri.cmake
@@ -0,0 +1,24 @@
# Find Poly2Tri
# ~~~~~~~~~
# Copyright (c) 2020, Peter Petrik <zilolv at gmail dot com>
# 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 )
22 changes: 16 additions & 6 deletions src/core/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit eac5d67

Please sign in to comment.