Skip to content

Commit

Permalink
Merge pull request #72 from Wolkabout/rework/cmake-project-structure
Browse files Browse the repository at this point in the history
Refactored everything to be structured more correctly
  • Loading branch information
Ana Vuletić authored Oct 17, 2023
2 parents 1af0b0d + cda04f2 commit 459bd98
Show file tree
Hide file tree
Showing 224 changed files with 1,120 additions and 1,118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
uses: jidicula/[email protected]
with:
clang-format-version: 10
exclude-regex: "core/utilities/nlohmann/json.hpp"
exclude-regex: "core/utility/nlohmann/json.hpp"
484 changes: 41 additions & 443 deletions CMakeLists.txt

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
/_/ /_/
========================================================================================================================

**Version 3.4.0**
- [IMPROVEMENT] - Completely reworked the CMake structure of the project.

**Version 3.3.0**
- [IMPROVEMENT] - Modernized the CMake a little bit more to appeal to more modern way of including headers.

Expand Down
32 changes: 32 additions & 0 deletions aws/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Include the util dependencies
include(cmake/dependencies.cmake)

# Create the library
add_library(${AWS_LOG_UPLOADER_TARGET_NAME})
add_library(${NAMESPACE}::${AWS_LOG_UPLOADER_TARGET_NAME} ALIAS ${AWS_LOG_UPLOADER_TARGET_NAME})

# Link the libraries
target_link_libraries(${AWS_LOG_UPLOADER_TARGET_NAME} ${UTIL_TARGET_NAME} aws-cpp-sdk-core aws-cpp-sdk-s3)

# Set some target properties
set_target_properties(${AWS_LOG_UPLOADER_TARGET_NAME} PROPERTIES OUTPUT_NAME "${NAMESPACE}${AWS_LOG_UPLOADER_TARGET_NAME}")
set_target_properties(${AWS_LOG_UPLOADER_TARGET_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(${AWS_LOG_UPLOADER_TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(${AWS_LOG_UPLOADER_TARGET_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})

# Add the sources
target_sources(${AWS_LOG_UPLOADER_TARGET_NAME} PRIVATE core/log_uploader/AwsLogUploader.cpp)

# Add the headers
target_sources(${AWS_LOG_UPLOADER_TARGET_NAME} PRIVATE core/log_uploader/AwsLogUploader.h)

# Add the private include directories
target_include_directories(${AWS_LOG_UPLOADER_TARGET_NAME}
PRIVATE
${PROJECT_SOURCE_DIR}/${AWS_LOG_UPLOADER_SUBDIRECTORY_PATH})

# Add the public include directories
target_include_directories(${AWS_LOG_UPLOADER_TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/${AWS_LOG_UPLOADER_SUBDIRECTORY_PATH}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
28 changes: 28 additions & 0 deletions aws/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Include the CMake modules
include(FetchContent)

# Define the AWS version
set(AWS_SDK_VERSION 1.8.173)

# Set the flags for AWS based on the CMake build type
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
option(ENABLE_UNITY_BUILD "If enabled, the SDK will be built using a single unified .cpp file for each service library. Reduces the size of static library binaries on Windows and Linux" OFF)
option(MINIMIZE_SIZE "If enabled, the SDK will be built via a unity aggregation process that results in smaller static libraries; additionally, release binaries will favor size optimizations over speed" OFF)
else (CMAKE_BUILD_TYPE STREQUAL "Release")
option(ENABLE_UNITY_BUILD "If enabled, the SDK will be built using a single unified .cpp file for each service library. Reduces the size of static library binaries on Windows and Linux" ON)
option(MINIMIZE_SIZE "If enabled, the SDK will be built via a unity aggregation process that results in smaller static libraries; additionally, release binaries will favor size optimizations over speed" ON)
endif ()

# Set the options
option(ENABLE_TESTING "Flag to enable/disable building unit and integration tests" OFF)
set(BUILD_ONLY s3 CACHE STRING "A semi-colon delimited list of the projects to build")

# Add AWS
FetchContent_Declare(
aws-sdk-cpp
GIT_REPOSITORY https://github.com/aws/aws-sdk-cpp
GIT_TAG ${AWS_SDK_VERSION}
)

# Make available
FetchContent_MakeAvailable(aws-sdk-cpp)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Wolkabout Technology s.r.o.
* Copyright 2023 Wolkabout Technology s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,9 +14,9 @@
* limitations under the License.
*/

#include "AwsLogUploader.h"
#include "core/log_uploader/AwsLogUploader.h"

#include "core/utilities/Logger.h"
#include "core/utility/Logger.h"

#include <algorithm>
#include <aws/core/Aws.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Wolkabout Technology s.r.o.
* Copyright 2023 Wolkabout Technology s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
#ifndef AWSLOGUPLOADER_H
#define AWSLOGUPLOADER_H

#include "core/utilities/LogUploader.h"
#include "core/utility/LogUploader.h"

#include <aws/core/utils/memory/stl/AWSString.h>

Expand Down
8 changes: 8 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@NAMESPACE@@[email protected]")

check_required_components(@NAMESPACE@@PROJECT_NAME@)

find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
22 changes: 22 additions & 0 deletions cmake/cxx-settings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Set the standard and flags
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic \
-pedantic-errors -Wcast-align \
-Wcast-qual -Wconversion \
-Wdisabled-optimization \
-Wfloat-equal -Wformat=2 \
-Werror=init-self \
-Werror=missing-field-initializers -Wmissing-format-attribute \
-Wmissing-include-dirs -Wmissing-noreturn \
-Werror=pointer-arith \
-Wno-packed -Wno-padded -Wredundant-decls \
-Werror=shadow -Werror=stack-protector \
-Wstrict-aliasing=2 -Wno-switch \
-Werror=unreachable-code -Wunused \
-Wvariadic-macros \
-Wwrite-strings -Werror=non-virtual-dtor -Werror=return-type")

# Set the tests flags
if (${BUILD_TESTS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -g")
endif ()
123 changes: 123 additions & 0 deletions cmake/install.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Import the required modules
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# Define the destination for public headers
set(PUBLIC_HEADERS_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${SOURCE_ROOT_FOLDER})
string(TOLOWER ${PUBLIC_HEADERS_DESTINATION} PUBLIC_HEADERS_DESTINATION)

# Define the component names
set(REL_COMPONENT RELEASE)
set(DEV_COMPONENT DEV)

# Define the targets lists
set(TARGETS_LIST ${UTIL_TARGET_NAME} ${AWS_LOG_UPLOADER_TARGET_NAME} ${CONNECTIVITY_TARGET_NAME})
set(TARGETS_DIRECTORIES ${UTIL_SUBDIRECTORY_PATH} ${AWS_LOG_UPLOADER_SUBDIRECTORY_PATH} ${CONNECTIVITY_SUBDIRECTORY_PATH})

# Go through the targets
list(LENGTH TARGETS_LIST TARGETS_LENGTH)
math(EXPR TARGETS_LENGTH ${TARGETS_LENGTH}-1)
foreach (INDEX RANGE ${TARGETS_LENGTH})
list(GET TARGETS_LIST ${INDEX} TARGET)
list(GET TARGETS_DIRECTORIES ${INDEX} TARGET_DIRECTORY)

if (NOT TARGET "${TARGET}")
continue()
endif ()

# Create the install rule for the main target
install(TARGETS ${TARGET}
EXPORT ${PROJECT_NAME}Targets
LIBRARY
COMPONENT ${REL_COMPONENT}
NAMELINK_SKIP
PUBLIC_HEADER
DESTINATION ${PUBLIC_HEADERS_DESTINATION}
INCLUDES DESTINATION ${PUBLIC_HEADERS_DESTINATION})

# Install all the header files
get_target_property(HEADER_FILES ${TARGET} SOURCES)
list(FILTER HEADER_FILES INCLUDE REGEX .*.h$)
list(TRANSFORM HEADER_FILES PREPEND ${TARGET_DIRECTORY}/)
string(LENGTH ${TARGET_DIRECTORY}/${SOURCE_ROOT_FOLDER}/ SOURCE_ROOT_FOLDER_LENGTH)
foreach (HEADER_FILE ${HEADER_FILES})
string(FIND ${HEADER_FILE} / SLASH_POSITION REVERSE)
math(EXPR SLASH_POSITION ${SLASH_POSITION}+1)
string(SUBSTRING ${HEADER_FILE} 0 ${SLASH_POSITION} HEADER_SUBDIRECTORY)
string(SUBSTRING ${HEADER_SUBDIRECTORY} ${SOURCE_ROOT_FOLDER_LENGTH} -1 HEADER_SUBDIRECTORY)
install(FILES ${HEADER_FILE}
COMPONENT ${DEV_COMPONENT}
DESTINATION ${PUBLIC_HEADERS_DESTINATION}/${HEADER_SUBDIRECTORY})
endforeach ()

# Add the util extra targets
if (${TARGET} STREQUAL ${UTIL_TARGET_NAME})
install(TARGETS spdlog
EXPORT ${PROJECT_NAME}Targets
LIBRARY
COMPONENT ${REL_COMPONENT}
NAMELINK_SKIP
PUBLIC_HEADER
DESTINATION ${PUBLIC_HEADERS_DESTINATION}
INCLUDES DESTINATION ${PUBLIC_HEADERS_DESTINATION})
endif ()

# Add the connectivity extra targets
if (${TARGET} STREQUAL ${CONNECTIVITY_TARGET_NAME})
# Install libpaho files
install(DIRECTORY ${CMAKE_PREFIX_PATH}/lib/
COMPONENT ${REL_COMPONENT}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING PATTERN REGEX "libpaho(.*).so")
install(DIRECTORY ${CMAKE_PREFIX_PATH}/lib/
COMPONENT ${REL_COMPONENT}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
FILES_MATCHING PATTERN REGEX "(.*)[Pp]aho(.*).cmake")
install(DIRECTORY ${CMAKE_PREFIX_PATH}/include/
COMPONENT ${DEV_COMPONENT}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install the json schema validator target
install(TARGETS nlohmann_json nlohmann_json_schema_validator
EXPORT ${PROJECT_NAME}Targets
LIBRARY
COMPONENT ${REL_COMPONENT}
NAMELINK_SKIP
PUBLIC_HEADER
DESTINATION ${PUBLIC_HEADERS_DESTINATION}
INCLUDES DESTINATION ${PUBLIC_HEADERS_DESTINATION})
endif ()

endforeach ()

# Create the config file
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${NAMESPACE}${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION cmake)

# Generate the version file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${NAMESPACE}${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion
)

# Expose the Targets.cmake in the CURRENT_BINARY_DIR
export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/${NAMESPACE}${PROJECT_NAME}Targets.cmake"
NAMESPACE ${NAMESPACE}::)

# Install the CMake files
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${NAMESPACE}${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${NAMESPACE}${PROJECT_NAME}ConfigVersion.cmake"
COMPONENT ${DEV_COMPONENT}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${NAMESPACE}${PROJECT_NAME}")
install(EXPORT
${PROJECT_NAME}Targets
FILE
"${NAMESPACE}${PROJECT_NAME}Targets.cmake"
NAMESPACE ${NAMESPACE}::
COMPONENT ${DEV_COMPONENT}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${NAMESPACE}${PROJECT_NAME}")
16 changes: 16 additions & 0 deletions cmake/paths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configure the paths for output
if (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
endif ()

if (NOT DEFINED CMAKE_LIBRARY_INCLUDE_DIRECTORY)
set(CMAKE_LIBRARY_INCLUDE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
endif ()

if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif ()

if (NOT DEFINED CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/build)
endif ()
90 changes: 90 additions & 0 deletions cmake/poco-options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Options for Poco
if (${BUILD_POCO})

# The Utility bundle
OPTION(POCO_BUILD_UTIL "" ON)
if (${POCO_BUILD_UTIL})
OPTION(POCO_ENABLE_UTIL "" ON)
endif ()

# The Network bundle
OPTION(POCO_BUILD_NET "" OFF)
if (${POCO_BUILD_NET})
OPTION(POCO_ENABLE_NET "" ON)
OPTION(POCO_ENABLE_NETSSL "" ON)
OPTION(POCO_ENABLE_CRYPTO "" ON)
if (WIN32)
OPTION(POCO_ENABLE_NETSSL_WIN "" OFF)
else ()
OPTION(POCO_ENABLE_NETSSL_WIN "" ON)
endif ()
endif ()

# The Data bundle
OPTION(POCO_BUILD_DATA "" OFF)
if (${POCO_BUILD_DATA})
OPTION(POCO_ENABLE_DATA "" ON)
OPTION(POCO_ENABLE_DATA_SQLITE "" ON)
OPTION(POCO_ENABLE_DATA_MYSQL "" OFF)
OPTION(POCO_ENABLE_DATA_ODBC "" ON)
endif ()

# The Encodings bundle
OPTION(POCO_BUILD_ENCODINGS "" OFF)
if (${POCO_BUILD_ENCODINGS})
OPTION(POCO_ENABLE_ENCODINGS "" ON)
OPTION(POCO_ENABLE_ENCODINGS_COMPILER "" ON)
OPTION(POCO_ENABLE_XML "" ON)
OPTION(POCO_ENABLE_JSON "" ON)
endif ()

# The MongoDB bundle
OPTION(POCO_BUILD_MONGODB "" OFF)
if (${POCO_BUILD_MONGODB})
OPTION(POCO_ENABLE_MONGODB "" ON)
endif ()

# The Redis bundle
OPTION(POCO_BUILD_REDIS "" OFF)
if (${POCO_BUILD_REDIS})
OPTION(POCO_ENABLE_REDIS "" ON)
endif ()

# The ZIP bundle
OPTION(POCO_BUILD_ZIP "" OFF)
if (${POCO_BUILD_ZIP})
OPTION(POCO_ENABLE_SEVENZIP "" ON)
OPTION(POCO_ENABLE_ZIP "" ON)
endif ()

# The PageCompiler bundle
OPTION(POCO_BUILD_PAGECOMPILER "" OFF)
if (${POCO_BUILD_PAGECOMPILER})
OPTION(POCO_ENABLE_PAGECOMPILER "" ON)
OPTION(POCO_ENABLE_PAGECOMPILER_FILE2PAGE "" ON)
endif ()

# The PDF bundle
OPTION(POCO_BUILD_PDF "" OFF)
if (${POCO_BUILD_PDF})
OPTION(POCO_ENABLE_PDF "" ON)
endif ()

# The Apache connection bundle
OPTION(POCO_BUILD_APACHECONNECTOR "" OFF)
if (${POCO_BUILD_APACHECONNECTOR})
OPTION(POCO_ENABLE_APACHECONNECTOR "" ON)
endif ()

# The CppParser bundle
OPTION(POCO_BUILD_CPPPARSER "" OFF)
if (${POCO_BUILD_CPPPARSER})
OPTION(POCO_ENABLE_CPPPARSER "" ON)
endif ()

# The PocoDoc bundle
OPTION(POCO_BUILD_POCODOC "" OFF)
if (${POCO_BUILD_POCODOC})
OPTION(POCO_ENABLE_POCODOC "" ON)
endif ()
endif ()
6 changes: 1 addition & 5 deletions configure.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2022 Wolkabout Technology s.r.o.
# Copyright 2023 Wolkabout Technology s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,6 @@
# Create the directory used
mkdir -p out

# Add the pre-commit hook to check code format with .clang-format
cp tools/git/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

# Enter the directory and start the CMake build
pushd out || exit
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
Expand Down
Loading

0 comments on commit 459bd98

Please sign in to comment.