diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e79f7342..aa1ca751d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -233,8 +233,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") add_link_options("$<$:-fprofile-generate>") add_compile_options("$<$:-fprofile-use>") add_link_options("$<$:-fprofile-use>") - add_compile_options("$<$:-fprofile-dir=${DEVILUTIONX_PROFILE_DIR}>") - add_link_options("$<$:-fprofile-dir=${DEVILUTIONX_PROFILE_DIR}>") + add_compile_options("$<$:-fprofile-dir=${DEVILUTIONX_PROFILE_DIR};-fprofile-prefix-path=${CMAKE_CURRENT_BINARY_DIR}>") + add_link_options("$<$:-fprofile-dir=${DEVILUTIONX_PROFILE_DIR};-fprofile-prefix-path=${CMAKE_CURRENT_BINARY_DIR}>") endif() # Not a genexp because CMake doesn't support it diff --git a/Packaging/OpenDingux/build.sh b/Packaging/OpenDingux/build.sh index e258f59a6..9eb016fe9 100755 --- a/Packaging/OpenDingux/build.sh +++ b/Packaging/OpenDingux/build.sh @@ -110,7 +110,6 @@ parse_args() { "-DDEVILUTIONX_PROFILE_GENERATE=ON" "-DDEVILUTIONX_PROFILE_DIR=${PROFILE_DIR}" ) - BUILD_TYPE=relwithdebinfo OPK_DESKTOP_NAME="DevilutionX PG" OPK_DESKTOP_EXEC="profile-generate.sh" OPK_EXTRA_FILES=( diff --git a/tools/build_pgo.sh b/tools/build_pgo.sh new file mode 100755 index 000000000..91286d373 --- /dev/null +++ b/tools/build_pgo.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# Builds a PGO-optimized binary with the profile data gathered by running the test demo. +set -euo pipefail + +PARALLELISM="$(getconf _NPROCESSORS_ONLN)" + +set -x + +rm -rf build-profile-data/config build-profile-data/profile +mkdir -p build-profile-data/config +cd build-profile-data/config +ln -s ../../test/fixtures/timedemo/WarriorLevel1to2/demo_* . +cp ../../test/fixtures/timedemo/WarriorLevel1to2/spawn_* . +cd - + +# We build both versions with the same FetchContent base directory because otherwise +# gcc will complain about the source locations for FetchContent dependencies, +# which are stored in the build directory by default. +# Ideally, we would only specify the location for the FetchContent src directories +# but CMake does not support that. +cmake -S. -Bbuild-profile-generate -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DDEVILUTIONX_PROFILE_GENERATE=ON \ + -DDEVILUTIONX_PROFILE_DIR="${PWD}/build-profile-data/profile" \ + -DFETCHCONTENT_BASE_DIR="${PWD}/build-profile-data/fetchcontent-base" \ + -DBUILD_TESTING=OFF "$@" +cmake --build build-profile-generate -j "$PARALLELISM" +build-profile-generate/devilutionx --diablo --spawn --lang en --demo 0 --timedemo \ + --save-dir build-profile-data/config + +cmake -S. -Bbuild-profile-use -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DDEVILUTIONX_PROFILE_USE=ON \ + -DDEVILUTIONX_PROFILE_DIR="${PWD}/build-profile-data/profile" \ + -DFETCHCONTENT_BASE_DIR="${PWD}/build-profile-data/fetchcontent-base" \ + -DBUILD_TESTING=OFF "$@" +cmake --build build-profile-use -j "$PARALLELISM"