Skip to content

Commit

Permalink
Coverage feature improvements and maintenance stuff: (#94)
Browse files Browse the repository at this point in the history
* Coverage feature improvements and maintenance stuff:
- coverage flags now only affect coverage targets.
- coverage report filters are now aggregated from coverage target include and sources by default if not explicitly specified by user
- refactored coverage setup functions into single function: `hdk_setup_gcovr_coverage_target`
- corrected a few invalid variable references
- added `include_guard` directives to core modules.
- converted several message() calls to hdk_log_* calls
- make_component and make_target will now warn user if function call has stray (unknown) arguments
- make_component now behaves smarter on detecting ALL_ prefixed variables
- make_component no longer forwards TRUE together with option type variables
- added hdk_fnlog_* log functions which prints source function and file name of call source together with message
- added hdk_function_required_arguments helper function which makes function arguments REQUIRED
- added hdk_parameter_defaul_value helper function to provide default values for optional arguments of functions
- added hdk_unset_if_empty helper function which unsets a variable if its' content is equal to an empty string

* Small cosmetic improvements for buildvariant
  • Loading branch information
Mustafa Kemal GILOR authored Nov 26, 2021
1 parent d7ea02d commit 7d0447f
Show file tree
Hide file tree
Showing 33 changed files with 392 additions and 320 deletions.
5 changes: 5 additions & 0 deletions cmake/modules/core/BuildVariant.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

include(CMakeDetermineCCompiler)
include(CMakeDetermineCXXCompiler)

Expand Down Expand Up @@ -87,6 +89,9 @@ function(hdk_set_build_variant)
endforeach()
endforeach()

string(STRIP "${WARN_BUT_NO_ERROR}" WARN_BUT_NO_ERROR)
string(STRIP "${EXTENDED_WARNINGS}" EXTENDED_WARNINGS)
string(STRIP "${EXCLUDED_WARNINGS}" EXCLUDED_WARNINGS)

if((CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) OR (CMAKE_BUILD_TYPE MATCHES Release))
if(NOT ${HDK_ROOT_PROJECT_NAME_UPPER}_HDK_NO_DEBUG_RELEASE_WARNING)
Expand Down
11 changes: 10 additions & 1 deletion cmake/modules/core/DiagnosticFlags_Clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@
set(CLANG_32_WARN_BUT_NO_ERROR "" )
set(CLANG_32_EXTENDED_WARNINGS "" )
set(CLANG_32_EXCLUDED_WARNINGS "-Wno-c++98-compat-pedantic -Wno-documentation -Wno-shadow -Wno-exit-time-destructors -Wno-global-constructors -Wno-braced-scalar-init" )
hdk_unset_if_empty(CLANG_32_WARN_BUT_NO_ERROR CLANG_32_EXTENDED_WARNINGS CLANG_32_EXCLUDED_WARNINGS)

# Clang 3.4 and above
set(CLANG_34_WARN_BUT_NO_ERROR "" )
set(CLANG_34_EXTENDED_WARNINGS "" )
set(CLANG_34_EXCLUDED_WARNINGS "-Wno-newline-eof" )
hdk_unset_if_empty(CLANG_34_WARN_BUT_NO_ERROR CLANG_34_EXTENDED_WARNINGS CLANG_34_EXCLUDED_WARNINGS)


# Clang 3.5 and above
set(CLANG_35_WARN_BUT_NO_ERROR "" )
set(CLANG_35_EXTENDED_WARNINGS "" )
set(CLANG_35_EXCLUDED_WARNINGS "-Wno-unreachable-code-return" )
hdk_unset_if_empty(CLANG_35_WARN_BUT_NO_ERROR CLANG_35_EXTENDED_WARNINGS CLANG_35_EXCLUDED_WARNINGS)


# Clang 3.9 and above
set(CLANG_39_WARN_BUT_NO_ERROR "" )
set(CLANG_39_EXTENDED_WARNINGS "" )
set(CLANG_39_EXCLUDED_WARNINGS "-Wno-shadow-field-in-constructor" )
set(CLANG_39_EXCLUDED_WARNINGS "-Wno-shadow-field-in-constructor" )
hdk_unset_if_empty(CLANG_39_WARN_BUT_NO_ERROR CLANG_39_EXTENDED_WARNINGS CLANG_39_EXCLUDED_WARNINGS)



16 changes: 16 additions & 0 deletions cmake/modules/core/DiagnosticFlags_GCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
set(GCC_34_WARN_BUT_NO_ERROR "-Wold-style-cast -Wmissing-noreturn" )
set(GCC_34_EXTENDED_WARNINGS "-Wformat=2 -Wcast-qual" )
set(GCC_34_EXCLUDED_WARNINGS "-Wno-unknown-pragmas -Wno-switch -Wno-unused-function" )
hdk_unset_if_empty(GCC_34_WARN_BUT_NO_ERROR GCC_34_EXTENDED_WARNINGS GCC_34_EXCLUDED_WARNINGS)

########################################
# GCC 4.3 and above
Expand All @@ -88,11 +89,15 @@ set(GCC_34_EXCLUDED_WARNINGS "-Wno-unknown-pragmas -Wno-switch -Wno-unused-funct
set(GCC_43_WARN_BUT_NO_ERROR "-Wlogical-op" )
set(GCC_43_EXTENDED_WARNINGS "" )
set(GCC_43_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_43_WARN_BUT_NO_ERROR GCC_43_EXTENDED_WARNINGS GCC_43_EXCLUDED_WARNINGS)


# GCC 4.6 and above
set(GCC_46_WARN_BUT_NO_ERROR "-Wdouble-promotion -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn" )
set(GCC_46_EXTENDED_WARNINGS "" )
set(GCC_46_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_46_WARN_BUT_NO_ERROR GCC_46_EXTENDED_WARNINGS GCC_46_EXCLUDED_WARNINGS)


########################################
# GCC 4.8 and above
Expand All @@ -111,16 +116,22 @@ set(GCC_46_EXCLUDED_WARNINGS "" )
set(GCC_48_WARN_BUT_NO_ERROR "-Wold-style-cast -Wmissing-noreturn" )
set(GCC_48_EXTENDED_WARNINGS "-Wuseless-cast" )
set(GCC_48_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_48_WARN_BUT_NO_ERROR GCC_48_EXTENDED_WARNINGS GCC_48_EXCLUDED_WARNINGS)


# GCC 5.0 and above
set(GCC_50_WARN_BUT_NO_ERROR "-Wsuggest-override" )
set(GCC_50_EXTENDED_WARNINGS "" )
set(GCC_50_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_50_WARN_BUT_NO_ERROR GCC_50_EXTENDED_WARNINGS GCC_50_EXCLUDED_WARNINGS)


# GCC 5.1 and above
set(GCC_51_WARN_BUT_NO_ERROR "-Wsuggest-final-methods -Wsuggest-final-types")
set(GCC_51_EXTENDED_WARNINGS "" )
set(GCC_51_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_51_WARN_BUT_NO_ERROR GCC_51_EXTENDED_WARNINGS GCC_51_EXCLUDED_WARNINGS)


########################################
# GCC 6.0 and above
Expand All @@ -142,6 +153,8 @@ set(GCC_51_EXCLUDED_WARNINGS "" )
set(GCC_60_WARN_BUT_NO_ERROR "" )
set(GCC_60_EXTENDED_WARNINGS "-Wduplicated-cond -Wnull-dereference")
set(GCC_60_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_60_WARN_BUT_NO_ERROR GCC_60_EXTENDED_WARNINGS GCC_60_EXCLUDED_WARNINGS)


########################################
# GCC 7.0 and above
Expand All @@ -156,9 +169,12 @@ set(GCC_60_EXCLUDED_WARNINGS "" )
set(GCC_70_WARN_BUT_NO_ERROR "" )
set(GCC_70_EXTENDED_WARNINGS "-Wduplicated-branches" )
set(GCC_70_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_70_WARN_BUT_NO_ERROR GCC_70_EXTENDED_WARNINGS GCC_70_EXCLUDED_WARNINGS)


# GCC 8.0 and above
set(GCC_80_WARN_BUT_NO_ERROR "-Wsuggest-attribute=malloc" )
set(GCC_80_EXTENDED_WARNINGS "" )
set(GCC_80_EXCLUDED_WARNINGS "" )
hdk_unset_if_empty(GCC_80_WARN_BUT_NO_ERROR GCC_80_EXTENDED_WARNINGS GCC_80_EXCLUDED_WARNINGS)

2 changes: 2 additions & 0 deletions cmake/modules/core/FetchConanPackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

function(hdk_fetch_conan_package PACKAGE_NAME PACKAGE_VERSION PROFILE_FILE)
hdk_log_set_context("hdk.fcp")
# Required conan package and package version, set if not specified
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/core/HardwareConcurrency.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

include(ProcessorCount)
ProcessorCount(HARDWARE_CONCURRENCY)
2 changes: 2 additions & 0 deletions cmake/modules/core/MakeCompilationUnit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

# Gather all files under `include` and `src` folders at current directory level
# to `COMPILATION_UNIT` variable in invocation scope.
function(hdk_make_compilation_unit COMPILATION_UNIT)
Expand Down
62 changes: 40 additions & 22 deletions cmake/modules/core/MakeComponent.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

include(.hadouken/cmake/modules/core/MakeTarget.cmake)

Expand Down Expand Up @@ -70,11 +71,11 @@ function(make_component COMPONENT_NAME)
cmake_parse_arguments(MAKE_COMPONENT_ARGS "${__HDK_MAKE_COMPONENT_OPTION_ARGS}" "${__HDK_MAKE_COMPONENT_SINGLE_VALUE_ARGS}" "${__HDK_MAKE_COMPONENT_MULTI_VALUE_ARGS}" ${ARGN})

if(NOT DEFINED COMPONENT_NAME)
message(FATAL_ERROR "make_component() requires COMPONENT_NAME parameter to be present.")
endif()
hdk_log_err("make_component() requires COMPONENT_NAME parameter to be present")
endif()

if(NOT DEFINED MAKE_COMPONENT_ARGS_TARGET)
message(FATAL_ERROR "make_component() requires at least one TARGET parameter.")
hdk_log_err("make_component() [${MAKE_COMPONENT_ARGS_COMPONENT_NAME}]: make_component() requires at least one TARGET parameter")
endif()

if(NOT DEFINED MAKE_COMPONENT_ARGS_VERSION)
Expand Down Expand Up @@ -109,6 +110,10 @@ function(make_component COMPONENT_NAME)
endif()
endif()

if(DEFINED MAKE_COMPONENT_ARGS_UNPARSED_ARGUMENTS)
hdk_log_warn("make_component: Component ${COMPONENT_NAME} has stray arguments: ${MAKE_COMPONENT_ARGS_UNPARSED_ARGUMENTS}")
endif()

hdk_capsan_name(COMPONENT_NAME COMPONENT_NAME_UPPER)

if(${HDK_ROOT_PROJECT_NAME_UPPER}_WITHOUT_${COMPONENT_NAME_UPPER})
Expand All @@ -126,28 +131,41 @@ function(make_component COMPONENT_NAME)

hdk_log_trace("make_component: created project ${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_DESCRIPTION} ${PROJECT_HOMEPAGE_URL} ${PROJECT_LANGUAGES}")

# The code below iterates all defined variables in this context and filters out
# the ones starting with MAKE_COMPONENT_ARGS_ALL_
# I know, it is not clean but AFAIK there is no clean way to do this.

####################################################################################
# Aggregate common arguments into the list
set(ALL_TARGET_PARAMETERS "")
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
hdk_log_trace("make_component: Checking variable ${_variableName}=${${_variableName}} to common variables list")
if(_variableName MATCHES "^MAKE_COMPONENT_ARGS_ALL_.*")
string(REPLACE "MAKE_COMPONENT_ARGS_ALL_" "" NEW_VAR_NAME ${_variableName})
# (mgilor): This is a little hack to omit booleans
# with false values. Their presence in argument list
# interpreted as true when forwarded, even though
# their value is FALSE. So, we have to filter them out.
if(NOT "${${_variableName}}" STREQUAL "FALSE")
hdk_log_verbose("make_component: Added ${NEW_VAR_NAME}=${${_variableName}} to common variables list")
list(APPEND ALL_TARGET_PARAMETERS ${NEW_VAR_NAME})
list(APPEND ALL_TARGET_PARAMETERS ${${_variableName}})
endif()

# Iterate over all available non-option make_target() parameter names
foreach (_variableName IN LISTS __HDK_MAKE_TARGET_SINGLE_VALUE_ARGS __HDK_MAKE_TARGET_MULTI_VALUE_ARGS)
hdk_log_verbose("make_component: Checking variable ${_variableName}")
# Check if argument is present
if(NOT DEFINED MAKE_COMPONENT_ARGS_ALL_${_variableName})
continue()
endif()
string(REPLACE "MAKE_COMPONENT_ARGS_ALL_" "" NEW_VAR_NAME ${_variableName})
hdk_log_verbose("make_component: found defined ALL argument -> MAKE_COMPONENT_ARGS_ALL_${_variableName} : ${MAKE_COMPONENT_ARGS_ALL_${_variableName}} : resulting var name ${NEW_VAR_NAME}")
list(APPEND ALL_TARGET_PARAMETERS ${NEW_VAR_NAME})
list(APPEND ALL_TARGET_PARAMETERS ${MAKE_COMPONENT_ARGS_ALL_${_variableName}})
endforeach()

# Iterate over all available option make_target() parameter names
foreach (_variableName IN LISTS __HDK_MAKE_TARGET_OPTION_ARGS)
hdk_log_verbose("make_component: Checking variable ${_variableName}")
# Check if argument is present
if(NOT DEFINED MAKE_COMPONENT_ARGS_ALL_${_variableName})
continue()
endif()

string(REPLACE "MAKE_COMPONENT_ARGS_ALL_" "" NEW_VAR_NAME ${_variableName})
hdk_log_verbose("make_component: found defined ALL argument -> MAKE_COMPONENT_ARGS_ALL_${_variableName} : ${MAKE_COMPONENT_ARGS_ALL_${_variableName}} : resulting var name ${NEW_VAR_NAME}")
# (mgilor): This is a little hack to omit booleans
# with false values. Their presence in argument list
# interpreted as true when forwarded, even though
# their value is FALSE. So, we have to filter them out.
if(NOT "${MAKE_COMPONENT_ARGS_ALL_${_variableName}}" STREQUAL "FALSE")
hdk_log_verbose("make_component: Added ${NEW_VAR_NAME}=${MAKE_COMPONENT_ARGS_ALL_${_variableName}} option common variables list")
list(APPEND ALL_TARGET_PARAMETERS ${NEW_VAR_NAME})
# (mgilor): Option parameters require no value, so value is omitted here
endif()
endforeach()
####################################################################################
Expand Down
Empty file.
17 changes: 16 additions & 1 deletion cmake/modules/core/MakeTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

# make_targe function arguments
set(__HDK_MAKE_TARGET_OPTION_ARGS "WITH_COVERAGE;WITH_INSTALL;EXPOSE_PROJECT_METADATA;NO_AUTO_COMPILATION_UNIT;DEBUG_PRINT_PROPERTIES;AUTO_SUFFIX")
set(__HDK_MAKE_TARGET_SINGLE_VALUE_ARGS "TYPE;SUFFIX;PREFIX;NAME;OUTPUT_NAME;PARTOF;PROJECT_METADATA_PREFIX;WORKING_DIRECTORY;COVERAGE_REPORT_OUTPUT_DIRECTORY;EXCLUDE_SOURCES;EXCLUDE_HEADERS")
Expand All @@ -32,6 +34,11 @@ include(.hadouken/cmake/modules/core/detail/helper_functions.cmake)
# We're doing pretty much the same stuff on all of our library targets.
function(make_target)
hdk_log_set_context("hdk.mt")

# foreach(Q RANGE 0 ${ARGC}-1)
# hdk_log_verbose("make_target() called with ${ARGV${Q}}")
# endforeach()

cmake_parse_arguments(ARGS "${__HDK_MAKE_TARGET_OPTION_ARGS}" "${__HDK_MAKE_TARGET_SINGLE_VALUE_ARGS}" "${__HDK_MAKE_TARGET_MULTI_VALUE_ARGS}" ${ARGN})

if(NOT DEFINED ARGS_TYPE)
Expand Down Expand Up @@ -78,6 +85,10 @@ function(make_target)
return ()
endif()

if(DEFINED ARGS_UNPARSED_ARGUMENTS)
hdk_log_warn("make_target: Target ${TARGET_NAME} has stray arguments: ${ARGS_UNPARSED_ARGUMENTS}")
endif()

if(NOT ARGS_NO_AUTO_COMPILATION_UNIT OR NOT ${ARGS_NO_AUTO_COMPILATION_UNIT})
# Gather sources of target to be created
hdk_make_compilation_unit(COMPILATION_UNIT
Expand Down Expand Up @@ -139,7 +150,11 @@ function(make_target)

# WITH_COVERAGE is only meaningful for unit test and benchmark target types
if(NOT ${ARGS_TYPE} STREQUAL "UNIT_TEST" AND NOT ${ARGS_TYPE} STREQUAL "BENCHMARK")
message(FATAL_ERROR "WITH_COVERAGE can only be used together with UNIT_TEST and BENCHMARK targets.")
hdk_fnlog_err("make_target() [${TARGET_NAME}]]: WITH_COVERAGE can only be used together with UNIT_TEST and BENCHMARK targets.")
endif()

if(NOT DEFINED ARGS_COVERAGE_TARGETS)
hdk_fnlog_err("make_target() [${TARGET_NAME}]: WITH_COVERAGE requires at least one COVERAGE_TARGET")
endif()

__hdk_setup_coverage_targets(
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/core/ProjectMetadataExposure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

#[=======================================================================[.rst:
hdk_project_metadata_as_compile_defn
-------------------
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/core/TargetProperties.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

# Get all propreties that cmake supports
execute_process(COMMAND ${CMAKE_COMMAND} --help-property-list OUTPUT_VARIABLE CMAKE_PROPERTY_LIST)

Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/core/TargetUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# SPDX-License-Identifier: Apache 2.0
# ______________________________________________________

include_guard(DIRECTORY)

function(hdk_copy_target_artifact_to)
cmake_parse_arguments(ARGS "" "TARGET_NAME;DESTINATION;STEP;" "" ${ARGN} )
Expand All @@ -23,7 +24,6 @@ function(hdk_copy_target_artifact_to)
message(FATAL_ERROR "hdk_copy_target_artifact_to() requires TARGET_NAME parameter.")
endif()


if(NOT DEFINED ARGS_STEP)
message(FATAL_ERROR "hdk_copy_target_artifact_to() requires ARGS_STEP parameter.")
endif()
Expand Down
Loading

0 comments on commit 7d0447f

Please sign in to comment.