Skip to content

Commit

Permalink
CMake: Allow to find Shapelib
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Oct 7, 2024
1 parent 880819b commit 98cb3d4
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Install Dependencies
run: |
brew update
brew install cmake ninja ccache geographiclib SDL2 exiv2
brew install cmake ninja ccache geographiclib SDL2 exiv2 shapelib
- name: Install Gstreamer
run: |
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ endif()
cmake_dependent_option(QGC_BUILD_TESTING "Enable testing" ON "CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
if(QGC_BUILD_TESTING)
add_compile_definitions(UNITTEST_BUILD) # TODO: QGC_UNITTEST_BUILD
else()
set(BUILD_TESTING OFF CACHE INTERNAL "")
endif()

# option(QGC_DISABLE_MAVLINK_INSPECTOR "Disable Mavlink Inspector" OFF) # This removes QtCharts which is GPL licensed
Expand Down
69 changes: 69 additions & 0 deletions cmake/find-modules/FindShapelib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file COPYING-CMAKE-SCRIPTS or https://cmake.org/licensing for details.

#.rst:
# FindShapelib
# -----------
#
# Copyright (c) 2018, Hiroshi Miura <miurahr@linux.com>
#

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_Shapelib QUIET shapelib)
endif()

find_path(Shapelib_INCLUDE_DIR
NAMES shapefil.h
HINTS ${PC_Shapelib_INCLUDE_DIRS})

if(Shapelib_INCLUDE_DIR)
if(PC_Shapelib_VERSION)
set(Shapelib_VERSION ${PC_Shapelib_VERSION})
else()
file(READ ${Shapelib_INCLUDE_DIR}/shapefil.h _shapefil_h_contents)
string(REGEX MATCH "Id: shapefil.h,v ([0-9.]+)" Shapelib_H_VERSION "${_shapefil_h_contents}")
string(REGEX MATCH "([0-9].[0-9][0-9])" Shapelib_H_VERSION "${Shapelib_H_VERSION}")
# shapefil.h 1.26 = release 1.2.10
# shapefil.h 1.52 = release 1.3.0
# shapefil.h 1.55 = release 1.4.0, 1.4.1
if(Shapelib_H_VERSION VERSION_LESS 1.26)
message(WARNING "Shapelib version detection failed")
elseif(Shapelib_H_VERSION VERSION_LESS 1.52)
set(Shapelib_VERSION 1.2.10)
elseif(Shapelib_H_VERSION VERSION_LESS 1.55)
set(Shapelib_VERSION 1.3.0)
else()
set(Shapelib_VERSION 1.4.0)
endif()
endif()
endif()

if(MSVC)
set(Shapelib_LIBNAME shapelib)
else()
set(Shapelib_LIBNAME shp)
endif()

find_library(Shapelib_LIBRARY NAMES ${Shapelib_LIBNAME})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Shapelib
FOUND_VAR Shapelib_FOUND
REQUIRED_VARS Shapelib_INCLUDE_DIR Shapelib_LIBRARY
VERSION_VAR Shapelib_VERSION
)

mark_as_advanced(Shapelib_INCLUDE_DIR Shapelib_LIBRARY)

if(Shapelib_FOUND)
set(Shapelib_INCLUDE_DIRS "${Shapelib_INCLUDE_DIR}")
set(Shapelib_LIBRARIES "${Shapelib_LIBRARY}")
if(NOT TARGET SHAPELIB::shp)
add_library(SHAPELIB::shp UNKNOWN IMPORTED)
set_target_properties(SHAPELIB::shp PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Shapelib_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES C
IMPORTED_LOCATION "${Shapelib_LIBRARY}")
endif()
endif()
59 changes: 33 additions & 26 deletions src/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,19 @@ qt_add_library(Utilities STATIC
)

if(MOBILE)
target_sources(Utilities
PRIVATE
MobileScreenMgr.cc
MobileScreenMgr.h
)
target_sources(Utilities PRIVATE MobileScreenMgr.h)
if(ANDROID)
target_sources(Utilities PRIVATE MobileScreenMgr.cc)
elseif(IOS)
target_sources(Utilities PRIVATE MobileScreenMgr.mm)
endif()
endif()

set(BUILD_SHAPELIB_CONTRIB OFF CACHE INTERNAL "")
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
set(BUILD_TESTING OFF CACHE INTERNAL "")
set(BUILD_APPS OFF CACHE INTERNAL "")

include(FetchContent)
FetchContent_Declare(shapelib
GIT_REPOSITORY https://github.com/OSGeo/shapelib.git
GIT_TAG 6fe5012d0d893964943befc2034a055d5aa588a8
)
FetchContent_GetProperties(shapelib)
if(NOT shapelib_POPULATED)
FetchContent_Populate(shapelib)
add_subdirectory(${shapelib_SOURCE_DIR} ${shapelib_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
target_include_directories(Utilities PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(Utilities
PRIVATE
Qt6::Qml
shp
FactSystem
Geo
QGC
Expand All @@ -72,11 +58,32 @@ target_link_libraries(Utilities
)

if(QGC_ENABLE_BLUETOOTH)
target_link_libraries(Utilities
PRIVATE
Qt6::Bluetooth
)
target_link_libraries(Utilities PRIVATE Qt6::Bluetooth)
endif()

set(MINIMUM_SHAPELIB_VERSION 1.6.0)

target_include_directories(Utilities PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(NOT QGC_BUILD_DEPENDENCIES)
find_package(Shapelib ${MINIMUM_SHAPELIB_VERSION})
if(Shapelib_FOUND)
message(STATUS "Found Shapelib ${Shapelib_VERSION}")
target_link_libraries(Utilities PRIVATE SHAPELIB::shp)
endif()
endif()

if(NOT Shapelib_FOUND)
message(STATUS "Building Shapelib")
include(FetchContent)
FetchContent_Declare(shapelib
GIT_REPOSITORY https://github.com/OSGeo/shapelib.git
GIT_TAG master
GIT_SHALLOW TRUE
)
set(BUILD_SHAPELIB_CONTRIB OFF CACHE INTERNAL "")
set(BUILD_APPS OFF CACHE INTERNAL "")
set(saved_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF CACHE INTERNAL "Disable testing for Shapelib")
FetchContent_MakeAvailable(shapelib)
set(BUILD_TESTING ${saved_BUILD_TESTING} CACHE INTERNAL "Restore BUILD_TESTING")
target_link_libraries(Utilities PRIVATE shp)
endif()
1 change: 1 addition & 0 deletions tools/setup/install-dependencies-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ DEBIAN_FRONTEND=noninteractive apt -y --quiet install \
libpulse-dev \
libsdl2-dev \
libspeechd-dev \
libshp-dev \
libunwind-dev \
libva-dev \
libvdpau-dev \
Expand Down

0 comments on commit 98cb3d4

Please sign in to comment.