add a second tracy target instead of modifying the main target

This commit is contained in:
2026-02-25 15:24:12 +01:00
parent 79f088d10e
commit dc894d1c38
2 changed files with 30 additions and 27 deletions

View File

@ -4,26 +4,6 @@ project(MassSprings)
set(CMAKE_CXX_STANDARD 26) set(CMAKE_CXX_STANDARD 26)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 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 "${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_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") 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_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
message("-- CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") 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/main.cpp
src/camera.cpp src/camera.cpp
src/renderer.cpp src/renderer.cpp
@ -51,19 +34,39 @@ add_executable(masssprings
src/distance.cpp src/distance.cpp
) )
# Main target
add_executable(masssprings ${SOURCES})
target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR}) target_include_directories(masssprings PUBLIC ${RAYLIB_CPP_INCLUDE_DIR})
if(USE_TRACY)
target_link_libraries(masssprings PUBLIC raylib Backward::Backward TracyClient)
else()
target_link_libraries(masssprings PUBLIC raylib Backward::Backward) target_link_libraries(masssprings PUBLIC raylib Backward::Backward)
# Tracy target
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)
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() endif()
# LTO
include(CheckIPOSupported) include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error) check_ipo_supported(RESULT supported OUTPUT error)
if(supported) if(supported)
message(STATUS "IPO / LTO enabled") message(STATUS "IPO / LTO enabled")
set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) set_property(TARGET masssprings PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(USE_TRACY)
set_property(TARGET masssprings_tracy PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
else() else()
message(STATUS "IPO / LTO not supported: <${error}>") message(STATUS "IPO / LTO not supported: <${error}>")
endif() endif()

View File

@ -247,7 +247,7 @@ rec {
echo "Running cmake" echo "Running cmake"
cmake -G "Unix Makefiles" \ cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE="${type}" \ -DCMAKE_BUILD_TYPE="${type}" \
-DUSE_TRACY=Off \ -DUSE_TRACY=On \
.. ..
echo "Linking compile_commands.json" echo "Linking compile_commands.json"
@ -286,7 +286,7 @@ rec {
abbr -a debug "${buildDebug} && ./cmake-build-debug/masssprings" abbr -a debug "${buildDebug} && ./cmake-build-debug/masssprings"
abbr -a release "${buildRelease} && ./cmake-build-release/masssprings" abbr -a release "${buildRelease} && ./cmake-build-release/masssprings"
abbr -a rungdb "${buildDebug} && gdb --tui ./cmake-build-debug/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" 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 in