diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 893b72f343e..482a7147621 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -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: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ce2f3b6381..720e7b99c63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/find-modules/FindShapelib.cmake b/cmake/find-modules/FindShapelib.cmake new file mode 100644 index 00000000000..cb1341cab54 --- /dev/null +++ b/cmake/find-modules/FindShapelib.cmake @@ -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 +# + +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() diff --git a/src/Utilities/CMakeLists.txt b/src/Utilities/CMakeLists.txt index e339cef387d..9fe91ebcfca 100644 --- a/src/Utilities/CMakeLists.txt +++ b/src/Utilities/CMakeLists.txt @@ -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 @@ -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() diff --git a/tools/setup/install-dependencies-debian.sh b/tools/setup/install-dependencies-debian.sh index c7c110a4a34..2d6ddb00f6a 100755 --- a/tools/setup/install-dependencies-debian.sh +++ b/tools/setup/install-dependencies-debian.sh @@ -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 \