Skip to content

Commit

Permalink
Use cpp-tool for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
milanzlicic committed Jun 13, 2024
1 parent 9d89dc7 commit ab09e2c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cpp-tools"]
path = cpp-tools
url = git@github.com:Wolkabout/cpp-tools.git
3 changes: 1 addition & 2 deletions cmake/cxx-settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic
-Wfloat-equal -Wformat=2 \
-Werror=init-self \
-Werror=missing-field-initializers -Wmissing-format-attribute \
-Wmissing-include-dirs -Wmissing-noreturn \
-Werror=pointer-arith \
-Wmissing-noreturn -Werror=pointer-arith \
-Wno-packed -Wno-padded -Wredundant-decls \
-Werror=shadow -Werror=stack-protector \
-Wstrict-aliasing=2 -Wno-switch \
Expand Down
9 changes: 9 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ foreach (INDEX RANGE ${TARGETS_LENGTH})
COMPONENT ${DEV_COMPONENT}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(TARGETS paho-mqtt3as
EXPORT ${PROJECT_NAME}Targets
LIBRARY
COMPONENT ${REL_COMPONENT}
NAMELINK_SKIP
PUBLIC_HEADER
DESTINATION ${PUBLIC_HEADERS_DESTINATION}
INCLUDES DESTINATION ${PUBLIC_HEADERS_DESTINATION})

# Install the json target
install(TARGETS nlohmann_json
EXPORT ${PROJECT_NAME}Targets
Expand Down
3 changes: 0 additions & 3 deletions connectivity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ add_library(${NAMESPACE}::${CONNECTIVITY_TARGET_NAME} ALIAS ${CONNECTIVITY_TARGE
target_link_directories(${CONNECTIVITY_TARGET_NAME} PRIVATE ${CMAKE_PREFIX_PATH}/lib)
target_link_libraries(${CONNECTIVITY_TARGET_NAME} paho-mqttpp3 paho-mqtt3as ${UTIL_TARGET_NAME} nlohmann_json::nlohmann_json nlohmann_json_schema_validator)

# Add the dependency
add_dependencies(${CONNECTIVITY_TARGET_NAME} pahomqttcpp)

# Set some target properties
set_target_properties(${CONNECTIVITY_TARGET_NAME} PROPERTIES OUTPUT_NAME "${NAMESPACE}${CONNECTIVITY_TARGET_NAME}")
set_target_properties(${CONNECTIVITY_TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN")
Expand Down
96 changes: 4 additions & 92 deletions connectivity/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,92 +1,4 @@
# Include the CMake modules
include(ExternalProject)
include(FetchContent)

# Define the versions
set(PAHO_MQTT_C_VERSION 1.3.8)
set(PAHO_MQTT_CPP_VERSION 1.2.0)
set(NLOHMANN_JSON_VERSION_PREFIX 3.7)
set(NLOHMANN_JSON_VERSION 3.7.3)
set(JSON_SCHEMA_VERSION 2.1.0)

# Include PahoMQTT for both C and C++
ExternalProject_Add(pahomqttc
GIT_REPOSITORY "https://github.com/eclipse/paho.mqtt.c"
GIT_TAG v${PAHO_MQTT_C_VERSION}
UPDATE_COMMAND ""
CMAKE_ARGS
# Options for pahomqttc
-DPAHO_WITH_SSL=ON
-DPAHO_BUILD_SHARED=ON
-DPAHO_BUILD_STATIC=OFF
-DPAHO_BUILD_DOCUMENTATION=OFF
-DPAHO_BUILD_SAMPLES=OFF
-DPAHO_BUILD_DEB_PACKAGE=OFF
-DPAHO_ENABLE_TESTING=OFF
-DPAHO_ENABLE_CPACK=OFF

# Target path for installation
-DCMAKE_INSTALL_PREFIX=${CMAKE_PREFIX_PATH}

# In case the library needs to cross-compile
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DARP_TOOLCHAIN_ROOT=${ARP_TOOLCHAIN_ROOT}
)

ExternalProject_Add(pahomqttcpp
GIT_REPOSITORY "https://github.com/eclipse/paho.mqtt.cpp"
GIT_TAG v${PAHO_MQTT_CPP_VERSION}
UPDATE_COMMAND ""
CMAKE_ARGS
# Options for pahomqttcpp
-DPAHO_WITH_SSL=ON
-DPAHO_BUILD_SHARED=ON
-DPAHO_BUILD_STATIC=OFF
-DPAHO_BUILD_DOCUMENTATION=OFF
-DPAHO_BUILD_SAMPLES=OFF
-DPAHO_BUILD_DEB_PACKAGE=OFF
-DPAHO_BUILD_TESTS=OFF

# Target path for installation
-DPAHO_MQTT_C_INCLUDE_DIRS=${CMAKE_PREFIX_PATH}/include
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_INSTALL_PREFIX=${CMAKE_PREFIX_PATH}

# In case the library needs to cross-compile
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DARP_TOOLCHAIN_ROOT=${ARP_TOOLCHAIN_ROOT}
DEPENDS pahomqttc
)

# Set JSON flags
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." OFF)

# Include nlohmann json and the schema)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v${NLOHMANN_JSON_VERSION}
FIND_PACKAGE_ARGS ${NLOHMANN_JSON_VERSION_PREFIX} NAMES nlohmann-json3-dev
)

# Save the flags, for reset after we run the cmake for schema
set(_BUILD_TESTS ${BUILD_TESTS})
set(_BUILD_EXAMPLES ${BUILD_EXAMPLES})
set(BUILD_TESTS OFF CACHE BOOL "Build tests" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)

FetchContent_Declare(
json-schema
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator
GIT_TAG ${JSON_SCHEMA_VERSION}
)

# Make everything available
FetchContent_MakeAvailable(nlohmann_json json-schema)

# Reset the flags for schema
set(BUILD_TESTS ${_BUILD_TESTS} CACHE BOOL "Build tests" FORCE)
set(BUILD_EXAMPLES ${_BUILD_EXAMPLES} CACHE BOOL "Build examples" FORCE)

# Adjust the compile options for `nlohmann_json` to disable the shadow and pedantic
target_compile_options(nlohmann_json_schema_validator PRIVATE "-Wno-shadow;-Wno-pedantic")
include(../cpp-tools/cmake/dependencies/paho_mqtt_c.cmake)
include(../cpp-tools/cmake/dependencies/paho_mqtt_cpp.cmake)
include(../cpp-tools/cmake/dependencies/nlohmann_json.cmake)
include(../cpp-tools/cmake/dependencies/json_schema_validator.cmake)
19 changes: 1 addition & 18 deletions connectivity/tests/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
# Include the CMake modules
include(FetchContent)

# Define the gtest/gmock version
set(GTEST_VERSION 1.10.0)

# Add gtest/gmock
FetchContent_Declare(
libgtest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-${GTEST_VERSION}
)

# Make available
FetchContent_MakeAvailable(libgtest)

# Adjust the compile options for `nlohmann_json` to disable the compilation errors with our flags
target_compile_options(gtest PRIVATE "-Wno-error=maybe-uninitialized;-Wno-error=suggest-attribute=noreturn")
include(../../cpp-tools/cmake/dependencies/gtest.cmake)
1 change: 1 addition & 0 deletions cpp-tools
Submodule cpp-tools added at d04a1a
18 changes: 2 additions & 16 deletions util/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# Include the CMake modules
include(FetchContent)
include(../cpp-tools/cmake/dependencies/spdlog.cmake)
include(../cpp-tools/cmake/dependencies/openssl_crypto.cmake)

# Add the pre-installed libraries
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)

# Define the spdlog version
set(SPDLOG_VERSION 1.8.5)

# Add spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v${SPDLOG_VERSION}
)

# Make available
FetchContent_MakeAvailable(spdlog)

0 comments on commit ab09e2c

Please sign in to comment.