From ea0562d1d13b92366284756d69e53dcfc76a7865 Mon Sep 17 00:00:00 2001 From: Grabt234 Date: Sat, 16 Dec 2023 18:28:43 +0200 Subject: [PATCH] Feat: Adding unix build --- CMakeLists.txt | 77 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 895702a..53a90d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,15 +2,74 @@ cmake_minimum_required(VERSION 3.18) project(BaseModuleProject CXX) +# Set directory vars set(SOURCE_DIR "source") set(INCLUDE_DIR "include") +set(SOURCE_TESTS_DIR "source_tests") +set(INCLUDE_TESTS_DIR "include_tests") -idf_component_register( - SRCS - ${SOURCE_DIR}/BaseModule.cpp - ${SOURCE_DIR}/RouterModule.cpp - INCLUDE_DIRS - ${INCLUDE_DIR} - REQUIRES - Chunk_Types -) +if(DEFINED ENV{IDF_PATH}) # this is normally only set when running in an esp idf terminal + message(STATUS "Building for ESP32") + + idf_component_register( + SRCS + ${SOURCE_DIR}/BaseModule.cpp + ${SOURCE_DIR}/RouterModule.cpp + INCLUDE_DIRS + ${INCLUDE_DIR} + REQUIRES + Chunk_Types + ) + +else() + message(STATUS "Building for Unix") + + # Set C++ standard + set(CMAKE_CXX_STANDARD 20) + + # Main executable + file(GLOB SOURCES "${SOURCE_DIR}/*.cpp") + add_library(BaseModuleLib + ${SOURCES} + ) + + # Test executable + add_executable(BaseModuleTest + ${SOURCE_TESTS_DIR}/BaseModuleTest.cpp + ) + + add_subdirectory(components/Chunk_Types) + add_subdirectory(components/plog) + + # Include directories for main code and tests + target_include_directories(BaseModuleLib + PRIVATE ${INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/components/Chunk_Types/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/components/plog/include + ) + + target_include_directories(BaseModuleTest + PRIVATE ${INCLUDE_DIR} + PRIVATE ${INCLUDE_TESTS_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/components/doctest/doctest + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/components/Chunk_Types/include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/components/plog/include + ) + + # Adding threads + target_link_libraries(BaseModuleLib PRIVATE pthread) + target_link_libraries(BaseModuleLib PRIVATE ${THREADS_LIBRARIES}) + + # Link with required libraries for the main executable + target_link_libraries(BaseModuleLib PRIVATE doctest::doctest) + + # Link with required libraries for the test executable + target_link_libraries(BaseModuleTest PRIVATE BaseModuleLib doctest::doctest) + + # Enable testing + enable_testing() + + # Add tests to CTest + add_test(NAME BaseModuleTest COMMAND BaseModuleTest) + +endif()