From ab047190be34cbee9d43a85e47e97367bf014528 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 May 2022 08:39:16 +0200 Subject: [PATCH] update and apply afmt --- CMakeLists.txt | 98 +++++++++++----------------- bsp_hosted/CMakeLists.txt | 10 +-- bsp_hosted/core/CMakeLists.txt | 6 +- bsp_hosted/core/ObjectFactory.cpp | 4 +- bsp_hosted/fsfwconfig/CMakeLists.txt | 21 ++---- bsp_hosted/utility/CMakeLists.txt | 8 +-- example_common | 2 +- fsfw | 2 +- scripts/apply-clang-format.sh | 7 -- scripts/auto-formatter.sh | 32 +++++++++ 10 files changed, 83 insertions(+), 107 deletions(-) delete mode 100755 scripts/apply-clang-format.sh create mode 100755 scripts/auto-formatter.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index ea5acc1..bad47a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,14 @@ -################################################################################ +# ############################################################################## # CMake support for the Flight Software Framework -# +# # Developed in an effort to replace Make with a modern build system. -# +# # Author: R. Mueller -################################################################################ +# ############################################################################## -################################################################################ +# ############################################################################## # Pre-Project preparation -################################################################################ +# ############################################################################## cmake_minimum_required(VERSION 3.13) # set(CMAKE_VERBOSE TRUE) @@ -16,7 +16,9 @@ cmake_minimum_required(VERSION 3.13) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") if(NOT FSFW_OSAL) - set(FSFW_OSAL host CACHE STRING "OS for the FSFW.") + set(FSFW_OSAL + host + CACHE STRING "OS for the FSFW.") endif() # Project Name @@ -28,9 +30,9 @@ if(OBSW_ENABLE_IPO) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif() -################################################################################ +# ############################################################################## # Pre-Sources preparation -################################################################################ +# ############################################################################## # Specify the C++ standard set(CMAKE_CXX_STANDARD 17) @@ -50,11 +52,8 @@ set(BSP_PATH "bsp_hosted") set(COMMON_CONFIG_PATH "${COMMON_PATH}/config") set(FSFW_CONFIG_PATH "${BSP_PATH}/fsfwconfig") set(FSFW_ADDITIONAL_INC_PATHS - "${COMMON_CONFIG_PATH}" - "${CMAKE_CURRENT_BINARY_DIR}" - CACHE STRING - "FSFW configuration paths" - ) + "${COMMON_CONFIG_PATH}" "${CMAKE_CURRENT_BINARY_DIR}" + CACHE STRING "FSFW configuration paths") configure_file(${COMMON_CONFIG_PATH}/commonConfig.h.in commonConfig.h) configure_file(${FSFW_CONFIG_PATH}/FSFWConfig.h.in FSFWConfig.h) @@ -63,13 +62,8 @@ configure_file(${FSFW_CONFIG_PATH}/OBSWConfig.h.in OBSWConfig.h) set(FSFW_ADD_MONITORING ON) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(WARNING_FLAGS - -Wall - -Wextra - -Wimplicit-fallthrough=1 - -Wno-unused-parameter - -Wno-psabi - ) + set(WARNING_FLAGS -Wall -Wextra -Wimplicit-fallthrough=1 + -Wno-unused-parameter -Wno-psabi) set(FSFW_WARNING_FLAGS ${WARNING_FLAGS}) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -84,15 +78,15 @@ if(FSFW_OSAL MATCHES linux) else() if(WIN32) + elseif(UNIX) find_package(Threads REQUIRED) endif() endif() - -################################################################################ +# ############################################################################## # Executable and Sources -################################################################################ +# ############################################################################## # Add executable add_executable(${TARGET_NAME}) @@ -105,52 +99,40 @@ add_subdirectory(${BSP_PATH}) add_subdirectory(${FSFW_PATH}) add_subdirectory(${COMMON_PATH}) -################################################################################ +# ############################################################################## # Post-Sources preparation -################################################################################ +# ############################################################################## # Add libraries for all sources. -target_link_libraries(${TARGET_NAME} PRIVATE - ${LIB_FSFW_NAME} - ${LIB_OS_NAME} - # ${LIB_FSFW_HAL_NAME} - ) +target_link_libraries( + ${TARGET_NAME} PRIVATE ${LIB_FSFW_NAME} ${LIB_OS_NAME} + # ${LIB_FSFW_HAL_NAME} +) # Add include paths for all sources. -target_include_directories(${TARGET_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${FSFW_CONFIG_PATH} - ) - +target_include_directories( + ${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ${FSFW_CONFIG_PATH}) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_options(${TARGET_NAME} PRIVATE - "-Wl,-Map=${TARGET_NAME}.map" - ) + target_link_options(${TARGET_NAME} PRIVATE "-Wl,-Map=${TARGET_NAME}.map") # Remove unused sections. - target_compile_options(${TARGET_NAME} PRIVATE - "-ffunction-sections" - "-fdata-sections" - ) + target_compile_options(${TARGET_NAME} PRIVATE "-ffunction-sections" + "-fdata-sections") # Removed unused sections. - target_link_options(${TARGET_NAME} PRIVATE - "-Wl,--gc-sections" - ) + target_link_options(${TARGET_NAME} PRIVATE "-Wl,--gc-sections") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + endif() if(CMAKE_VERBOSE) message(STATUS "Warning flags: ${WARNING_FLAGS}") endif() - # Compile options for all sources. -target_compile_options(${TARGET_NAME} PRIVATE - ${WARNING_FLAGS} - ) +target_compile_options(${TARGET_NAME} PRIVATE ${WARNING_FLAGS}) if(NOT CMAKE_SIZE) set(CMAKE_SIZE size) @@ -165,19 +147,15 @@ else() set(TARGET_STRING "Target BSP: Hosted") endif() -string(CONCAT POST_BUILD_COMMENT - "Build directory: ${CMAKE_BINARY_DIR}\n" - "Target OSAL: ${FSFW_OSAL}\n" - "Target Build Type: ${CMAKE_BUILD_TYPE}\n" - "${TARGET_STRING}" - ) +string(CONCAT POST_BUILD_COMMENT "Build directory: ${CMAKE_BINARY_DIR}\n" + "Target OSAL: ${FSFW_OSAL}\n" + "Target Build Type: ${CMAKE_BUILD_TYPE}\n" "${TARGET_STRING}") add_custom_command( TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_SIZE} ${TARGET_NAME}${FILE_SUFFIX} - COMMENT ${POST_BUILD_COMMENT} -) + COMMENT ${POST_BUILD_COMMENT}) -include (BuildType) +include(BuildType) set_build_type() diff --git a/bsp_hosted/CMakeLists.txt b/bsp_hosted/CMakeLists.txt index cbb6c79..920f297 100644 --- a/bsp_hosted/CMakeLists.txt +++ b/bsp_hosted/CMakeLists.txt @@ -1,13 +1,7 @@ -target_sources(${TARGET_NAME} - PRIVATE - main.cpp -) +target_sources(${TARGET_NAME} PRIVATE main.cpp) add_subdirectory(core) add_subdirectory(fsfwconfig) add_subdirectory(utility) -target_include_directories(${TARGET_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) \ No newline at end of file +target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/bsp_hosted/core/CMakeLists.txt b/bsp_hosted/core/CMakeLists.txt index 2b124ba..5edc79a 100644 --- a/bsp_hosted/core/CMakeLists.txt +++ b/bsp_hosted/core/CMakeLists.txt @@ -1,5 +1 @@ -target_sources(${TARGET_NAME} - PRIVATE - InitMission.cpp - ObjectFactory.cpp -) \ No newline at end of file +target_sources(${TARGET_NAME} PRIVATE InitMission.cpp ObjectFactory.cpp) diff --git a/bsp_hosted/core/ObjectFactory.cpp b/bsp_hosted/core/ObjectFactory.cpp index 0052aa6..33569f5 100644 --- a/bsp_hosted/core/ObjectFactory.cpp +++ b/bsp_hosted/core/ObjectFactory.cpp @@ -25,7 +25,7 @@ void ObjectFactory::produce(void* args) { Factory::setStaticFrameworkObjectIds(); - + ObjectFactory::produceGenericObjects(); #if OBSW_ADD_CORE_COMPONENTS == 1 { LocalPool::LocalPoolConfig poolCfg = {{16, 100}, {32, 50}, {64, 25}, {128, 15}, {1024, 5}}; @@ -62,6 +62,4 @@ void ObjectFactory::produce(void* args) { periodicEvent = true; #endif new FsfwTestTask(objects::TEST_TASK, periodicEvent); - - ObjectFactory::produceGenericObjects(); } diff --git a/bsp_hosted/fsfwconfig/CMakeLists.txt b/bsp_hosted/fsfwconfig/CMakeLists.txt index c336e10..f7a2d9e 100644 --- a/bsp_hosted/fsfwconfig/CMakeLists.txt +++ b/bsp_hosted/fsfwconfig/CMakeLists.txt @@ -1,25 +1,16 @@ -target_sources(${TARGET_NAME} - PRIVATE - ipc/missionMessageTypes.cpp - pollingsequence/pollingSequenceFactory.cpp -) +target_sources( + ${TARGET_NAME} PRIVATE ipc/missionMessageTypes.cpp + pollingsequence/pollingSequenceFactory.cpp) # Add include paths for the executable -target_include_directories(${TARGET_NAME} - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} -) +target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) # If a special translation file for object IDs exists, compile it. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") - target_sources(${TARGET_NAME} PRIVATE - objects/translateObjects.cpp - ) + target_sources(${TARGET_NAME} PRIVATE objects/translateObjects.cpp) endif() # If a special translation file for events exists, compile it. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/objects/translateObjects.cpp") - target_sources(${TARGET_NAME} PRIVATE - events/translateEvents.cpp - ) + target_sources(${TARGET_NAME} PRIVATE events/translateEvents.cpp) endif() diff --git a/bsp_hosted/utility/CMakeLists.txt b/bsp_hosted/utility/CMakeLists.txt index 721ba1c..71740d3 100644 --- a/bsp_hosted/utility/CMakeLists.txt +++ b/bsp_hosted/utility/CMakeLists.txt @@ -1,7 +1 @@ -target_sources(${TARGET_NAME} - PUBLIC - printChar.c -) - - - +target_sources(${TARGET_NAME} PUBLIC printChar.c) diff --git a/example_common b/example_common index e1aa39f..21e9987 160000 --- a/example_common +++ b/example_common @@ -1 +1 @@ -Subproject commit e1aa39f5e4ccd7dc5694e2f5bffb5e3161778097 +Subproject commit 21e998763671026bcc53e1df26acdd40e6589fd5 diff --git a/fsfw b/fsfw index 5764144..d0fc360 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 576414438c81b43d18ac0472c4baa8bc545f8d3f +Subproject commit d0fc360697e0fae7ccb4b827b8bc3d0398c342bc diff --git a/scripts/apply-clang-format.sh b/scripts/apply-clang-format.sh deleted file mode 100755 index 5079a70..0000000 --- a/scripts/apply-clang-format.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -if [[ ! -f README.md ]]; then - cd .. -fi - -find ./bsp_hosted -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i -find ./example_common -iname *.h -o -iname *.cpp -o -iname *.c | xargs clang-format --style=file -i diff --git a/scripts/auto-formatter.sh b/scripts/auto-formatter.sh new file mode 100755 index 0000000..d9b970e --- /dev/null +++ b/scripts/auto-formatter.sh @@ -0,0 +1,32 @@ +#!/bin/bash +if [[ ! -f README.md ]]; then + cd .. +fi + +folder_list=( + "./bsp_hosted" + "./example_common" +) + +cmake_fmt="cmake-format" +file_selectors="-iname CMakeLists.txt" +if command -v ${cmake_fmt} &> /dev/null; then + echo "Auto-formatting all CMakeLists.txt files" + ${cmake_fmt} -i CMakeLists.txt + for dir in ${folder_list[@]}; do + find ${dir} ${file_selectors} | xargs ${cmake_fmt} -i + done +else + echo "No ${cmake_fmt} tool found, not formatting CMake files" +fi + +cpp_format="clang-format" +file_selectors="-iname *.h -o -iname *.cpp -o -iname *.c -o -iname *.tpp" +if command -v ${cpp_format} &> /dev/null; then + for dir in ${folder_list[@]}; do + echo "Auto-formatting C/C++ files in ${dir} recursively" + find ${dir} ${file_selectors} | xargs ${cpp_format} --style=file -i + done +else + echo "No ${cpp_format} tool found, not formatting C++/C files" +fi