Skip to content

Commit

Permalink
CMake: Add CPM
Browse files Browse the repository at this point in the history
  • Loading branch information
HTRamsey committed Jan 16, 2025
1 parent dcb2838 commit b15ec26
Show file tree
Hide file tree
Showing 8 changed files with 1,371 additions and 66 deletions.
1,285 changes: 1,285 additions & 0 deletions cmake/modules/CPM.cmake

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions cmake/modules/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.5)
set(CPM_HASH_SUM "c46b876ae3b9f994b4f05a4c15553e0485636862064f1fcc9d8b4f832086bc5d")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
7 changes: 5 additions & 2 deletions src/AnalyzeView/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ target_precompile_headers(AnalyzeView
#===========================================================================#

message(STATUS "Building ULogParser")
FetchContent_Declare(ulogparser

include(CPM)
CPMAddPackage(
NAME ulog_cpp
GIT_REPOSITORY https://github.com/PX4/ulog_cpp.git
GIT_TAG main
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ulogparser)

if(TARGET ulog_cpp::ulog_cpp)
target_link_libraries(AnalyzeView PRIVATE ulog_cpp::ulog_cpp)
endif()
Expand Down
6 changes: 3 additions & 3 deletions src/FirmwarePlugin/APM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ target_link_libraries(APMFirmwarePlugin

target_include_directories(APMFirmwarePlugin PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

message(STATUS "Fetching ArduPilot Parameters")
FetchContent_Declare(ArduPilotParams
include(CPM)
CPMAddPackage(
NAME ArduPilotParams
GIT_REPOSITORY https://github.com/ArduPilot/ParameterRepository.git
GIT_TAG main
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(ArduPilotParams)

# file(GLOB QML_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.qml)
# # file(GLOB QML_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/res/*/*.*)
Expand Down
69 changes: 27 additions & 42 deletions src/GPS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,6 @@ if(QGC_NO_SERIAL_LINK)
return()
endif()

message(STATUS "Building GPS Drivers")
FetchContent_Declare(PX4-GPSDrivers
GIT_REPOSITORY https://github.com/PX4/PX4-GPSDrivers.git
GIT_TAG main
GIT_SHALLOW TRUE
SOURCE_SUBDIR src
)
FetchContent_MakeAvailable(PX4-GPSDrivers)

qt_add_library(GPSDrivers STATIC
definitions.h
${px4-gpsdrivers_SOURCE_DIR}/src/ashtech.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/ashtech.h
${px4-gpsdrivers_SOURCE_DIR}/src/base_station.h
${px4-gpsdrivers_SOURCE_DIR}/src/crc.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/crc.h
${px4-gpsdrivers_SOURCE_DIR}/src/emlid_reach.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/emlid_reach.h
${px4-gpsdrivers_SOURCE_DIR}/src/femtomes.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/femtomes.h
${px4-gpsdrivers_SOURCE_DIR}/src/gps_helper.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/gps_helper.h
${px4-gpsdrivers_SOURCE_DIR}/src/mtk.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/mtk.h
${px4-gpsdrivers_SOURCE_DIR}/src/nmea.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/nmea.h
${px4-gpsdrivers_SOURCE_DIR}/src/rtcm.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/rtcm.h
${px4-gpsdrivers_SOURCE_DIR}/src/sbf.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/sbf.h
${px4-gpsdrivers_SOURCE_DIR}/src/ubx.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/ubx.h
${px4-gpsdrivers_SOURCE_DIR}/src/unicore.cpp
${px4-gpsdrivers_SOURCE_DIR}/src/unicore.h
)

target_link_libraries(GPSDrivers PUBLIC Qt6::Core)

target_compile_definitions(GPSDrivers PUBLIC GPS_DEFINITIONS_HEADER=<${CMAKE_CURRENT_SOURCE_DIR}/definitions.h>)

target_include_directories(GPSDrivers PUBLIC ${px4-gpsdrivers_SOURCE_DIR}/src)

target_sources(GPS
PRIVATE
GPSManager.cc
Expand Down Expand Up @@ -79,3 +37,30 @@ target_link_libraries(GPS
)

target_include_directories(GPS PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

#===========================================================================#

message(STATUS "Building GPS Drivers")

include(CPM)
CPMAddPackage(
NAME px4-gpsdrivers
GIT_REPOSITORY https://github.com/PX4/PX4-GPSDrivers.git
GIT_TAG main
GIT_SHALLOW TRUE
SOURCE_SUBDIR src
)

file(GLOB GPS_DRIVERS_SOURCES "${px4-gpsdrivers_SOURCE_DIR}/src/*")
qt_add_library(GPSDrivers STATIC
definitions.h
${GPS_DRIVERS_SOURCES}
)

target_link_libraries(GPSDrivers PUBLIC Qt6::Core)

target_compile_definitions(GPSDrivers PUBLIC GPS_DEFINITIONS_HEADER=<${CMAKE_CURRENT_SOURCE_DIR}/definitions.h>)

target_include_directories(GPSDrivers PUBLIC ${px4-gpsdrivers_SOURCE_DIR}/src)

target_link_libraries(GPS PUBLIC GPSDrivers)
10 changes: 4 additions & 6 deletions src/Joystick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ target_compile_definitions(Joystick PRIVATE QGC_SDL_JOYSTICK SDL_MAIN_HANDLED)

#===========================================================================#

FetchContent_Declare(SDL_GameControllerDB
include(CPM)
CPMAddPackage(
NAME sdl_gamecontrollerdb
GIT_REPOSITORY https://github.com/mdqinc/SDL_GameControllerDB.git
GIT_TAG master
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(SDL_GameControllerDB)

set_source_files_properties(${sdl_gamecontrollerdb_SOURCE_DIR}/gamecontrollerdb.txt
PROPERTIES
QT_RESOURCE_ALIAS gamecontrollerdb.txt
)
set_source_files_properties(${sdl_gamecontrollerdb_SOURCE_DIR}/gamecontrollerdb.txt PROPERTIES QT_RESOURCE_ALIAS gamecontrollerdb.txt)

qt_add_resources(Joystick "gamecontrollerdb.txt"
PREFIX "/db/mapping/joystick"
Expand Down
8 changes: 5 additions & 3 deletions src/MAVLink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ target_include_directories(MAVLink PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

############# MAVLink

message(STATUS "Building MAVLink")

# TODO:
# FetchContent_Declare(mavlink
# GIT_REPOSITORY https://github.com/mavlink/mavlink.git
Expand All @@ -43,12 +45,12 @@ target_include_directories(MAVLink PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# set(MAVLINK_VERSION 2.0)
# FetchContent_MakeAvailable(mavlink)

message(STATUS "Building MAVLink")
FetchContent_Declare(mavlink
include(CPM)
CPMAddPackage(
NAME mavlink
GIT_REPOSITORY ${QGC_MAVLINK_GIT_REPO}
GIT_TAG ${QGC_MAVLINK_GIT_TAG}
)
FetchContent_MakeAvailable(mavlink)

target_include_directories(MAVLink
PUBLIC
Expand Down
28 changes: 18 additions & 10 deletions src/MAVLink/LibEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
find_package(Qt6 REQUIRED COMPONENTS Core)

message(STATUS "Building libevents")
FetchContent_Declare(libevents
GIT_REPOSITORY https://github.com/mavlink/libevents.git
GIT_TAG main
GIT_SHALLOW TRUE
SOURCE_SUBDIR libs/cpp
)
FetchContent_MakeAvailable(libevents)

qt_add_library(LibEventsWrapper STATIC
EventHandler.cc
EventHandler.h
Expand All @@ -23,7 +14,6 @@ target_link_libraries(LibEventsWrapper
Utilities
PUBLIC
Qt6::Core
libevents
MAVLink
)

Expand All @@ -32,3 +22,21 @@ target_include_directories(LibEventsWrapper
${CMAKE_CURRENT_SOURCE_DIR}
${libevents_SOURCE_DIR}/libs/cpp
)

#===========================================================================#

message(STATUS "Building libevents")

include(CPM)
CPMAddPackage(
NAME libevents
GIT_REPOSITORY https://github.com/mavlink/libevents.git
GIT_TAG main
GIT_SHALLOW TRUE
SOURCE_SUBDIR libs/cpp
)

if(TARGET libevents)
target_link_libraries(LibEventsWrapper PUBLIC libevents)
target_include_directories(LibEventsWrapper PUBLIC ${libevents_SOURCE_DIR}/libs/cpp)
endif()

0 comments on commit b15ec26

Please sign in to comment.