Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CMake Infrastructure Start #814

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions cmake/spiffs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Find SPIFFS

if(DEFINED ENV{SPIFFSPATH})
set(SPIFFSPATH $ENV{SPIFFSPATH})
else()
find_path(
SPIFFSPATH
src/
HINTS
/opt/spiffs
/opt/spiffs/default
)
endif()

# SPIFFS
if(${TARGET_SPIFFS})
add_library(spiffs
${SPIFFSPATH}/src/spiffs_cache.c
${SPIFFSPATH}/src/spiffs_check.c
${SPIFFSPATH}/src/spiffs_gc.c
${SPIFFSPATH}/src/spiffs_hydrogen.c
${SPIFFSPATH}/src/spiffs_nucleus.c
${OPENMRNPATH}/src/freertos_drivers/spiffs/SPIFFS.cxx
)
target_include_directories(spiffs
PUBLIC
${SPIFFSPATH}/src
${OPENMRNPATH}/src/frertos_drivers/spiffs
)
target_compile_options(spiffs
PUBLIC
-DNO_TEST
)
endif() # TARGET_SPIFFS
55 changes: 55 additions & 0 deletions cmake/test_setup_epilogue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This is a target file designed to run on a host system.

# Treat the tests (*.cxxtest extension) as C++ language files.
set_source_files_properties(${TESTS} PROPERTIES LANGUAGE CXX)

if(${COVERAGE})
# Setup gcov target.
add_custom_target(TARGET_GCOV ALL
DEPENDS gcovr/coverage.html
)
endif()

# Build an executable for each test file.
foreach(testsourcefile ${TESTS})
get_filename_component(testname ${testsourcefile} NAME_WE)
add_executable(${testname} ${testsourcefile})
target_include_directories(${testname}
PUBLIC
$ENV{OPENMRNPATH}/src
$ENV{OPENMRNPATH}/include
$ENV{SXMLCPATH}/src
${ROOT_DIR}
)
target_link_libraries(${testname}
GTest::gtest_main
GTest::gmock_main

-fPIC
-lgcov
-Wl,--start-group
openmrn
${LINK_LIBS}
-Wl,--end-group
-lavahi-client
-lavahi-common
)
add_custom_command(TARGET ${testname}
POST_BUILD
COMMAND ./${testname}
# Forces the coverage report to be regenerated if tests are run.
COMMAND rm -rf gcovr
)
if(${COVERAGE})
add_dependencies(TARGET_GCOV ${testname})
endif()
endforeach(testsourcefile ${TESTS})

if(${COVERAGE})
# Generate the HTML coverage report
add_custom_command(OUTPUT gcovr/coverage.html
COMMAND mkdir -p gcovr
COMMAND gcovr --html-details gcovr/coverage.html --exclude=_deps.* -r ${GCOV_SOURCE_DIR} .
VERBATIM
)
endif()
53 changes: 53 additions & 0 deletions cmake/test_setup_prologue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is a target file designed to run on a host system.

# Default coverage option to off.
option(COVERAGE "COVERAGE" OFF)

# Enable the required language standards.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

if(NOT DEFINED GTEST_TAG)
set(GTEST_TAG v1.15.2)
endif()
message(STATUS "Using GoogleTest tag: ${GTEST_TAG}")

# Get a copy of GoogleTest.
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/${GTEST_TAG}.zip
)

# On Windows: Prevent overriding the parent project's compiler/linker settings.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# This magic is required in order to properly add the "-x" option for the
# *.cxxtest file extension.
set(CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> -c -MD -MF [email protected] <DEFINES> <INCLUDES> <FLAGS> -o \
<OBJECT> -c -x c++ <SOURCE>"
)

# Compile flags.
add_compile_options(
-fPIC -g -O0 -Wall -Werror -DGTEST -D_GNU_SOURCE
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-Wno-attributes
)
if(${COVERAGE})
# Compile flags for coverage.
add_compile_options(--coverage)
endif()

# GTest and GMock includes.
include_directories(${gtest_SOURCE_DIR}/include ${gmock_SOURCE_DIR}/include)

# Add OpenMRN sources
add_subdirectory(${OPENMRNPATH}/src openmrn)

Loading
Loading