From 46a6cdba3a423947564d80083e95e11237477b8c Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 1 Nov 2021 09:10:32 +0100 Subject: [PATCH] cmake: add {-g3,-gsplit-dwarf} flags for debugging cmake: * check if we're being run for valgrind, in which case do not split dwarf information, valgrinds does not like it (see #1). makefile: * build for vagrant into a separate folder entirely. ci: * install gcc, cmake and ninja along with vagrant, since now we are building inside of the ci container as well. close #1 --- .drone.starlark | 4 ++-- CMakeLists.txt | 20 ++++++++++++++++++++ Makefile | 17 +++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.drone.starlark b/.drone.starlark index 86885c0..d18fe39 100644 --- a/.drone.starlark +++ b/.drone.starlark @@ -58,7 +58,7 @@ def main(ctx): "depends_on": ["build debug"], "commands": [ "uname -r", - "pacman -Sy valgrind --noconfirm --needed", + "pacman -Sy gcc cmake ninja valgrind --noconfirm --needed", "valgrind --version", "make valgrind" ] @@ -70,7 +70,7 @@ def main(ctx): "depends_on": ["build release"], "commands": [ "uname -r", - "pacman -Sy valgrind --noconfirm --needed", + "pacman -Sy gcc cmake ninja valgrind --noconfirm --needed", "valgrind --version", "make valgrind-release" ] diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c140ec..7eb65bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,26 @@ project(fortuna LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) if(CMAKE_BUILD_TYPE MATCHES "Debug") + # Produce debugging information in the operating system's native format. + # Level 3 includes extra information, such as all the macro definitions + # present in the program. Some debuggers support macro expansion when you + # use -g3 + if(NOT CMAKE_CXX_FLAGS MATCHES "-g") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") + endif(NOT CMAKE_CXX_FLAGS MATCHES "-g") + + if(NOT $ENV{VALGRIND} MATCHES "true") + # If DWARF debugging information is enabled, separate as much debugging + # information as possible into a separate output file with the extension + # .dwo. This option allows the build system to avoid linking files with + # debug information. + if(NOT CMAKE_CXX_FLAGS MATCHES "-gsplit-dwarf") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gsplit-dwarf") + endif(NOT CMAKE_CXX_FLAGS MATCHES "-gsplit-dwarf") + else() + message(STATUS "VALGRIND=true, not setting '-gsplit-dwarf'") + endif(NOT $ENV{VALGRIND} MATCHES "true") + if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif(NOT CMAKE_CXX_FLAGS MATCHES "-Wall") diff --git a/Makefile b/Makefile index 1c0b3ee..34511c6 100644 --- a/Makefile +++ b/Makefile @@ -10,17 +10,20 @@ r_folder = cmake-build-release t = clang-tidy t_args = --config="" --format-style=google --checks="clang-diagnostic-*,clang-analyzer-*,google-*" --use-color=true -p $(d_folder) ./*.{cpp,h} v = valgrind +v_env = VALGRIND= +v_db = $(d_folder)_valgr +v_rl = $(r_folder)_valgr .PHONY: check tidy build debug release valgrind test debug: if [ ! -d "$(d_folder)" ]; then mkdir -pv $(d_folder); fi - $(c) $(c_args)Debug -B $(d_folder) $(cpp_flags) && \ + $(v_env)false $(c) $(c_args)Debug -B $(d_folder) $(cpp_flags) && \ $(n) $(n_args) $(d_folder) release: if [ ! -d "$(r_folder)" ]; then mkdir -pv $(r_folder); fi - $(c) $(c_args)Release -B $(r_folder) $(cpp_flags) && \ + $(v_env)false $(c) $(c_args)Release -B $(r_folder) $(cpp_flags) && \ $(n) $(n_args) $(r_folder) check: @@ -33,10 +36,16 @@ tidy: valgrind: valgrind-debug valgrind-debug: - $(v) ./$(d_folder)/fortuna + if [ ! -d "$(v_db)" ]; then mkdir -pv "$(v_db)"; fi + $(v_env)true $(c) $(c_args)Debug -B "$(v_db)" $(cpp_flags) && \ + $(n) $(n_args) "$(v_db)" + $(v) ./$(v_db)/fortuna valgrind-release: - $(v) ./$(r_folder)/fortuna + if [ ! -d "$(v_rl)" ]; then mkdir -pv "$(v_rl)"; fi + $(v_env)true $(c) $(c_args)Release -B "$(v_rl)" $(cpp_flags) && \ + $(n) $(n_args) "$(v_rl)" + $(v) ./$(v_rl)/fortuna build: debug