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

fix(cmake): fix custom targets #313

Merged
merged 81 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7d6cead
fix(cmake): fix custom targets
glencoe Oct 25, 2024
950a596
wip(cmake): make the first three unit tests work
glencoe Oct 28, 2024
963c035
wip(cmake): add cmake presets
glencoe Oct 28, 2024
47ec78f
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Oct 28, 2024
bef97d0
wip(cmake): compile hw tests
glencoe Oct 29, 2024
9969e45
wip(cmake): make custom targets more explicit
glencoe Oct 29, 2024
fdc8e97
docs(cmake): document new cmake approach
glencoe Oct 30, 2024
b1d56ef
docs(cmake): remove transitive deps
glencoe Nov 4, 2024
9510e6c
fix(cmake): restore previous __hdrs __impl behaviour
glencoe Nov 4, 2024
61815be
fix(cmake): add missing cmake targets
glencoe Nov 4, 2024
2a2f5d1
build(cmake): add missing cmake targets
glencoe Nov 4, 2024
f87c641
fix(cmake): fix cmake files for unit tests except for mqtt unit test
Nov 4, 2024
47e57f7
fix(cmake): cheat direct dependency linking order
Nov 5, 2024
ba5ca26
wip(cmake): first hardwaretest cmake implementation
Nov 6, 2024
f43d5ac
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 6, 2024
94563ee
wip(cmake): Hardwaretest for BMI works now, but StressTestAdxl345b st…
Nov 8, 2024
0cb3022
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 8, 2024
115486d
wip(cmake): fix stub_defs print message
Nov 11, 2024
d338c03
wip(cmake): move to idiomatic cmake defs
glencoe Nov 11, 2024
1f93701
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
glencoe Nov 11, 2024
363efcf
wip(cmake): simplify scripts and fix conflicts
glencoe Nov 12, 2024
7d5c616
wip(cmake): add adxl hw test
glencoe Nov 12, 2024
1e0c66d
fix(cmake): sensor hardwaretest work
Nov 12, 2024
bd0cd60
wip(cmake): working on spi and network issue
Nov 15, 2024
b54bc22
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
b2efae8
fix(cmake): fix missing dependency on http hw test
Nov 15, 2024
b5680a2
fix(cmake): fix missing dependency on usb hw test
Nov 15, 2024
6aa3f5d
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
7dcc566
fix(cmake): fix missing dependencies
Nov 15, 2024
f34952f
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
d03e74b
fix(cmake): unit tests work
Nov 20, 2024
8b23218
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 20, 2024
250ca31
wip(cmake): implement bare bones hw test for esp
Nov 28, 2024
f588a24
fix(cmake): fix custom targets
glencoe Oct 25, 2024
4a1d525
wip(cmake): make the first three unit tests work
glencoe Oct 28, 2024
af65dfd
wip(cmake): add cmake presets
glencoe Oct 28, 2024
950545f
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Oct 28, 2024
e083472
fix(unit-test): fix merge conflicts
glencoe Oct 29, 2024
7fff5db
wip(cmake): make custom targets more explicit
glencoe Oct 29, 2024
620644c
docs(cmake): document new cmake approach
glencoe Oct 30, 2024
aefb7d6
docs(cmake): remove transitive deps
glencoe Nov 4, 2024
a4f612f
fix(cmake): restore previous __hdrs __impl behaviour
glencoe Nov 4, 2024
9b0ec60
fix(cmake): add missing cmake targets
glencoe Nov 4, 2024
2f87cf8
build(cmake): add missing cmake targets
glencoe Nov 4, 2024
c690339
fix(cmake): fix cmake files for unit tests except for mqtt unit test
Nov 4, 2024
144142d
fix(cmake): cheat direct dependency linking order
Nov 5, 2024
322367d
wip(cmake): first hardwaretest cmake implementation
Nov 6, 2024
d44d6ef
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 6, 2024
d146843
wip(cmake): Hardwaretest for BMI works now, but StressTestAdxl345b st…
Nov 8, 2024
e44604b
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 8, 2024
6c111aa
wip(cmake): move to idiomatic cmake defs
glencoe Nov 11, 2024
5712787
wip(cmake): simplify scripts and fix conflicts
glencoe Nov 12, 2024
aa0012a
wip(cmake): add adxl hw test
glencoe Nov 12, 2024
e7148d5
fix(cmake): sensor hardwaretest work
Nov 12, 2024
8565348
wip(cmake): working on spi and network issue
Nov 15, 2024
1413dca
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
d0acacf
fix(cmake): fix missing dependency on http hw test
Nov 15, 2024
59c1c9d
fix(cmake): fix missing dependency on usb hw test
Nov 15, 2024
10bb7aa
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
b0fdb7c
fix(cmake): fix missing dependencies
Nov 15, 2024
1a71b4e
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Nov 15, 2024
deba7e5
fix(unit-test): resolve merge conflict no. 2
Nov 20, 2024
d526599
fix(unit-test): fix merge conflict no. 3
actions-user Nov 20, 2024
d36d89b
wip(cmake): implement bare bones hw test for esp
Nov 28, 2024
9db9047
fix(hardware-test): fixing hardware tests that were not building corr…
Dec 20, 2024
c0c1538
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
daa3006
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Dec 20, 2024
29b4bb0
Update run_checks.yml
HerrCooker Dec 20, 2024
c49cde2
Update run_checks.yml
HerrCooker Dec 20, 2024
99c2915
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
46ac496
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
21070c1
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
48e3427
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
dbc2929
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
fde6422
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
ce1dc30
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
944b3a0
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
9f17a05
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
d49c0bc
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
32a2013
Merge remote-tracking branch 'origin/fix-custom-cmake-targets' into f…
Dec 20, 2024
85c2b9c
style(all): apply clang-format to 'fix-custom-cmake-targets'
actions-user Dec 20, 2024
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
15 changes: 5 additions & 10 deletions .github/workflows/run_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- clang-format
strategy:
matrix:
config: [1, 2]

steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -83,20 +81,17 @@ jobs:
sudo apt install -y ninja-build
- name: Setup CMake
run: |
cmake -B build/unit-tests -D UNIT_TEST:BOOL=ON -D CMAKE_BUILD_TYPE=DEBUG -D REVISION=${{ matrix.config }} -G Ninja .
cmake -B build/host -D UNIT_TEST:BOOL=ON -D CMAKE_BUILD_TYPE=DEBUG -D ELASTIC_AI_TARGET=HOST -G Ninja .
- name: Build Targets
run: |
cmake --build build/unit-tests -j 4
cmake --build build/host -j 4
- name: Run Unit-Tests
run: ctest --test-dir build/unit-tests/test/unit --output-on-failure
run: ctest --test-dir build/host/test/unit --output-on-failure

build_all_targets:
runs-on: ubuntu-latest
needs:
- unit-tests
strategy:
matrix:
config: [1, 2]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -107,7 +102,7 @@ jobs:
sudo apt update && sudo apt install -y ninja-build gcc-arm-none-eabi graphviz
- name: Setup CMake
run: |
cmake -B build -D CMAKE_BUILD_TYPE=RELEASE -D REVISION=${{ matrix.config }} -G Ninja .
cmake -B build -D CMAKE_BUILD_TYPE=RELEASE -D ELASTIC_AI_TARGET=ENV5_REV2 -G Ninja .
- name: Build Targets
run: |
cmake --build build
12 changes: 0 additions & 12 deletions .idea/cmake.xml

This file was deleted.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/elastic-ai.runtime.enV5.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/runConfigurations/all.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 44 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,69 +1,64 @@
cmake_minimum_required(VERSION 3.20...3.24)
include(helpers.cmake)

include(cmake/set_build_target.cmake)


include(cmake/third_party_deps.cmake)

add_pico_sdk("2.0.0")
add_unity()
add_cexception()
add_runtime_c()



set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

# enable debug prints
if (DEBUG_OUTPUT)
add_definitions(-DDEBUG_MODE)
endif ()

if (UNIT_TEST)
message(NOTICE "INFO: Building for local machine")
else ()
message(NOTICE "INFO: Building for enV5 hardware (Type: ${CMAKE_BUILD_TYPE})")
setupPicoSdk("2.0.0")
endif ()

project(enV5 C CXX ASM)

# enable test execution via CMake

pico_sdk_init()

include(cmake/custom_targets.cmake)
include(cmake/pico_targets.cmake)

include(CTest)

# include unit-test framework
add_unity()

# include required standard libs for testing

if(UNIT_TEST)
add_runtime_c()
add_cexception()
add_freertos()

if(BUILDING_FOR_ELASTIC_NODE)
add_subdirectory(test/hardware)
add_subdirectory(src)
else()
add_compile_options(-ftrapv) # abort execution on integer overflow

add_subdirectory(src/common)
add_subdirectory(src/network/atCommands)
add_subdirectory(src/network/config)

# include dummies for local machine
add_subdirectory(test/unit/dummies)

# include our own libraries to test
add_subdirectory(src/hal/enV5HwConfiguration)
add_subdirectory(src/sensor/sht3x)
add_subdirectory(src/sensor/adxl345b)
add_subdirectory(src/sensor/pac193x)
add_subdirectory(src/network/wifi)
add_subdirectory(src/network/http)
add_subdirectory(src/network/broker)
add_subdirectory(src/fpga/fpgaConfigurationHandler)
add_subdirectory(src/filesystem)
add_subdirectory(src/flash)
add_subdirectory(src/fpga/fpgaConfigurationHandler)
add_subdirectory(src/hal)
add_subdirectory(src/network)
add_subdirectory(src/rtos)
add_subdirectory(src/sensor)
add_subdirectory(src/usb_protocol)

# include unit-tests
add_subdirectory(test/unit)
else ()
pico_sdk_init()

if (TARGET tinyusb_device)
# include required libraries
add_basic_functionality()
add_freertos_kernel()

add_rp2040_hal()
add_sensor_libraries()

# include hardware tests
add_subdirectory(test/hardware)
add_subdirectory(test/unit/Pac193x)
add_subdirectory(test/unit/FpgaConfigurationHandler)
add_subdirectory(test/unit/Http)
add_subdirectory(test/unit/Network)
add_subdirectory(test/unit/MqttBroker)
add_subdirectory(test/unit/Sht3x)
endif ()

add_dependency_graph()
elseif (PICO_ON_DEVICE)
message(WARNING "Not building Project, because TinyUSB submodule is not initialized in the SDK!")
endif ()
if(BUILDING_FOR_ELASTIC_NODE AND NOT TARGET tinyusb_device)
message(WARNING "not building project, because tinyusb not initialized")
else()
endif ()

76 changes: 76 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "host",
"displayName": "Host Config",
"description": "Build for your host system (MacOs, Linux, Windows)",
"generator": "Ninja",
"binaryDir": "build/host/",
"cacheVariables": {
"ELASTIC_AI_TARGET": "HOST",
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "env5_rev2",
"displayName": "EnV5 Rev2",
"generator": "Ninja",
"binaryDir": "build/env5_rev2",
"cacheVariables": {
"ELASTIC_AI_TARGET": "ENV5_REV2",
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "env5_rev2_debug",
"displayName": "EnV5 Rev2 Debug",
"generator": "Ninja",
"binaryDir": "build/env5_rev2_debug",
"cacheVariables": {
"ELASTIC_AI_TARGET": "ENV5_REV2",
"CMAKE_BUILD_TYPE": "Debug",
"DEBUG_MODE": "ON"
}
}
],
"buildPresets": [
{
"name": "host",
"configurePreset": "host",
"jobs": 4
},
{
"name": "env5_rev2",
"configurePreset": "env5_rev2",
"jobs": 6
},
{
"name": "unit_test",
"inherits": "host",
"targets": "all_unit_tests"
}
],
"testPresets": [
{
"name": "unit_test",
"displayName": "Unit Tests",
"configurePreset": "host",
"output": {
"outputJUnitFile": "unit-test.junit",
"outputOnFailure": true
},
"filter": {
"include": {
"label": "unit"
}
}

}
]
}
49 changes: 49 additions & 0 deletions cmake/Readme.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
== Cmake Scripts

=== Encapsulated Libraries

We want to have the following goals

- fine-grained control over dependencies for flexibility and to facilitate link-time substitution
- prevent access to header files of transitive dependencies, i.e., if you call a function defined in `libB` you have to explicitly depend on it. There should not be a way to include a header provided by `B` without declaring that explicit dependency. This way, we avoid hidden source code dependencies. And each module only sees the header files it actually needs.
- for convenience, we want to have a target combines implementation and headers.

We achieve these by (typically) defining four build targets for each of our modules. Assuming we want to define a new library `A` that performs a direct call to library `B`. Then we define

`A__hdrs`:: providing access to all public header files of our module `A`, e.g.,
+
[source, cmake]
----
add_library(A__hdrs INTERFACE)
target_include_directories(A__hdrs INTERFACE include)
----
`A__impl`:: containing the implementation of `A`. This target needs access to the headers of its dependent modules, e.g.,
+
[source, cmake]
----
add_library(A__impl A.c)
target_link_libraries(A__impl PRIVATE B__hdrs)
----
+
`A`:: providing access to public headers for consuming targets (e.g., executables) and transitively providing dependent library implementations
[source, cmake]
----
add_library(A INTERFACE)
target_link_libraries(A INTERFACE A__impl A__hdrs)
----

Currently, the `elastic_ai_add_library` function provides most of this functionality. However, using it will prevent the IDE from automatically discovering your targets for the sake of jump-to-definition and auto-completion.

=== Building HW Dependent Libs
The build scripts will set a global variable `BUILDING_FOR_ELASTIC_NODE` to `true` iff we're building for an elastic node hardware.
If you need to define a HW dependent lib, e.g., because it calls into the pico_sdk, you should ask for that flag and define the `__impl` as an empty interface target. E.g.,

[source, cmake]
----
if(BUILDING_FOR_ELASTIC_NODE)
add_library(A__impl A.c)
target_link_libraries(A__impl PRIVATE Pico::pico_runtime__hdrs)
else()
add_library(A__impl INTERFACE)
endif ()
----
Loading
Loading