From defcd1206315707b44a726618599578e31ac5220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Betto?= <niccolo.betto@skywarder.eu> Date: Fri, 17 Nov 2023 11:31:44 +0100 Subject: [PATCH] [CMake] Build Boardcore targets with C++17 --- .vscode/c_cpp_properties.json | 36 ++++++++++++++-------------- cmake/boardcore.cmake | 6 +++++ cmake/sbs.cmake | 6 +++++ src/entrypoints/sdcard-benchmark.cpp | 14 +++++------ 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b16913f5d..bc6d48e74 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -24,7 +24,7 @@ { "name": "stm32f205rc_ciuti", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -46,7 +46,7 @@ { "name": "stm32f429zi_death_stack_v1", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -70,7 +70,7 @@ { "name": "stm32f429zi_death_stack_v2", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -93,7 +93,7 @@ { "name": "stm32f429zi_death_stack_v3", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -116,7 +116,7 @@ { "name": "stm32f429zi_nokia", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -139,7 +139,7 @@ { "name": "stm32f429zi_parafoil", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -162,7 +162,7 @@ { "name": "stm32f429zi_pyxis_auxiliary", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -184,7 +184,7 @@ { "name": "stm32f429zi_rig", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -207,7 +207,7 @@ { "name": "stm32f756zg_nucleo", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -230,7 +230,7 @@ { "name": "stm32f767zi_automated_antennas", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -253,7 +253,7 @@ { "name": "stm32f767zi_compute_unit", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -276,7 +276,7 @@ { "name": "stm32f767zi_death_stack_v4", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -299,7 +299,7 @@ { "name": "stm32f767zi_gemini_gs", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -322,7 +322,7 @@ { "name": "stm32f767zi_gemini_motor", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -346,7 +346,7 @@ { "name": "stm32f407vg_stm32f4discovery", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -368,7 +368,7 @@ { "name": "stm32f429zi_stm32f4discovery", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -391,7 +391,7 @@ { "name": "stm32f767zi_nucleo", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", @@ -414,7 +414,7 @@ { "name": "stm32f769ni_discovery", "cStandard": "c11", - "cppStandard": "c++14", + "cppStandard": "c++17", "compilerPath": "/opt/arm-miosix-eabi/bin/arm-miosix-eabi-g++", "defines": [ "${defaultDefines}", diff --git a/cmake/boardcore.cmake b/cmake/boardcore.cmake index b45ff0b53..4ea20df03 100644 --- a/cmake/boardcore.cmake +++ b/cmake/boardcore.cmake @@ -144,6 +144,12 @@ function(add_boardcore_library BOARD_OPTIONS_FILE) set(BOARDCORE_LIB boardcore-${BOARD_NAME}) add_library(${BOARDCORE_LIB} STATIC EXCLUDE_FROM_ALL ${BOARDCORE_SRC}) + # Set the C++ standard + set_target_properties(${BOARDCORE_LIB} PROPERTIES + CXX_STANDARD ${BOARDCORE_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON + ) + # Only one include directory for Boardcore! target_include_directories(${BOARDCORE_LIB} PUBLIC ${BOARDCORE_PATH}/src/shared) diff --git a/cmake/sbs.cmake b/cmake/sbs.cmake index 7cd5a66c2..90a1a87f1 100644 --- a/cmake/sbs.cmake +++ b/cmake/sbs.cmake @@ -20,6 +20,7 @@ # THE SOFTWARE. enable_language(C CXX ASM) +set(BOARDCORE_CXX_STANDARD 17) # Load in SBS_BASE the project path cmake_path(GET CMAKE_CURRENT_LIST_DIR PARENT_PATH SBS_BASE) @@ -43,6 +44,11 @@ function(sbs_target TARGET OPT_BOARD) message(FATAL_ERROR "No board selected") endif() + set_target_properties(${TARGET} PROPERTIES + CXX_STANDARD ${BOARDCORE_CXX_STANDARD} + CXX_STANDARD_REQUIRED ON + ) + # The only include directory of Boardcore is shared! target_include_directories(${TARGET} PRIVATE src/shared) diff --git a/src/entrypoints/sdcard-benchmark.cpp b/src/entrypoints/sdcard-benchmark.cpp index 9a54a3a63..140c31f39 100644 --- a/src/entrypoints/sdcard-benchmark.cpp +++ b/src/entrypoints/sdcard-benchmark.cpp @@ -33,15 +33,15 @@ using namespace Boardcore; using namespace miosix; -using namespace std; ///< Number of writes to perform for each buffer size const unsigned int NUM_WRITES = 1000; -vector<size_t> BUFFER_SIZES = {128, 256, 512, 1024, 2048, +std::vector<size_t> BUFFER_SIZES = {128, 256, 512, 1024, 2048, 4096, 8192, 16348, 32768, 65536}; -array<float, NUM_WRITES> data; +using result_array = std::array<float, NUM_WRITES>; +result_array data; /** * @brief Fills a buffer with random bytes. @@ -59,7 +59,7 @@ void rndFill(uint8_t* buf, size_t size); * @param results Array where to store the duration measured for each write. * @return True if no error encountered. */ -bool benchmark(size_t bufferSize, array<float, NUM_WRITES>& results); +bool benchmark(size_t bufferSize, result_array& results); /** * @brief Prints the test results for the specified buffer size. @@ -67,7 +67,7 @@ bool benchmark(size_t bufferSize, array<float, NUM_WRITES>& results); * @param bufferSize Buffer size of the benchmark. * @param results Results form the benchmark. */ -void printResults(size_t bufferSize, array<float, NUM_WRITES>& results); +void printResults(size_t bufferSize, result_array& results); int main() { @@ -94,7 +94,7 @@ void rndFill(uint8_t* buf, size_t size) buf[i] = rand() % 256; } -bool benchmark(size_t bufferSize, array<float, NUM_WRITES>& results) +bool benchmark(size_t bufferSize, result_array& results) { uint8_t* buffer = new uint8_t[bufferSize]; @@ -138,7 +138,7 @@ bool benchmark(size_t bufferSize, array<float, NUM_WRITES>& results) return true; } -void printResults(size_t bufferSize, array<float, NUM_WRITES>& results) +void printResults(size_t bufferSize, result_array& results) { // Compute statistics on the benchmark results Stats stats; -- GitLab