Skip to content

Commit

Permalink
🔊 (cmake): ut - print out flags, options, definitions when configuring
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Dec 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent dc2299f commit cb50428
Showing 3 changed files with 110 additions and 18 deletions.
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
93 changes: 93 additions & 0 deletions cmake/utils/Utils.cmake
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 16 additions & 7 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "")

0 comments on commit cb50428

Please sign in to comment.