Skip to content

Commit

Permalink
Merge pull request #9 from Sherif-MoOo/std_libs
Browse files Browse the repository at this point in the history
Enhance CMake Configurations, Toolchain Logging, and ara::core::Array Implementation for Adaptive AUTOSAR for ISO compliance
  • Loading branch information
Sherif-MoOo authored Dec 27, 2024
2 parents f8fb2b3 + f72c5d8 commit a006db5
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 50 deletions.
149 changes: 146 additions & 3 deletions CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,29 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
# -Wconversion: Warn for implicit type conversions that may alter a value.
# -pedantic: Enforce strict ISO compliance.
# -Wshadow: Warn when a variable shadows another variable.
#
# Added Flags:
# -Werror: Treat all warnings as errors.
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
# -Wredundant-decls: Warn about redundant declarations.
# -Wcast-align: Warn about potentially unsafe alignment casts.
# -Wformat=2: Check printf/scanf format strings.
# -Wfloat-equal: Warn if floating-point values are used in equality comparisons.
# -fno-common: Prevent multiple definitions.
# -march=native: Optimize for the local machine architecture.
# -flto: Enable Link Time Optimization.
# -fstack-protector-strong: Enable stack protection.
# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows.
#=======================================================================
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations -v" CACHE STRING "Initial C++ Compiler Flags")
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
-Wcast-align -Wformat=2 -Wfloat-equal \
-fno-common -march=native -flto -fstack-protector-strong \
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags")

#-----------------------------------------------------------------------
# Build-Type Specific C Flags
Expand All @@ -84,6 +105,7 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG" CACHE STRING "C Compiler
set(CMAKE_C_FLAGS_ALSAN_INIT "-fsanitize=address -fno-omit-frame-pointer" CACHE STRING "C Compiler Flags for Address Sanitizer")
set(CMAKE_C_FLAGS_TSAN_INIT "-fsanitize=thread" CACHE STRING "C Compiler Flags for Thread Sanitizer")
set(CMAKE_C_FLAGS_UBSAN_INIT "-fsanitize=undefined" CACHE STRING "C Compiler Flags for Undefined Behavior Sanitizer")
set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Flags for ReleaseWithO2")

#=======================================================================
# Compiler Configuration for C++
Expand All @@ -99,8 +121,34 @@ set(CMAKE_C_FLAGS_UBSAN_INIT "-fsanitize=undefined" CACHE STRING "C Compiler Fla
# -Wold-style-cast: Warn about C-style casts.
# -pedantic: Enforce strict ISO compliance.
# -Wshadow: Warn when a variable shadows another variable.
# -Wno-error=deprecated-declarations: Do not treat deprecated declarations as errors.
# -v: Verbose output during compilation.
#
# Added Flags:
# -Werror: Treat all warnings as errors.
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
# -Wredundant-decls: Warn about redundant declarations.
# -Wcast-align: Warn about potentially unsafe alignment casts.
# -Wformat=2: Check printf/scanf format strings.
# -Wfloat-equal: Warn if floating-point values are used in equality comparisons.
# -fno-exceptions: Disable C++ exception handling.
# -fno-rtti: Disable Run-Time Type Information.
# -fno-common: Prevent multiple definitions.
# -march=native: Optimize for the local machine architecture.
# -flto: Enable Link Time Optimization.
# -fstack-protector-strong: Enable stack protection.
# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows.
#=======================================================================
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow" CACHE STRING "Initial C++ Compiler Flags")
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
-pedantic -Wshadow -Wno-error=deprecated-declarations -v \
-Werror -Wstrict-overflow=5 \
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
-Wcast-align -Wformat=2 -Wfloat-equal \
-fno-exceptions -fno-rtti -fno-common -march=native -flto -fstack-protector-strong \
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags")

#-----------------------------------------------------------------------
# Build-Type Specific C++ Flags
Expand Down Expand Up @@ -154,6 +202,101 @@ set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Executable Linker Flags
# Flags for RelWithDebInfo build: Include debug symbols.
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-g" CACHE STRING "Executable Linker Flags for RelWithDebInfo")

# Flags for ReleaseWithO2 build: No additional flags.
set(CMAKE_EXE_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Executable Linker Flags for ReleaseWithO2")

#=======================================================================
# Module Linker Flags
#=======================================================================
#
# Initial flags for the module linker applicable to all build types.
#=======================================================================
set(CMAKE_MODULE_LINKER_FLAGS_INIT "" CACHE STRING "Initial Module Linker Flags")

#-----------------------------------------------------------------------
# Build-Type Specific Module Linker Flags
#-----------------------------------------------------------------------
# Flags for Debug build: No additional flags.
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Module Linker Flags for Debug")

# Flags for MinSizeRel build: No additional flags.
set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Module Linker Flags for MinSizeRel")

# Flags for Release build: No additional flags.
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Module Linker Flags for Release")

# Flags for RelWithDebInfo build: No additional flags.
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Module Linker Flags for RelWithDebInfo")

# Flags for ReleaseWithO2 build: No additional flags.
set(CMAKE_MODULE_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Module Linker Flags for ReleaseWithO2")

#=======================================================================
# Shared Library Linker Flags
#=======================================================================
#
# Initial flags for the shared library linker applicable to all build types.
#=======================================================================
set(CMAKE_SHARED_LINKER_FLAGS_INIT "" CACHE STRING "Initial Shared Library Linker Flags")

#-----------------------------------------------------------------------
# Build-Type Specific Shared Library Linker Flags
#-----------------------------------------------------------------------
# Flags for Debug build: No additional flags.
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Shared Library Linker Flags for Debug")

# Flags for MinSizeRel build: No additional flags.
set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Shared Library Linker Flags for MinSizeRel")

# Flags for Release build: No additional flags.
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Shared Library Linker Flags for Release")

# Flags for RelWithDebInfo build: No additional flags.
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Shared Library Linker Flags for RelWithDebInfo")

# Flags for ReleaseWithO2 build: No additional flags.
set(CMAKE_SHARED_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Shared Library Linker Flags for ReleaseWithO2")

#=======================================================================
# Static Library Linker Flags
#=======================================================================
#
# Initial flags for the static library linker applicable to all build types.
#=======================================================================
set(CMAKE_STATIC_LINKER_FLAGS_INIT "" CACHE STRING "Initial Static Library Linker Flags")

#-----------------------------------------------------------------------
# Build-Type Specific Static Library Linker Flags
#-----------------------------------------------------------------------
# Flags for Debug build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Static Library Linker Flags for Debug")

# Flags for MinSizeRel build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Static Library Linker Flags for MinSizeRel")

# Flags for Release build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Static Library Linker Flags for Release")

# Flags for RelWithDebInfo build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Static Library Linker Flags for RelWithDebInfo")

# Flags for ReleaseWithO2 build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library Linker Flags for ReleaseWithO2")

#=======================================================================
# AUTOSAR Specific Compiler Flags
#=======================================================================
#
# AUTOSAR provides specific guidelines and macros. Depending on the GCC
# compiler support, you may need to define additional macros or flags.
#
# Example:
# -D_AUTOSAR=4.2.2: Define AUTOSAR version.
# -DAUTOSAR_COMPILATION: Enable AUTOSAR-specific compilation paths.
#=======================================================================
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C Compiler Flags with AUTOSAR")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C++ Compiler Flags with AUTOSAR")

#=======================================================================
# Additional CMake Settings
#=======================================================================
Expand All @@ -165,4 +308,4 @@ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-g" CACHE STRING "Executable Lin
# Example:
# set(SOME_PROJECT_VARIABLE "value" CACHE STRING "Description of the variable")
#
#=======================================================================
#=======================================================================
54 changes: 51 additions & 3 deletions CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,25 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
# -pedantic: Enforce strict ISO compliance.
# -Wshadow: Warn when a variable shadows another variable.
# -D_QNX_SOURCE: Define _QNX_SOURCE macro for QNX-specific features.
#
# Added Flags:
# -Werror: Treat all warnings as errors.
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
# -Wredundant-decls: Warn about redundant declarations.
# -Wcast-align: Warn about potentially unsafe alignment casts.
# -Wformat=2: Check printf/scanf format strings.
# -Wfloat-equal: Warn if floating point values are used in equality comparisons.
# -fno-common: Prevent multiple definitions.
# -mcpu=generic: Optimize for generic AArch64 architecture.
#=======================================================================
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow -D_QNX_SOURCE" CACHE STRING "Initial C Compiler Flags")
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow -D_QNX_SOURCE \
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
-Wcast-align -Wformat=2 -Wfloat-equal \
-fno-common -mcpu=generic" CACHE STRING "Initial C Compiler Flags")

#-----------------------------------------------------------------------
# Build-Type Specific C Flags
Expand Down Expand Up @@ -118,8 +135,26 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
# -Wno-error=deprecated-declarations: Do not treat deprecated declarations as errors.
# -v: Verbose output during compilation.
# -D_QNX_SOURCE: Define _QNX_SOURCE macro for QNX-specific features.
#
# Added Flags:
# -Werror: Treat all warnings as errors.
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
# -Wredundant-decls: Warn about redundant declarations.
# -Wcast-align: Warn about potentially unsafe alignment casts.
# -Wformat=2: Check printf/scanf format strings.
# -Wfloat-equal: Warn if floating point values are used in equality comparisons.
# -fno-exceptions: Disable C++ exception handling.
# -fno-rtti: Disable Run-Time Type Information.
# -mcpu=generic: Optimize for generic AArch64 architecture.
#=======================================================================
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations -v -D_QNX_SOURCE" CACHE STRING "Initial C++ Compiler Flags")
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
-pedantic -Wshadow -Wno-error=deprecated-declarations -v -D_QNX_SOURCE \
-Werror -Wstrict-overflow=5 \
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
-Wcast-align -Wformat=2 -Wfloat-equal \
-fno-exceptions -fno-rtti -mcpu=generic" CACHE STRING "Initial C++ Compiler Flags")

#-----------------------------------------------------------------------
# Build-Type Specific C++ Flags
Expand Down Expand Up @@ -254,6 +289,20 @@ set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Static Librar
# Flags for ReleaseWithO2 build: No additional flags.
set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library Linker Flags for ReleaseWithO2")

#=======================================================================
# AUTOSAR Specific Compiler Flags
#=======================================================================
#
# AUTOSAR provides specific guidelines and macros. Depending on the QCC
# compiler support, you may need to define additional macros or flags.
#
# Example:
# -D_AUTOSAR=4.2.2: Define AUTOSAR version.
# -DAUTOSAR_COMPILATION: Enable AUTOSAR-specific compilation paths.
#=======================================================================
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C Compiler Flags with AUTOSAR")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C++ Compiler Flags with AUTOSAR")

#=======================================================================
# Additional CMake Settings
#=======================================================================
Expand All @@ -266,4 +315,3 @@ set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library
# set(SOME_PROJECT_VARIABLE "value" CACHE STRING "Description of the variable")
#
#=======================================================================

20 changes: 17 additions & 3 deletions CMake/Toolchain/CMakeLogging/tool_chain_log_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ log_option("CACHE_ALL_FLAG_VARS")
log_option("ENABLE_COLOR")
log_option("SET_LINKER")

log_decorator("=============================================================")
log_decorator("-------------------------------------------------------------")

# ------------------------------------------------------------------------------
# 8) Optional: Dump ALL cache variables
Expand All @@ -292,5 +292,19 @@ if(VERBOSE_TOOLCHAIN_LOG)
get_property(_val CACHE "${_cv}" PROPERTY VALUE)
log_debug(" [${_cv}] = ${_val}")
endforeach()
log_decorator("=============================================================")
endif()
log_decorator("-------------------------------------------------------------")
endif()


# ------------------------------------------------------------------------------
# 13) Summary Report
# ------------------------------------------------------------------------------
log_decorator("=================== BUILD SUMMARY ===========================")

log_info("Build Type : ${CMAKE_BUILD_TYPE}")
log_info("C Compiler : ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_VERSION})")
log_info("C++ Compiler : ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_VERSION})")
log_info("Build Shared Libs : ${BUILD_SHARED_LIBS}")
log_info("Optimization Flags : ${CMAKE_C_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}")

log_decorator("=============================================================")
Loading

0 comments on commit a006db5

Please sign in to comment.