From 629f465866a6da640b8669e2919059de3b23f08b Mon Sep 17 00:00:00 2001 From: Simon Thorell Date: Mon, 5 Feb 2024 11:35:57 +0000 Subject: [PATCH 1/3] Devcontainer config --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 9 +- .vscode/c_cpp_properties.json | 14 +++ .vscode/cmake-kits.json | 10 ++ .vscode/keybindings.json | 17 +++- .vscode/launch.json | 2 +- .vscode/settings.json | 162 ++++++++++++++++---------------- .vscode/tasks.json | 17 ++++ 8 files changed, 141 insertions(+), 91 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/cmake-kits.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c7b8882..fd2d5ff 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -24,6 +24,7 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ # Git, OpenSSL, and SSL development libraries are required to build the dependencies RUN apt-get update && apt-get install -y \ git \ + ninja-build \ openssl \ libssl-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 72165e2..03948fd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,13 +17,14 @@ // Configure tool-specific properties. "customizations": { "extensions": [ - "ms-vscode.cpptools", // C/C++ Extension - "ms-vscode.cmake-tools", // CMake Tools - "twxs.cmake" // CMake Extension + "ms-vscode.cpptools", // C/C++ Extension + "ms-vscode.cmake-tools", // CMake Tools + "twxs.cmake" // CMake Extension ], "vscode": { "extensions": [ - "tal7aouy.icons" // Custom VS-Code Icons + "tal7aouy.icons", // Custom VS-Code Icons + "bierner.markdown-preview-github-styles" // Markdown Preview Github Styles ] } }, diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a8ebc24 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,14 @@ +{ + "configurations": [ + { + "name": "Linux Debian12 DevContainer", + "includePath": ["${workspaceFolder}/**"], + "defines": [], + "compilerPath": "/usr/bin/aarch64-linux-gnu-g++", + "cStandard": "c17", + "cppStandard": "c++20", + "intelliSenseMode": "linux-gcc-arm64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json new file mode 100644 index 0000000..95b336a --- /dev/null +++ b/.vscode/cmake-kits.json @@ -0,0 +1,10 @@ +[ + { + "name": "GCC 12.2.0 aarch64-linux-gnu", + "compilers": { + "C": "/usr/bin/aarch64-linux-gnu-gcc", + "CXX": "/usr/bin/aarch64-linux-gnu-g++" + }, + "isTrusted": true + } + ] \ No newline at end of file diff --git a/.vscode/keybindings.json b/.vscode/keybindings.json index 2c22c5f..d4c3c42 100644 --- a/.vscode/keybindings.json +++ b/.vscode/keybindings.json @@ -1,5 +1,12 @@ -{ - "key": "shift+f5", // Replace with your preferred shortcut - "command": "workbench.action.tasks.runTask", - "args": "Run MyProject" -} \ No newline at end of file +// [ +// { +// "key": "shift+f5", +// "command": "workbench.action.tasks.runTask", +// "args": "Run MyProject" +// }, + // { + // "key": "ctrl+f7", + // "command": "workbench.action.tasks.runTask", + // "args": "CMake Clean Build" + // } +// ] diff --git a/.vscode/launch.json b/.vscode/launch.json index 89f8800..d854cd9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "environment": [], "externalConsole": false, // Set to true in order to use MacOS terminal instead of VSCode terminal "MIMode": "lldb", - "preLaunchTask": "CMake Build Task" // Replace with your build task name + // "preLaunchTask": "CMake Build Task" // Replace with your build task name } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index bc12890..eab5cfa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,83 +1,83 @@ { -"workbench.iconTheme": "icons", -"files.associations": { - "__bit_reference": "cpp", - "__config": "cpp", - "__debug": "cpp", - "__errc": "cpp", - "__hash_table": "cpp", - "__locale": "cpp", - "__mutex_base": "cpp", - "__node_handle": "cpp", - "__split_buffer": "cpp", - "__threading_support": "cpp", - "__verbose_abort": "cpp", - "array": "cpp", - "atomic": "cpp", - "bitset": "cpp", - "cctype": "cpp", - "charconv": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "complex": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "exception": "cpp", - "initializer_list": "cpp", - "ios": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "locale": "cpp", - "mutex": "cpp", - "new": "cpp", - "optional": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "span": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "typeinfo": "cpp", - "unordered_map": "cpp", - "variant": "cpp", - "vector": "cpp", - "algorithm": "cpp", - "condition_variable": "cpp", - "iomanip": "cpp", - "numbers": "cpp", - "thread": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "chrono": "cpp", - "compare": "cpp", - "concepts": "cpp", - "deque": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "random": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "format": "cpp", - "ranges": "cpp", - "queue": "cpp", - "semaphore": "cpp", - "stack": "cpp", - "stop_token": "cpp" -} + "workbench.iconTheme": "icons", + "files.associations": { + "__bit_reference": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "atomic": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "locale": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp", + "algorithm": "cpp", + "condition_variable": "cpp", + "iomanip": "cpp", + "numbers": "cpp", + "thread": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "compare": "cpp", + "concepts": "cpp", + "deque": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "ranges": "cpp", + "queue": "cpp", + "semaphore": "cpp", + "stack": "cpp", + "stop_token": "cpp" + } } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bacb093..03c1a06 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,6 +1,23 @@ { "version": "2.0.0", "tasks": [ + { + "label": "CMake Clean Build", // Keeping _deps folder + "type": "shell", + "command": "find . -mindepth 1 -maxdepth 1 ! -name '_deps' -exec rm -rf {} +", + "options": { + "cwd": "${workspaceFolder}/build" + }, + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "shared" + } + }, { // Debug task "label": "CMake Build Task", From 5fd81abf10a69c3108b24bec7fbfdbba672375ed Mon Sep 17 00:00:00 2001 From: Simon Thorell Date: Mon, 5 Feb 2024 18:20:00 +0000 Subject: [PATCH 2/3] Dependencies add CMake --- .devcontainer/Dockerfile | 3 +- .vscode/keybindings.json | 12 ------ .vscode/launch.json | 34 +++++++++++++++- .vscode/tasks.json | 83 +++++++++++++++++++++++++--------------- CMakeLists.txt | 52 +++++++++++++++++-------- include/test_file.h | 8 ++++ src/CMakeLists.txt | 23 ++++++----- src/main.cpp | 6 +++ src/test_file.cpp | 6 +++ 9 files changed, 157 insertions(+), 70 deletions(-) delete mode 100644 .vscode/keybindings.json create mode 100644 include/test_file.h create mode 100644 src/test_file.cpp diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index fd2d5ff..0bc67e2 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -21,12 +21,13 @@ RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -# Git, OpenSSL, and SSL development libraries are required to build the dependencies +# Git, OpenSSL, SSL and SQLite3 development libraries are required to build the dependencies RUN apt-get update && apt-get install -y \ git \ ninja-build \ openssl \ libssl-dev \ + sqlite3 \ && rm -rf /var/lib/apt/lists/* #============================================================================== diff --git a/.vscode/keybindings.json b/.vscode/keybindings.json deleted file mode 100644 index d4c3c42..0000000 --- a/.vscode/keybindings.json +++ /dev/null @@ -1,12 +0,0 @@ -// [ -// { -// "key": "shift+f5", -// "command": "workbench.action.tasks.runTask", -// "args": "Run MyProject" -// }, - // { - // "key": "ctrl+f7", - // "command": "workbench.action.tasks.runTask", - // "args": "CMake Clean Build" - // } -// ] diff --git a/.vscode/launch.json b/.vscode/launch.json index d854cd9..127105b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,3 +1,35 @@ +// { +// "version": "0.2.0", +// "configurations": [ +// { +// "name": "C/C++: Debug My Project", +// "type": "cppdbg", +// "request": "launch", +// "program": "${workspaceFolder}/build/debug/MyProject", // Path to your binary +// "args": [], // Command line arguments (if any) +// "stopAtEntry": false, +// "cwd": "${workspaceFolder}", +// "environment": [], +// "externalConsole": false, +// "MIMode": "gdb", +// "miDebuggerPath": "/usr/bin/gdb", // Path to GDB +// "setupCommands": [ +// { +// "description": "Enable pretty-printing for gdb", +// "text": "-enable-pretty-printing", +// "ignoreFailures": true +// } +// ], +// "preLaunchTask": "CMake Build Task", // Task to run before debugging +// "logging": { +// "trace": true, +// "traceResponse": true, +// "engineLogging": true +// } +// } +// ] +// } + { "version": "0.2.0", "configurations": [ @@ -12,7 +44,7 @@ "environment": [], "externalConsole": false, // Set to true in order to use MacOS terminal instead of VSCode terminal "MIMode": "lldb", - // "preLaunchTask": "CMake Build Task" // Replace with your build task name + "preLaunchTask": "CMake Build Task" // Replace with your build task name } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 03c1a06..fd2ed8c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,43 +1,42 @@ { - "version": "2.0.0", "tasks": [ { - "label": "CMake Clean Build", // Keeping _deps folder - "type": "shell", - "command": "find . -mindepth 1 -maxdepth 1 ! -name '_deps' -exec rm -rf {} +", + "label": "CMake Build Task", + "type": "cppbuild", + "command": "/usr/bin/aarch64-linux-gnu-g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}", + "-I${workspaceFolder}/include" + ], "options": { - "cwd": "${workspaceFolder}/build" + "cwd": "${fileDirname}" }, - "problemMatcher": [], - "group": { - "kind": "build", - "isDefault": true - }, - "presentation": { - "reveal": "always", - "panel": "shared" - } + "problemMatcher": [ + "$gcc" + ], + "group": "build", + "detail": "Debugging Configuration" }, { - // Debug task - "label": "CMake Build Task", + "label": "Run Debug Binary", "type": "shell", - "command": "cmake", - "args": [ - "--build", - "${workspaceFolder}/build" - // Add additional arguments as needed - ], - "group": { - "kind": "build", - "isDefault": true - } + "command": "${workspaceFolder}/build/debug/MyProject", + "group": "build", + "presentation": { + "reveal": "always", + "panel": "new", + "clear": true + }, + "problemMatcher": [] }, { - // Run executable task - "label": "Run MyProject", + "label": "Run Release Binary", "type": "shell", - "command": "${workspaceFolder}/build/src/MyProject", + "command": "${workspaceFolder}/build/release/MyProject", "group": "build", "presentation": { "reveal": "always", @@ -45,6 +44,30 @@ "clear": true }, "problemMatcher": [] + }, + { + "type": "cppbuild", + "label": "C/C++: g++-12 build active file", + "command": "/usr/bin/g++-12", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." } - ] + ], + "version": "2.0.0" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ccfd43..5a84608 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,45 @@ cmake_minimum_required(VERSION 3.28.2) project(MyProject) -# Specify the C++ standard +#=================== Set C++ Standard ====================# set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) -# Fetch external libraries -include(FetchContent) +#================= Set Build Configuration ================# +# Debug configuration +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message("Debug build") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/debug) + add_compile_options( + -g # Debug information + -Werror # Treat warnings as errors + -Wall # Enable all warnings + -Wextra # Enable extra warnings + -pedantic # Ensure standards-compliant code + ) + +# Release configuration +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + message("Release build") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release) + add_compile_options( + -O2 # Optimization level 2 + ) + +# Other configurations (if needed) +else() + message("Other build configuration") +endif() + +#================= Find Installed Packages ================# +find_package(OpenSSL REQUIRED) +find_package(PahoMqttCpp REQUIRED) +find_package(SQLite3 REQUIRED) #======================= Fetch JSON =======================# -# Fetch the JSON library as it's a header-only library +include(FetchContent) # Fetch external libraries +# Fetch the JSON library as it's a header-only library FetchContent_Declare( json GIT_REPOSITORY https://github.com/nlohmann/json.git @@ -18,17 +47,6 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(json) -#==========================================================# - -# Add the subdirectories +#=================== Add Subdirectories ===================# add_subdirectory(src) -add_subdirectory(tests) - -# Add compiler options -add_compile_options( - -Werror # Treat warnings as errors - -Wall # Enable all warnings - -Wextra # Enable extra warnings - -pedantic # Ensure standards-compliant code - -O2 # Optimize code -) \ No newline at end of file +add_subdirectory(tests) \ No newline at end of file diff --git a/include/test_file.h b/include/test_file.h new file mode 100644 index 0000000..13a88b6 --- /dev/null +++ b/include/test_file.h @@ -0,0 +1,8 @@ +#ifndef TEST_FILE_H +#define TEST_FILE_H + +#include + +int test_method(); + +#endif // TEST_FILE_H \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2c7d85..93cc896 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,24 +1,29 @@ #============= Find All Source Files ===============# -file(GLOB_RECURSE SOURCE_FILES "*.cpp") +set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/test_file.cpp +) + +message(STATUS "Source files: ${SOURCE_FILES}") -#============ Find External Libraries ==============# +#================= Find Libraries =================# add_library(MyProjectLib ${SOURCE_FILES}) target_include_directories(MyProjectLib PUBLIC - ../include PRIVATE + ../include ${json_SOURCE_DIR}/include ) #============ Link external libraries ==============# target_link_libraries(MyProjectLib PRIVATE nlohmann_json::nlohmann_json + OpenSSL::Crypto + paho-mqtt3as + paho-mqttpp3 + sqlite3 ) #=============== Add the executable ================# -add_executable(MyProject ${SOURCE_FILES}) -target_include_directories(MyProject PUBLIC "../include") +add_executable(${PROJECT_NAME} main.cpp) # Only compile main.cpp for the executable +target_include_directories(${PROJECT_NAME} PUBLIC ../include) #========= Link against static libraries ===========# -# Uncomment to link against external libraries -target_link_libraries(MyProject PRIVATE - MyProjectLib # Link against the static library -) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} MyProjectLib) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1cb17f6..3999abf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,12 @@ #include +#include // OpenSSL Crypto library +#include // SQLite3 library +#include // MQTT library +#include "test_file.h" int main() { + int testing = test_method(); + std::cout << "Testing: " << testing << std::endl; return 0; } \ No newline at end of file diff --git a/src/test_file.cpp b/src/test_file.cpp new file mode 100644 index 0000000..37c4680 --- /dev/null +++ b/src/test_file.cpp @@ -0,0 +1,6 @@ +#include "test_file.h" + +int test_method() { + std::cout << "Hello, world!" << std::endl; + return 1; +} \ No newline at end of file From 6100c0a0ca8a83948554993bcb1b83e560c95642 Mon Sep 17 00:00:00 2001 From: Simon Thorell Date: Mon, 5 Feb 2024 18:27:13 +0000 Subject: [PATCH 3/3] Rename app --- .vscode/launch.json | 59 +++++++++++++++----------------------------- .vscode/tasks.json | 4 +-- CMakeLists.txt | 2 +- src/CMakeLists.txt | 8 +++--- tests/CMakeLists.txt | 12 ++++----- 5 files changed, 33 insertions(+), 52 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 127105b..e83a406 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,50 +1,31 @@ -// { -// "version": "0.2.0", -// "configurations": [ -// { -// "name": "C/C++: Debug My Project", -// "type": "cppdbg", -// "request": "launch", -// "program": "${workspaceFolder}/build/debug/MyProject", // Path to your binary -// "args": [], // Command line arguments (if any) -// "stopAtEntry": false, -// "cwd": "${workspaceFolder}", -// "environment": [], -// "externalConsole": false, -// "MIMode": "gdb", -// "miDebuggerPath": "/usr/bin/gdb", // Path to GDB -// "setupCommands": [ -// { -// "description": "Enable pretty-printing for gdb", -// "text": "-enable-pretty-printing", -// "ignoreFailures": true -// } -// ], -// "preLaunchTask": "CMake Build Task", // Task to run before debugging -// "logging": { -// "trace": true, -// "traceResponse": true, -// "engineLogging": true -// } -// } -// ] -// } - { "version": "0.2.0", "configurations": [ { - "name": "Debug MyProject with LLDB", + "name": "C/C++: Debug Project", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/src/MyProject", - "args": [], + "program": "${workspaceFolder}/build/debug/cpp-mqtt-sqlite", // Path to your binary + "args": [], // Command line arguments (if any) "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], - "externalConsole": false, // Set to true in order to use MacOS terminal instead of VSCode terminal - "MIMode": "lldb", - "preLaunchTask": "CMake Build Task" // Replace with your build task name + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerPath": "/usr/bin/gdb", // Path to GDB + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "CMake Build Task", // Task to run before debugging + "logging": { + "trace": true, + "traceResponse": true, + "engineLogging": true + } } ] -} +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fd2ed8c..1c2d19c 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -24,7 +24,7 @@ { "label": "Run Debug Binary", "type": "shell", - "command": "${workspaceFolder}/build/debug/MyProject", + "command": "${workspaceFolder}/build/debug/cpp-mqtt-sqlite", "group": "build", "presentation": { "reveal": "always", @@ -36,7 +36,7 @@ { "label": "Run Release Binary", "type": "shell", - "command": "${workspaceFolder}/build/release/MyProject", + "command": "${workspaceFolder}/build/release/cpp-mqtt-sqlite", "group": "build", "presentation": { "reveal": "always", diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a84608..f25b2e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.28.2) -project(MyProject) +project(cpp-mqtt-sqlite) #=================== Set C++ Standard ====================# set(CMAKE_CXX_STANDARD 20) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93cc896..6df1645 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,14 +6,14 @@ set(SOURCE_FILES message(STATUS "Source files: ${SOURCE_FILES}") #================= Find Libraries =================# -add_library(MyProjectLib ${SOURCE_FILES}) -target_include_directories(MyProjectLib PUBLIC +add_library(${PROJECT_NAME}-lib ${SOURCE_FILES}) +target_include_directories(${PROJECT_NAME}-lib PUBLIC ../include ${json_SOURCE_DIR}/include ) #============ Link external libraries ==============# -target_link_libraries(MyProjectLib PRIVATE +target_link_libraries(${PROJECT_NAME}-lib PRIVATE nlohmann_json::nlohmann_json OpenSSL::Crypto paho-mqtt3as @@ -26,4 +26,4 @@ add_executable(${PROJECT_NAME} main.cpp) # Only compile main.cpp for the executa target_include_directories(${PROJECT_NAME} PUBLIC ../include) #========= Link against static libraries ===========# -target_link_libraries(${PROJECT_NAME} MyProjectLib) \ No newline at end of file +target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}-lib) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d23a76..a80defd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,22 +8,22 @@ FetchContent_Declare( FetchContent_MakeAvailable(googletest) # Link against gtest or gtest_main as needed -add_executable(TestMyProject test_main.cpp) # Adjust with your test files +add_executable(test-${PROJECT_NAME} test_main.cpp) # Adjust with your test files # target_link_libraries(TestMyProject gtest_main) -target_link_libraries(TestMyProject gtest_main MyProjectLib) +target_link_libraries(test-${PROJECT_NAME} gtest_main ${PROJECT_NAME}-lib) # Include the directory where header files is located -target_include_directories(TestMyProject PRIVATE ../include) +target_include_directories(test-${PROJECT_NAME} PRIVATE ../include) # Add your tests here -add_test(NAME test_my_project COMMAND TestMyProject) +add_test(NAME test_my_project COMMAND test-${PROJECT_NAME}) # For more info on GoogleTest, see https://google.github.io/googletest/quickstart-cmake.html # Create a custom target for running tests at compile time add_custom_target(run_tests ALL COMMAND echo "Running Tests" - COMMAND $) + COMMAND $) # Make sure your main project always builds before the tests -add_dependencies(MyProject run_tests) \ No newline at end of file +add_dependencies(${PROJECT_NAME} run_tests) \ No newline at end of file