From dc894d1c389cd07636735757c6631575e574dd64 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 25 Feb 2026 15:24:12 +0100 Subject: [PATCH] add a second tracy target instead of modifying the main target --- CMakeLists.txt | 53 ++++++++++++++++++++++++++------------------------ flake.nix | 4 ++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 302b261..116e16d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,26 +4,6 @@ project(MassSprings) set(CMAKE_CXX_STANDARD 26) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -find_package(raylib REQUIRED) -find_package(Backward REQUIRED) - -# Need to enable/disable this based on a variable for nix build -if(USE_TRACY) - include(FetchContent) - FetchContent_Declare(tracy - GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.11.1 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE - ) - FetchContent_MakeAvailable(tracy) - option(TRACY_ENABLE "" ON) - option(TRACY_ON_DEMAND "" ON) - - # Enable tracy macros in the application. Uses a LOT of memory. - add_compile_definitions(TRACY) -endif() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wno-unused-parameter -Wunreachable-code") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2 -ggdb") # -fsanitize=address already fails on InitWindow(), -fsanitize=undefined, -fsanitize=leak set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -march=native") @@ -35,9 +15,12 @@ message("-- CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") message("-- CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") message("-- CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") -include_directories(include) +find_package(raylib REQUIRED) +find_package(Backward REQUIRED) -add_executable(masssprings +# Headers + Sources +include_directories(include) +set(SOURCES src/main.cpp src/camera.cpp src/renderer.cpp @@ -51,19 +34,39 @@ add_executable(masssprings src/distance.cpp ) +# Main target +add_executable(masssprings ${SOURCES}) target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR}) +target_link_libraries(masssprings PUBLIC raylib Backward::Backward) +# Tracy target if(USE_TRACY) - target_link_libraries(masssprings PUBLIC raylib Backward::Backward TracyClient) -else() - target_link_libraries(masssprings PUBLIC raylib Backward::Backward) + include(FetchContent) + FetchContent_Declare(tracy + GIT_REPOSITORY https://github.com/wolfpld/tracy.git + GIT_TAG v0.11.1 + GIT_SHALLOW TRUE + GIT_PROGRESS TRUE + ) + FetchContent_MakeAvailable(tracy) + option(TRACY_ENABLE "" ON) + option(TRACY_ON_DEMAND "" ON) + + add_executable(masssprings_tracy ${SOURCES}) + target_include_directories(masssprings_tracy PUBLIC ${RAYLIB_CPP_INCLUDE_DIR}) + target_compile_definitions(masssprings_tracy PRIVATE TRACY) + target_link_libraries(masssprings_tracy PUBLIC raylib Backward::Backward TracyClient) endif() +# LTO include(CheckIPOSupported) check_ipo_supported(RESULT supported OUTPUT error) if(supported) message(STATUS "IPO / LTO enabled") set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + if(USE_TRACY) + set_property(TARGET masssprings_tracy PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() else() message(STATUS "IPO / LTO not supported: <${error}>") endif() diff --git a/flake.nix b/flake.nix index 59750a1..597bcee 100644 --- a/flake.nix +++ b/flake.nix @@ -247,7 +247,7 @@ rec { echo "Running cmake" cmake -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE="${type}" \ - -DUSE_TRACY=Off \ + -DUSE_TRACY=On \ .. echo "Linking compile_commands.json" @@ -286,7 +286,7 @@ rec { abbr -a debug "${buildDebug} && ./cmake-build-debug/masssprings" abbr -a release "${buildRelease} && ./cmake-build-release/masssprings" abbr -a rungdb "${buildDebug} && gdb --tui ./cmake-build-debug/masssprings" - abbr -a runtracy "tracy -a 127.0.0.1 &; ${buildRelease} && sudo -E ./cmake-build-release/masssprings" + abbr -a runtracy "tracy -a 127.0.0.1 &; ${buildRelease} && sudo -E ./cmake-build-release/masssprings_tracy" abbr -a runvalgrind "${buildDebug} && valgrind --leak-check=full --show-reachable=no --show-leak-kinds=definite,indirect,possible --track-origins=no --suppressions=valgrind.supp --log-file=valgrind.log ./cmake-build-debug/masssprings && cat valgrind.log" ''; in