From cb50428fd33726ea430cb4998903235dfc5a1d82 Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 14 Dec 2022 13:18:40 +0100 Subject: [PATCH] :loud_sound: (cmake): ut - print out flags, options, definitions when configuring --- CMakeLists.txt | 12 +---- cmake/utils/Utils.cmake | 93 +++++++++++++++++++++++++++++++++++++++ tests/unit/CMakeLists.txt | 23 +++++++--- 3 files changed, 110 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5aecf7fd4..4594174064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,9 +148,6 @@ add_subdirectory(${BOOTLOADER_DIR}) # Add LekaOS add_subdirectory(${OS_DIR}) -# Finally print the mbed-cmake build report -mbed_cmake_print_build_report() - # # MARK: - Misc. options # @@ -160,11 +157,4 @@ if(VERBOSE_BUILD) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -# Print options -message(STATUS "") -message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS --> ${CMAKE_EXPORT_COMPILE_COMMANDS}") -message(STATUS "ENABLE_LOG_DEBUG --> ${ENABLE_LOG_DEBUG}") -message(STATUS "ENABLE_SYSTEM_STATS --> ${ENABLE_SYSTEM_STATS}") -message(STATUS "BUILD_TARGETS_FOR_BOOTLOADER --> ${BUILD_TARGETS_TO_USE_WITH_BOOTLOADER}") -message(STATUS "CMAKE_VERBOSE_MAKEFILE --> ${VERBOSE_BUILD}") -message(STATUS "") +print_compilers_flags_options_definitions() diff --git a/cmake/utils/Utils.cmake b/cmake/utils/Utils.cmake index b03709de1c..3d766db090 100644 --- a/cmake/utils/Utils.cmake +++ b/cmake/utils/Utils.cmake @@ -121,3 +121,96 @@ function(target_link_custom_leka_targets TARGET) # endif() # endforeach() endfunction() + +function(print_compilers_flags_options_definitions) + set(LIST_PREFIX "\n-- ") + + function(output_flags FLAGS) + set(PROJECT_FLAGS ${${FLAGS}}) + string(REPLACE " " "${LIST_PREFIX}" PROJECT_FLAGS "${PROJECT_FLAGS}") + + if(NOT PROJECT_FLAGS STREQUAL "") + message(STATUS "${FLAGS} (Global):${LIST_PREFIX}${PROJECT_FLAGS}") + else() + message(STATUS "${FLAGS} (Global): (empty)") + endif(NOT PROJECT_FLAGS STREQUAL "") + + message(STATUS "") + + set(PROJECT_FLAGS_BUILD_TYPE ${${FLAGS}_${CMAKE_BUILD_TYPE_UPPERCASE}}) + string(REPLACE " " "${LIST_PREFIX}" PROJECT_FLAGS_BUILD_TYPE "${PROJECT_FLAGS_BUILD_TYPE}") + + # message(STATUS "${FLAGS} (For ${CMAKE_BUILD_TYPE}):${LIST_PREFIX}${PROJECT_FLAGS_BUILD_TYPE}") + if(NOT PROJECT_FLAGS_BUILD_TYPE STREQUAL "") + message(STATUS "${FLAGS} (${CMAKE_BUILD_TYPE}):${LIST_PREFIX}${PROJECT_FLAGS_BUILD_TYPE}") + else() + message(STATUS "${FLAGS} (${CMAKE_BUILD_TYPE}): (empty)") + endif(NOT PROJECT_FLAGS_BUILD_TYPE STREQUAL "") + + message(STATUS "") + endfunction(output_flags) + + function(output_flags_build_type FLAGS) + set(PROJECT_FLAGS ${${FLAGS}}) + string(REPLACE " " "${LIST_PREFIX}" PROJECT_FLAGS "${PROJECT_FLAGS}") + message(STATUS "${FLAGS} (Global):${LIST_PREFIX}${PROJECT_FLAGS}") + message(STATUS "") + endfunction(output_flags_build_type) + + function(output_options_definitions OPTIONS_DEFINITIONS) + get_property(PROJECT_${OPTIONS_DEFINITIONS} DIRECTORY PROPERTY ${OPTIONS_DEFINITIONS}) + string(REPLACE ";" "${LIST_PREFIX}" PROJECT_${OPTIONS_DEFINITIONS} "${PROJECT_${OPTIONS_DEFINITIONS}}") + + if(NOT PROJECT_${OPTIONS_DEFINITIONS} STREQUAL "") + message(STATUS "${OPTIONS_DEFINITIONS}:${LIST_PREFIX}${PROJECT_${OPTIONS_DEFINITIONS}}") + else() + message(STATUS "${OPTIONS_DEFINITIONS}: (empty)") + endif(NOT PROJECT_${OPTIONS_DEFINITIONS} STREQUAL "") + + message(STATUS "") + endfunction(output_options_definitions FLAGS_OPTIONS_DEFINITIONS) + + string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPERCASE) + + message(STATUS "") + message(STATUS ">> ") + message(STATUS ">> Build type & compilers") + message(STATUS ">> ") + message(STATUS "") + + message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") + message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") + + message(STATUS "") + message(STATUS ">> ") + message(STATUS ">> C/C++ flags") + message(STATUS ">> ") + message(STATUS "") + + output_flags(CMAKE_C_FLAGS) + + output_flags(CMAKE_CXX_FLAGS) + + output_flags(CMAKE_EXE_LINKER_FLAGS) + + message(STATUS ">> ") + message(STATUS ">> Compile & link options/definitions") + message(STATUS ">> ") + message(STATUS "") + + output_options_definitions(COMPILE_OPTIONS) + output_options_definitions(LINK_OPTIONS) + output_options_definitions(COMPILE_DEFINITIONS) + output_options_definitions(LINK_DEFINITIONS) + + message(STATUS ">> ") + message(STATUS ">> CMake options") + message(STATUS ">> ") + message(STATUS "") + + message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS --> ${CMAKE_EXPORT_COMPILE_COMMANDS}") + message(STATUS "CMAKE_VERBOSE_MAKEFILE --> ${CMAKE_VERBOSE_MAKEFILE}") + + message(STATUS "") +endfunction() diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 310f1b7b3a..418f27f652 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -129,6 +129,13 @@ set(LIBS_DIR ${ROOT_DIR}/libs) set(DRIVERS_DIR ${ROOT_DIR}/drivers) set(INCLUDE_DIR ${ROOT_DIR}/include) +# +# MARK: - External tools +# +list(APPEND CMAKE_MODULE_PATH ${ROOT_DIR}/cmake/utils) + +include(Utils) + # # Mark: - Add GoogleTest & GMock # @@ -317,12 +324,14 @@ if(VERBOSE_BUILD) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -# Print options +print_compilers_flags_options_definitions() + +message(STATUS ">> ") +message(STATUS ">> External definitions") +message(STATUS ">> ") message(STATUS "") -message(STATUS "CMAKE_CXX_COMPILER --> ${CMAKE_CXX_COMPILER}") -message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS --> ${CMAKE_EXPORT_COMPILE_COMMANDS}") -message(STATUS "UT LITE --> ${UT_LITE}") -message(STATUS "CODE_COVERAGE --> ${COVERAGE}") -message(STATUS "SANITIZERS --> ${SANITIZERS}") -message(STATUS "CMAKE_VERBOSE_MAKEFILE --> ${VERBOSE_BUILD}") + +message(STATUS "UT LITE --> ${UT_LITE}") +message(STATUS "CODE_COVERAGE --> ${COVERAGE}") +message(STATUS "SANITIZERS --> ${SANITIZERS}") message(STATUS "")