Skip to content

Commit

Permalink
General CMake cleanup (#635)
Browse files Browse the repository at this point in the history
* General CMake improvements

* Make extra warnings optional (for now)

* Remove section sorting

* Update functions.h for better inlining

* Fix formatting

---------

Co-authored-by: Paul Freund <[email protected]>
  • Loading branch information
stellar-aria and PaulFreund authored Oct 24, 2023
1 parent b03b7c8 commit c3f1d36
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Checks: >
clang-diagnostic-*,
clang-analyzer-*,
cppcoreguidelines-*,
cppcoreguidelines-*,
readability-*,
modernize-*,
bugprone-*,
llvm-include-order,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
Expand Down
2 changes: 1 addition & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CompileFlags:
Add: [-Wno-unknown-argument, -Wno-unknown-warning-option]
Remove: [-mthumb-interwork]
Remove: [-mthumb-interwork, -fanalyzer]
140 changes: 66 additions & 74 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ project(Deluge
include(ProcessorCount)
ProcessorCount(HOST_NUM_CORES)

# Check for IPO support
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT error)

if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION
$<$<CONFIG:DEBUG>:OFF>
$<$<CONFIG:RELWITHDEBINFO>:ON>
$<$<CONFIG:RELEASE>:ON>
)
endif()

# Create our version string
set(RELEASE_TYPE "dev" CACHE STRING "The type of releasepack to build")
set_property(CACHE RELEASE_TYPE PROPERTY STRINGS dev nightly alpha beta rc release)
Expand Down Expand Up @@ -80,66 +68,15 @@ else()
set(EXECUTABLE_VERSION_SUFFIX "")
endif(ENABLE_VERSIONED_OUTPUT)

# Global compilation options
add_compile_options(

# Feature flags
-fdiagnostics-parseable-fixits
-fsigned-char

# Debug symbols
$<$<CONFIG:DEBUG>:-g> # Include
$<$<CONFIG:DEBUG>:-ggdb> # Include
$<$<CONFIG:RELWITHDEBINFO>:-g> # Include
$<$<CONFIG:RELEASE>:-s> # Strip

# Optimization level
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELWITHDEBINFO>:-O2>
$<$<CONFIG:RELEASE>:-O2>
-fno-inline-functions
# Link time optimizations
$<$<CONFIG:RELWITHDEBINFO>:-flto>
$<$<CONFIG:RELEASE>:-flto>
-ffunction-sections
-fdata-sections

# C++ stuff
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>

# ASM stuff
$<$<COMPILE_LANGUAGE:ASM>:-x>
$<$<COMPILE_LANGUAGE:ASM>:assembler-with-cpp>
)

add_link_options(
-T ${PROJECT_SOURCE_DIR}/linker_script_rz_a1l.ld
LINKER:--gc-sections

-nostartfiles # Don't emit startfiles
-estart # Set the entrypoint to 'start' (see RZA1/compiler/asm/start.S)
)

# RTT Debug options
# RTT option
option(ENABLE_RTT "Enable RTT output" ON)

# SYSEX Load option
option(ENABLE_SYSEX_LOAD "Enable loading firmware over midi sysex" OFF)

# Colored output
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." ON)

if(FORCE_COLORED_OUTPUT)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Forcing colors for GCC")
add_compile_options(-fdiagnostics-color=always)
add_link_options(-fdiagnostics-color=always)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Forcing colors for Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif(FORCE_COLORED_OUTPUT)
set(CMAKE_COLOR_DIAGNOSTICS ON)
add_compile_options($<$<CXX_COMPILER_ID:Clang>:-fansi-escape-codes>)

# ##### Documentation generation #######
# check if Doxygen is installed
Expand Down Expand Up @@ -181,6 +118,38 @@ else(DOXYGEN_FOUND)
"Please install from https://github.com/doxygen/doxygen/releases")
endif(DOXYGEN_FOUND)

# Global compilation options
add_compile_options(

# Feature flags
-fdiagnostics-parseable-fixits
-fsigned-char

# Debug symbols
$<$<CONFIG:DEBUG,RELWITHDEBINFO>:-ggdb3> # Include

# Optimization level
$<$<CONFIG:DEBUG>:-Og>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-O2>
-fno-inline-functions

# Link time optimizations
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-flto=auto>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-fuse-linker-plugin>
-ffunction-sections
-fdata-sections

# C++ stuff
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>

# ASM stuff
$<$<COMPILE_LANGUAGE:ASM>:-x>
$<$<COMPILE_LANGUAGE:ASM>:assembler-with-cpp>
)

# Add libraries
add_subdirectory(lib)

Expand All @@ -195,15 +164,20 @@ add_subdirectory(src)

# )

option(MAINTAINER_MODE "Enables all warnings and errors" OFF)

# Project-only compile options (warnings, etc.)
target_compile_options(deluge PUBLIC
$<$<AND:$<BOOL:${MAINTAINER_MODE}>,$<CXX_COMPILER_ID:GNU>>:-fanalyzer> # static analysis

# Warnings
# $<$<CONFIG:DEBUG>:-Wextra> # TODO: Enable when ready
# $<$<CONFIG:DEBUG>:-Wall> # TODO: Enable when ready
# $<$<CONFIG:DEBUG>:-Wpedantic> # TODO: Enable when ready
$<$<BOOL:${MAINTAINER_MODE}>:-Wextra>
$<$<BOOL:${MAINTAINER_MODE}>:-Wall>
$<$<BOOL:${MAINTAINER_MODE}>:-Wabi>
$<$<BOOL:${MAINTAINER_MODE}>:-Wpedantic>
$<$<CONFIG:DEBUG>:-Wnull-dereference>
$<$<CONFIG:DEBUG>:-Wno-psabi>
$<$<CONFIG:DEBUG>:-Wno-unused-parameter>

$<$<CONFIG:DEBUG>:-Werror=write-strings>

Expand All @@ -214,13 +188,12 @@ target_compile_options(deluge PUBLIC
# tracked for diagnostic usage. We have a 32k stack so it's not that important
# primarily concerned with unbounded stack use
$<$<CONFIG:DEBUG>:-Wstack-usage=2000>
$<$<CONFIG:RELWITHDEBINFO>:-Wstack-usage=2000>
$<$<CONFIG:RELEASE>:-Wstack-usage=2000>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-Wstack-usage=2000>
)

set_target_properties(deluge
PROPERTIES
C_STANDARD 11
C_STANDARD 17
C_STANDARD_REQUIRED ON
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON
Expand All @@ -236,8 +209,27 @@ set(NMDUMP_FILE $<CONFIG>/deluge${EXECUTABLE_VERSION_SUFFIX}.nmdump)

# add link options to generate memory map
target_link_options(deluge PUBLIC
-T ${PROJECT_SOURCE_DIR}/linker_script_rz_a1l.ld
LINKER:-Map=${MAP_FILE}
LINKER:--cref
LINKER:--gc-sections
LINKER:--entry=start # Set the entrypoint to 'start' (see RZA1/compiler/asm/start.S)

$<$<CONFIG:RELEASE>:LINKER:--strip-all> # Strip

-nostartfiles # Don't emit startfiles

# Print details
LINKER:--warn-common
LINKER:--stats
#$<$<CXX_COMPILER_ID:GNU>:LINKER:--print-memory-usage>

# Link-Time Optimization
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-flto=auto>
$<$<CONFIG:RELEASE,RELWITHDEBINFO>:-fuse-linker-plugin>

# Coloring
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
)

# generate .bin firmware file
Expand Down
11 changes: 5 additions & 6 deletions scripts/cmake/CMakeToolchainDeluge.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ set(CMAKE_STRIP ${ARM_TOOLCHAIN_BIN_PATH}/arm-none-eabi-strip${TOOLCHAIN_
set(CMAKE_NM ${ARM_TOOLCHAIN_BIN_PATH}/arm-none-eabi-nm${TOOLCHAIN_EXT} CACHE FILEPATH "Path to list symbols.")
set(CMAKE_OBJDUMP ${ARM_TOOLCHAIN_BIN_PATH}/arm-none-eabi-objdump${TOOLCHAIN_EXT} CACHE FILEPATH "Path to dump objects.")

set(CMAKE_ASM_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used by the ASM compiler during RELEASE builds." FORCE)
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used by the C compiler during RELEASE builds." FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING "Flags used by the C++ compiler during RELEASE builds." FORCE)
set(CMAKE_ASM_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "Flags used by the ASM compiler during RELEASE builds." FORCE)
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "Flags used by the C compiler during RELEASE builds." FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG" CACHE STRING "Flags used by the C++ compiler during RELEASE builds." FORCE)

set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs --specs=rdimon.specs" CACHE STRING "Flags used by the linker during all build types.")

# Architecture
set(ARCH_FLAGS
-mcpu=cortex-a9
#-march=armv7-a
-mfpu=neon
-mfloat-abi=hard
-marm
-mthumb-interwork
-mlittle-endian
-mfloat-abi=hard
-mfpu=neon
)
add_compile_options(${ARCH_FLAGS})
add_link_options(${ARCH_FLAGS})
Expand Down
10 changes: 1 addition & 9 deletions src/definitions_cxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once
#include "definitions.h"
#include "util/misc.h"
#include "version.h"
#include <algorithm>
#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -58,15 +59,6 @@

#define PITCH_DETECT_DEBUG_LEVEL 0

struct SemVer {
uint8_t major;
uint8_t minor;
uint8_t patch;
// NOTE: below needs C++20
//auto operator<=>(const SemVer &) const = default
};
constexpr SemVer kCommunityFirmwareVersion{1, 0, 0};

// FIXME: These need to be nuked and all references in the codebase removed in prep for the Community Firmware v1.0.0 release
// correspondingly, we should probably we storing the semver version in three bytes in the flash rather than trying to compress
// it all to one (see above class)
Expand Down
13 changes: 6 additions & 7 deletions src/deluge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ target_link_libraries(deluge PUBLIC
)

target_compile_definitions(deluge PUBLIC
$<$<CONFIG:DEBUG>:IN_HARDWARE_DEBUG=1>
$<$<CONFIG:DEBUG>:ENABLE_TEXT_OUTPUT=1>
$<$<CONFIG:RELWITHDEBINFO>:IN_HARDWARE_DEBUG=1>
$<$<CONFIG:RELWITHDEBINFO>:ENABLE_TEXT_OUTPUT=1>
$<$<CONFIG:DEBUG,RELWITHDEBINFO>:IN_HARDWARE_DEBUG=1>
$<$<CONFIG:DEBUG,RELWITHDEBINFO>:ENABLE_TEXT_OUTPUT=1>
)

if(ENABLE_RTT)
message(STATUS "RTT enabled for deluge")
target_compile_definitions(deluge PUBLIC
$<$<CONFIG:DEBUG>:HAVE_RTT=1>
$<$<CONFIG:RELWITHDEBINFO>:HAVE_RTT=1>
$<$<CONFIG:DEBUG,RELWITHDEBINFO>:HAVE_RTT=1>
)
target_link_libraries(deluge PUBLIC
$<$<CONFIG:DEBUG,RELWITHDEBINFO>:RTT>
)
target_link_libraries(deluge PUBLIC RTT)
endif(ENABLE_RTT)

if(ENABLE_SYSEX_LOAD)
Expand Down
Loading

0 comments on commit c3f1d36

Please sign in to comment.