From a36b8da462131e320d014e05aec64d11057d3d65 Mon Sep 17 00:00:00 2001 From: Masterkatze Date: Sun, 23 Jun 2024 19:49:49 +0300 Subject: [PATCH 1/4] Add GitHub Actions workflow --- .github/workflows/cibuild.yml | 189 ++++++++++++++++++ .gitignore | 2 +- CONTRIBUTING.md | 2 +- README.md | 21 +- .../{GameMenu.preproc.res => GameMenu.res.in} | 2 +- mp/src/CMakeLists.txt | 117 ++++++++--- mp/src/CMakePresets.json | 97 +++++++++ mp/src/cmake/build_info.cmake | 26 ++- mp/src/cmake/packaging.cmake | 21 ++ mp/src/cmake/utils.cmake | 111 +++++++--- mp/src/game/client/CMakeLists.txt | 10 +- mp/src/game/server/CMakeLists.txt | 14 +- mp/src/game/shared/neo/neo_version.cpp | 6 +- .../game/shared/neo/neo_version_info.cpp.in | 12 ++ mp/src/game/shared/neo/neo_version_info.h | 9 + .../shared/neo/neo_version_info.preproc.h | 14 -- .../materialsystem/stdshaders/CMakeLists.txt | 8 +- 17 files changed, 543 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/cibuild.yml rename mp/game/neo/resource/{GameMenu.preproc.res => GameMenu.res.in} (93%) create mode 100644 mp/src/CMakePresets.json create mode 100644 mp/src/cmake/packaging.cmake create mode 100644 mp/src/game/shared/neo/neo_version_info.cpp.in create mode 100644 mp/src/game/shared/neo/neo_version_info.h delete mode 100644 mp/src/game/shared/neo/neo_version_info.preproc.h diff --git a/.github/workflows/cibuild.yml b/.github/workflows/cibuild.yml new file mode 100644 index 000000000..2970c509b --- /dev/null +++ b/.github/workflows/cibuild.yml @@ -0,0 +1,189 @@ +name: Build + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + build: + name: ${{ matrix.platform.display_name }} ${{ matrix.preset_build_type.display_name }} + + runs-on: ${{ matrix.platform.os }} + + defaults: + run: + shell: bash + + strategy: + fail-fast: false + + matrix: + platform: + - { display_name: 'Linux Native Libraries', os: ubuntu-latest, preset_os: linux } + - { display_name: 'Windows Native Libraries', os: windows-latest, preset_os: windows } + + preset_build_type: + - { display_name: 'Debug', name: debug } + - { display_name: 'Release', name: release } + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + run: | + preset_name="${{ matrix.platform.preset_os }}-${{ matrix.preset_build_type.name }}" + workspace_dir="${{ github.workspace }}" + source_dir=${workspace_dir//\\//}/mp/src + build_dir=${workspace_dir//\\//}/mp/src/build/$preset_name + install_dir=$build_dir/install + echo "source_dir=$source_dir" >> "$GITHUB_ENV" + echo "build_dir=$build_dir" >> "$GITHUB_ENV" + echo "install_dir=$install_dir" >> "$GITHUB_ENV" + echo "preset_name=$preset_name" >> "$GITHUB_ENV" + + - name: Install packages + if: ${{ matrix.platform.os == 'ubuntu-latest' }} + run: | + sudo apt update + sudo apt install gcc-multilib g++-multilib ninja-build -y + + - name: Install packages + if: ${{ matrix.platform.os == 'windows-latest' }} + run: choco install -y ninja + + - uses: ilammy/msvc-dev-cmd@v1 + if: ${{ matrix.platform.os == 'windows-latest' }} + with: + arch: x86 + + - name: Print PATH + if: ${{ matrix.platform.os == 'windows-latest' }} + run: | + echo "PATH: $PATH" + + # Libraries + + - name: CMake configure libraries build + working-directory: ${{ env.source_dir }} + run: > + cmake + --preset ${{ env.preset_name }} + -DCMAKE_INSTALL_PREFIX=${{ env.install_dir }} + -DNEO_USE_CCACHE=OFF + -DNEO_COPY_LIBRARIES=OFF + -DNEO_USE_SEPARATE_BUILD_INFO=ON + -DNEO_INSTALL_LIBRARIES=ON + -DNEO_INSTALL_RESOURCES=OFF + + - name: CMake libraries build + working-directory: ${{ env.source_dir }} + run: cmake --build --preset ${{ env.preset_name }} --parallel --verbose + + - name: Install libraries + run: cmake --install ${{ env.build_dir }} + + # Dedicated library + + - name: CMake reconfigure dedicated library build + working-directory: ${{ env.source_dir }} + run: > + cmake + --preset ${{ env.preset_name }} + -DNEO_DEDICATED=ON + + - name: CMake dedicated library build + working-directory: ${{ env.source_dir }} + run: cmake --build --preset ${{ env.preset_name }} --parallel --verbose + + - name: Install dedicated library + run: cmake --install ${{ env.build_dir }} + + # Artifacts + + - name: Get artifact names + working-directory: ${{ env.install_dir }} + run: | + echo "libraries=$(find . -regex '\.\/neo-\w*-\w*-libraries-\w*-\w*' -printf '%f')" >> "$GITHUB_ENV" + echo "libraries_debuginfo=$(find . -regex '\.\/neo-\w*-\w*-libraries-debuginfo-\w*-\w*' -printf '%f')" >> "$GITHUB_ENV" + echo "dedicated=$(find . -regex '\.\/neo-\w*-\w*-dedicated-\w*-\w*' -printf '%f')" >> "$GITHUB_ENV" + echo "dedicated_debuginfo=$(find . -regex '\.\/neo-\w*-\w*-dedicated-debuginfo-\w*-\w*' -printf '%f')" >> "$GITHUB_ENV" + + - name: Upload libraries + uses: actions/upload-artifact@v4 + with: + name: ${{ env.libraries }} + path: ${{ env.install_dir }}/${{ env.libraries }} + + - name: Upload libraries debug information + uses: actions/upload-artifact@v4 + with: + name: ${{ env.libraries_debuginfo }} + path: ${{ env.install_dir }}/${{ env.libraries_debuginfo }} + + - name: Upload dedicated library + uses: actions/upload-artifact@v4 + with: + name: ${{ env.dedicated }} + path: ${{ env.install_dir }}/${{ env.dedicated }} + + - name: Upload dedicated library debug information + uses: actions/upload-artifact@v4 + with: + name: ${{ env.dedicated_debuginfo }} + path: ${{ env.install_dir }}/${{ env.dedicated_debuginfo }} + + pack-resources: + name: Windows Native Resources + + runs-on: windows-latest + + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + run: | + workspace_dir="${{ github.workspace }}" + source_dir=${workspace_dir//\\//}/mp/src + build_dir=${workspace_dir//\\//}/mp/src/build/windows-release + install_dir=$build_dir/install + echo "source_dir=$source_dir" >> "$GITHUB_ENV" + echo "build_dir=$build_dir" >> "$GITHUB_ENV" + echo "install_dir=$install_dir" >> "$GITHUB_ENV" + + - name: Install packages + run: choco install -y ninja + + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x86 + + # Resources + + - name: CMake configure resources build + working-directory: ${{ env.source_dir }} + run: > + cmake + --preset windows-release + -DCMAKE_INSTALL_PREFIX=${{ env.install_dir }} + -DNEO_USE_CCACHE=OFF + -DNEO_COPY_LIBRARIES=OFF + -DNEO_INSTALL_LIBRARIES=OFF + -DNEO_INSTALL_RESOURCES=ON + + - name: Install resources + run: cmake --install ${{ env.build_dir }} + + - name: Get artifact name + working-directory: ${{ env.install_dir }} + run: echo "resources=$(echo neo-*-*-resources)" >> "$GITHUB_ENV" + + - name: Upload resources + uses: actions/upload-artifact@v4 + with: + name: ${{ env.resources }} + path: ${{ env.install_dir }}/${{ env.resources }} diff --git a/.gitignore b/.gitignore index c4c0f591b..3976c4c30 100644 --- a/.gitignore +++ b/.gitignore @@ -205,4 +205,4 @@ mp/game/neo/cfg/sourcemod # Auto-generated by CMake mp/game/neo/resource/GameMenu.res -mp/src/game/shared/neo/neo_version_info.h +mp/src/game/shared/neo/neo_version_info.cpp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 91a2753ca..da2ef9736 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -111,7 +111,7 @@ Ochii's impressive [reverse engineering project](https://github.com/Ochii/neotok ### Current: CMake -This project currently use the [CMake](https://cmake.org/) build system to generate ninja/makefiles and is integrated with IDEs such as VS2022 and qtcreator. When modifying the project file structure, look into `CMakeLists.txt` and `cmake/*.cmake`. +This project currently use the [CMake](https://cmake.org/) build system to generate ninja/makefiles and is integrated with IDEs such as VS2022 and Qt Creator. When modifying the project file structure, look into `CMakeLists.txt` and `cmake/*.cmake`. ### Legacy: Solutions/makefiles diff --git a/README.md b/README.md index 91d5aa985..2d3e1a5eb 100644 --- a/README.md +++ b/README.md @@ -28,19 +28,14 @@ NT;RE can be built using [VS2022 IDE](#visual-studio-2022-windows), [Qt Creator #### Visual Studio 2022 (Windows) 1. Open up VS2022 without a project, then go to: `File > Open > CMake...` 2. Open the `CMakeLists.txt` found in `mp\src` -3. In the top section, you may see "x64-Debug"/"x64-Release" as a selected profile. This needs to be changed to "x86-Debug"/"x86-Release" as this is a 32-bit project. To do so... -4. Click on the dropdown, go to: "Manage Configurations..." -5. Click the green plus button and select "x86-Debug" for debug or "x86-Release" for release mode and apply the configuration. -6. Then make sure to change it over to "x86-Debug" or "x86-Release". -7. In the "Solution Explorer", it'll be under the "Folder View". To switch to the CMake view, right-click and click on "Switch to CMake Targets View". +3. To switch to the CMake view, right-click and click on "Switch to CMake Targets View" in the "Solution Explorer", it'll be under the "Folder View". After that, it should be able to compile. For debugger/run CMake configuration, refer to: [CONTRIBUTING.md - Debugging - VS2022 + CMake (Windows)](CONTRIBUTING.md#vs2022--cmake-windows). #### Qt Creator (Linux) 1. On the "Welcome" screen, click on "Open Project..." 2. Open the `CMakeLists.txt` found in `mp/src` -3. It may ask about kit configuration, tick both Debug and Release configuration and set their build directories ending in "...build/debug" and "...build/release" respectively. -4. By default, the build is not done in parallel but rather sequentiality. Note, parallel builds at the default setting could deadlock the system or make it unresponsive during the process. Available since CMake 3.12, the amount of jobs can be tweaked using `--parallel ` where `` is a number to specify parallel build level, or just simply don't apply it to turn it off. To turn on parallel builds in Qt Creator: On the "Projects" screen, in [YOUR KIT (under Build & Run)] > Build, go to "Build Steps" section, expand by clicking on "Details", and add `--parallel` to the CMake arguments. +3. By default, the build is not done in parallel but rather sequentiality. Note, parallel builds at the default setting could deadlock the system or make it unresponsive during the process. Available since CMake 3.12, the amount of jobs can be tweaked using `--parallel ` where `` is a number to specify parallel build level, or just simply don't apply it to turn it off. To turn on parallel builds in Qt Creator: On the "Projects" screen, in [YOUR KIT (under Build & Run)] > Build, go to "Build Steps" section, expand by clicking on "Details", and add `--parallel` to the CMake arguments. After that, it should be able to compile. For debugger/running configuration, refer to: [CONTRIBUTING.md - Debugging - Qt Creator (Linux)](CONTRIBUTING.md#qt-creator-linux) @@ -83,16 +78,12 @@ Using with the ninja build system, to build NT;RE using the CLI can be done with ``` $ cd /PATH_TO_REPO/neo/mp/src - -$ # To build in Release mode: -$ cmake -S . -B build/release -G Ninja -DCMAKE_BUILD_TYPE=Release -$ cmake --build build/release --parallel - -$ # To build in Debug mode: -$ cmake -S . -B build/debug -G Ninja -$ cmake --build build/debug --parallel +$ cmake --preset PRESET_NAME +$ cmake --build --preset PRESET_NAME ``` +Available PRESET_NAME values: `windows-debug`, `windows-release`, `linux-debug`, `linux-release`. + ## Steam mod setup To make it appear in Steam, the install files have to appear under the sourcemods directory or be directed to it. diff --git a/mp/game/neo/resource/GameMenu.preproc.res b/mp/game/neo/resource/GameMenu.res.in similarity index 93% rename from mp/game/neo/resource/GameMenu.preproc.res rename to mp/game/neo/resource/GameMenu.res.in index 7e8a8f870..75e86245f 100644 --- a/mp/game/neo/resource/GameMenu.preproc.res +++ b/mp/game/neo/resource/GameMenu.res.in @@ -56,7 +56,7 @@ } "13" { - "label" "Build @BUILD_DATE@_@GIT_HASH@ (@OS_BUILD@)" + "label" "Build @BUILD_DATE_SHORT@_@GIT_HASH@ (@OS_BUILD@)" "command" "" } } diff --git a/mp/src/CMakeLists.txt b/mp/src/CMakeLists.txt index 6b020ccc1..04e17ff82 100644 --- a/mp/src/CMakeLists.txt +++ b/mp/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.18.4) +cmake_minimum_required(VERSION 3.25) cmake_policy(SET CMP0091 NEW) @@ -6,9 +6,14 @@ project(neo) set(CMAKE_VERBOSE_MAKEFILE TRUE) message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") +string(TIMESTAMP BUILD_DATETIME UTC) +message(STATUS "${BUILD_DATETIME}") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(cmake/utils.cmake) +include(cmake/build_info.cmake) +include(cmake/packaging.cmake) if(NOT OS_WINDOWS AND NOT OS_LINUX AND NOT OS_MACOS) message(FATAL_ERROR "Unknown OS") @@ -25,9 +30,6 @@ option(NEO_RAD_TELEMETRY_DISABLED "Telemetry disabled" ON) option(NEO_QUICKTIME_VIDEO "Use Quicktime video on Windows" OFF) option(NEO_BUILD_REPLAY "Build replay system" OFF) # NOTE not implemented for neo option(NEO_BUILD_WEAPON_PBK56S "Build PBK56S weapon" OFF) -option(NEO_COPY_LIBRARIES "Copy libraries to bin directory by default" ON) -set(NEO_OUTPUT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../game/neo/bin" CACHE PATH "Directory for output libraries") - if(OS_WINDOWS) set(NEO_BUILD_TIER1 ON CACHE BOOL "" FORCE) set(NEO_BUILD_MATHLIB ON CACHE BOOL "" FORCE) @@ -37,6 +39,11 @@ else() option(NEO_BUILD_MATHLIB "Build mathlib library" ON) option(NEO_BUILD_VGUI_CONTROLS "Build vgui_controls library" ON) endif() +option(NEO_COPY_LIBRARIES "Copy libraries to bin directory by default" ON) +set(NEO_OUTPUT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../game/neo/bin" CACHE PATH "Directory for output libraries") +option(NEO_INSTALL_LIBRARIES "Install game libraries" OFF) +option(NEO_INSTALL_RESOURCES "Install game resources" OFF) +option(NEO_USE_SEPARATE_BUILD_INFO "Use separate build info on Linux" OFF) message(STATUS "chroot build mode: ${NEO_CHROOT_BUILD}") message(STATUS "Use ccache: ${NEO_USE_CCACHE}") @@ -54,17 +61,23 @@ message(STATUS "Build mathlib library: ${NEO_BUILD_MATHLIB}") message(STATUS "Build vgui_controls library: ${NEO_BUILD_VGUI_CONTROLS}") message(STATUS "Copy libraries to bin directory by default: ${NEO_COPY_LIBRARIES}") message(STATUS "Directory for output libraries: ${NEO_OUTPUT_LIBRARY_PATH}") +message(STATUS "Install game libraries: ${NEO_INSTALL_LIBRARIES}") +message(STATUS "Install game resources: ${NEO_INSTALL_RESOURCES}") +message(STATUS "Use separate build info on Linux: ${NEO_USE_SEPARATE_BUILD_INFO}") - -file(MAKE_DIRECTORY "${NEO_OUTPUT_LIBRARY_PATH}") +if(NEO_COPY_LIBRARIES) + file(MAKE_DIRECTORY "${NEO_OUTPUT_LIBRARY_PATH}") +endif() if(CMAKE_VERBOSE_MAKEFILE) set(CMAKE_EXECUTE_PROCESS_COMMAND_ECHO STDOUT) endif() +set(CMAKE_SKIP_RPATH TRUE) + set(CMAKE_CXX_STANDARD 20) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_POSITION_INDEPENDENT_CODE OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +set(CMAKE_POSITION_INDEPENDENT_CODE FALSE) set(SOURCESDK TRUE) @@ -397,24 +410,70 @@ add_custom_target( VERBATIM ) -# TODO add later? -# $Project "raytrace" "raytrace\raytrace.vpc" [$WIN32||$X360||$POSIX] - -# Not needed? -# $Project "serverplugin_empty" "utils\serverplugin_sample\serverplugin_empty.vpc" [$WIN32||$POSIX] -# $Project "captioncompiler" "utils\captioncompiler\captioncompiler.vpc" [$WIN32] -# $Project "fgdlib" "fgdlib\fgdlib.vpc" [$WIN32] -# $Project "glview" "utils\glview\glview.vpc" [$WIN32] -# $Project "height2normal" "utils\height2normal\height2normal.vpc" [$WIN32] -# $Project "motionmapper" "utils\motionmapper\motionmapper.vpc" [$WIN32] -# $Project "phonemeextractor" "utils\phonemeextractor\phonemeextractor.vpc" [$WIN32] -# $Project "qc_eyes" "utils\qc_eyes\qc_eyes.vpc" [$WIN32] -# $Project "tgadiff" "utils\tgadiff\tgadiff.vpc" [$WIN32] -# $Project "vbsp" "utils\vbsp\vbsp.vpc" [$WIN32] -# $Project "vice" "utils\vice\vice.vpc" [$WIN32] -# $Project "vrad_dll" "utils\vrad\vrad_dll.vpc" [$WIN32] -# $Project "vrad_launcher" "utils\vrad_launcher\vrad_launcher.vpc" [$WIN32] -# $Project "vtf2tga" "utils\vtf2tga\vtf2tga.vpc" [$WIN32] -# $Project "vtfdiff" "utils\vtfdiff\vtfdiff.vpc" [$WIN32] -# $Project "vvis_dll" "utils\vvis\vvis_dll.vpc" [$WIN32] -# $Project "vvis_launcher" "utils\vvis_launcher\vvis_launcher.vpc" [$WIN32] +if(NEO_INSTALL_LIBRARIES) + if(NEO_DEDICATED) + set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + + install( + TARGETS server + LIBRARY DESTINATION "${LIBRARY_INSTALL_PATH}" + RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" + ) + + set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-debuginfo-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + + if(OS_WINDOWS) + install( + FILES "$" + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + #OPTIONAL + ) + else() + get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) + install( + FILES ${SERVER_SPLIT_DEBUG_INFO_FILE} + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + OPTIONAL + ) + endif() + else() + set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + + install( + TARGETS client game_shader_dx9 server + LIBRARY DESTINATION "${LIBRARY_INSTALL_PATH}" + RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" + ) + + set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-debuginfo-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + + if(OS_WINDOWS) + install( + FILES + $ + $ + $ + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + ) + else() + get_target_property(CLIENT_SPLIT_DEBUG_INFO_FILE client SPLIT_DEBUG_INFO_FILE) + get_target_property(SHADER_SPLIT_DEBUG_INFO_FILE game_shader_dx9 SPLIT_DEBUG_INFO_FILE) + get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) + install( + FILES + ${CLIENT_SPLIT_DEBUG_INFO_FILE} + ${SHADER_SPLIT_DEBUG_INFO_FILE} + ${SERVER_SPLIT_DEBUG_INFO_FILE} + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + OPTIONAL + ) + endif() + endif() +endif() + +if(NEO_INSTALL_RESOURCES) + install( + DIRECTORY ${CMAKE_SOURCE_DIR}/../game/ + DESTINATION "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-resources" + ) +endif() diff --git a/mp/src/CMakePresets.json b/mp/src/CMakePresets.json new file mode 100644 index 000000000..a4ac78984 --- /dev/null +++ b/mp/src/CMakePresets.json @@ -0,0 +1,97 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}" + }, + { + "name": "windows", + "hidden": true, + "inherits": "base", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-debug", + "displayName": "Windows Debug", + "inherits": "windows", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "windows-release", + "displayName": "Windows Release", + "inherits": "windows", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "linux", + "hidden": true, + "inherits": "base", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "linux-debug", + "displayName": "Linux Debug", + "inherits": "linux", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "linux-release", + "displayName": "Linux Release", + "inherits": "linux", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + } + ], + "buildPresets": [ + { + "name": "windows-debug", + "displayName": "Windows Debug", + "configurePreset": "windows-debug" + }, + { + "name": "windows-release", + "displayName": "Windows Release", + "configurePreset": "windows-release" + }, + { + "name": "linux-debug", + "displayName": "Linux Debug", + "configurePreset": "linux-debug" + }, + { + "name": "linux-release", + "displayName": "Linux Release", + "configurePreset": "linux-release" + } + ] +} diff --git a/mp/src/cmake/build_info.cmake b/mp/src/cmake/build_info.cmake index d171b7349..b6611b43a 100644 --- a/mp/src/cmake/build_info.cmake +++ b/mp/src/cmake/build_info.cmake @@ -1,14 +1,5 @@ -string(TIMESTAMP BUILD_DATE "%Y%m%d") -string(TIMESTAMP BUILD_DATETIME UTC) - find_package(Git REQUIRED) -execute_process( - COMMAND git log -1 --format=%h - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET -) + execute_process( COMMAND git log -1 --format=%H WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} @@ -16,16 +7,23 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) -string(SUBSTRING "${GIT_HASH}" 0 7 GIT_HASH) +string(SUBSTRING "${GIT_LONGHASH}" 0 7 GIT_HASH) + +string(TIMESTAMP BUILD_DATE_SHORT "%Y%m%d") +string(TIMESTAMP BUILD_DATE_LONG "%Y-%m-%d") + +set(OS_BUILD "${CMAKE_SYSTEM_NAME}") +set(COMPILER_ID "${CMAKE_CXX_COMPILER_ID}") +set(COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION}") configure_file( - ${CMAKE_SOURCE_DIR}/../game/neo/resource/GameMenu.preproc.res + ${CMAKE_SOURCE_DIR}/../game/neo/resource/GameMenu.res.in ${CMAKE_SOURCE_DIR}/../game/neo/resource/GameMenu.res @ONLY ) configure_file( - ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.preproc.h - ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.h + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.cpp.in + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.cpp @ONLY ) diff --git a/mp/src/cmake/packaging.cmake b/mp/src/cmake/packaging.cmake new file mode 100644 index 000000000..d37c52cf3 --- /dev/null +++ b/mp/src/cmake/packaging.cmake @@ -0,0 +1,21 @@ +if(NEO_INSTALL_LIBRARIES) + if(NEO_DEDICATED) + set(CPACK_PACKAGE_FILE_NAME "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}") + else() + set(CPACK_PACKAGE_FILE_NAME "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}") + endif() +endif() + +if(NEO_INSTALL_RESOURCES) + set(CPACK_PACKAGE_FILE_NAME "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-resources") +endif() + +if(OS_WINDOWS) + set(CPACK_GENERATOR "ZIP") +else() + set(CPACK_GENERATOR "TXZ") +endif() + +set(CPACK_ARCHIVE_THREADS 0) + +include(CPack) diff --git a/mp/src/cmake/utils.cmake b/mp/src/cmake/utils.cmake index 708eb8bb4..01fc1ab7b 100644 --- a/mp/src/cmake/utils.cmake +++ b/mp/src/cmake/utils.cmake @@ -48,10 +48,10 @@ function(target_sources_grouped) source_group(${PARSED_ARGS_NAME} FILES ${PARSED_ARGS_FILES}) endfunction() -function(add_library_copy_and_symlink) +function(add_library_copy_target) cmake_parse_arguments( PARSED_ARGS - "CREATE_SRV" + "" "TARGET" "" ${ARGN} @@ -72,38 +72,85 @@ function(add_library_copy_and_symlink) WORKING_DIRECTORY "${NEO_OUTPUT_LIBRARY_PATH}" VERBATIM ) +endfunction() + +# Used by split_debug_information +if(NOT MSVC) + include(CMakeFindBinUtils) +endif() - if(OS_LINUX AND PARSED_ARGS_CREATE_SRV) - add_custom_command( - OUTPUT ${PARSED_ARGS_TARGET}_copy_lib_command APPEND - COMMAND ln -sf ${PARSED_ARGS_TARGET}.so ${PARSED_ARGS_TARGET}_srv.so - VERBATIM +function(split_debug_information) + cmake_parse_arguments( + PARSED_ARGS + "" + "TARGET" + "" + ${ARGN} + ) + + if(MSVC) + # MSVC splits debug information by itself + return() + elseif(NOT CMAKE_OBJCOPY) + message(FATAL_ERROR "'objcopy' is not found") + elseif(NOT CMAKE_STRIP) + message(FATAL_ERROR "'strip' is not found") + endif() + + # If the linker doesn't support --compress-debug-sections=zlib, check if objcopy supports --compress-debug-sections + if(LDFLAG_--compress-debug-sections) + # ld supports --compress-debug-sections=zlib. + set(OBJCOPY_COMPRESS_DEBUG_SECTIONS_PARAM "" CACHE INTERNAL "objcopy parameter to compress debug sections") + elseif(NOT LDFLAG_--compress-debug-sections AND NOT DEFINED OBJCOPY_COMPRESS_DEBUG_SECTIONS_PARAM) + # Check for objcopy --compress-debug-sections. + message(STATUS "Checking if objcopy supports --compress-debug-sections") + execute_process(COMMAND ${CMAKE_OBJCOPY} --help + OUTPUT_VARIABLE xc_out + ERROR_QUIET ) + if(xc_out MATCHES "--compress-debug-sections") + # objcopy has --compress-debug-sections + message(STATUS "Checking if objcopy supports --compress-debug-sections - yes") + set(OBJCOPY_COMPRESS_DEBUG_SECTIONS_PARAM "--compress-debug-sections" CACHE INTERNAL "objcopy parameter to compress debug sections") + else() + # objcopy does *not* have --compress-debug-sections + message(STATUS "Checking if objcopy supports --compress-debug-sections - no") + set(OBJCOPY_COMPRESS_DEBUG_SECTIONS_PARAM "" CACHE INTERNAL "objcopy parameter to compress debug sections") + endif() + unset(xc_out) endif() - set_source_files_properties(${PARSED_ARGS_TARGET}_copy_lib_command PROPERTIES SYMBOLIC "true") -endfunction() + # NOTE: Prefix expression was simplified - it probably doesn't work for static libraries + get_property(TARGET_PREFIX TARGET ${PARSED_ARGS_TARGET} PROPERTY PREFIX) + get_property(TARGET_POSTFIX TARGET ${PARSED_ARGS_TARGET} PROPERTY POSTFIX) + get_property(TARGET_OUTPUT_NAME TARGET ${PARSED_ARGS_TARGET} PROPERTY OUTPUT_NAME) + + if("${TARGET_OUTPUT_NAME}" STREQUAL "") + set(TARGET_OUTPUT_NAME "${PARSED_ARGS_TARGET}") + endif() + + set(OUTPUT_NAME_FULL "${TARGET_PREFIX}${TARGET_OUTPUT_NAME}${TARGET_POSTFIX}.debug") + + set(SPLITDEBUG_SOURCE "$") + set(SPLITDEBUG_TARGET "$/${OUTPUT_NAME_FULL}") -add_custom_command( - OUTPUT - ${CMAKE_SOURCE_DIR}/../game/neo/resource/GameMenu.res - ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.h - ALL - COMMAND - ${CMAKE_COMMAND} - -D OS_BUILD=${CMAKE_SYSTEM_NAME} - -D COMPILER_ID=${CMAKE_CXX_COMPILER_ID} - -D COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION} - -P ${CMAKE_SOURCE_DIR}/cmake/build_info.cmake - WORKING_DIRECTORY - ${CMAKE_SOURCE_DIR} -) - -# rebuild GameMenu.res + neo_version_info.h every time -add_custom_target( - get_build_info - ALL - DEPENDS - ${CMAKE_SOURCE_DIR}/../game/neo/resource/GameMenu.res - ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.h -) + # NOTE: objcopy --strip-debug does NOT fully strip the binary; two sections are left: + # - .symtab: Symbol table. + # - .strtab: String table. + # These sections are split into the .debug file, so there's no reason to keep them in the executable + add_custom_command(TARGET ${PARSED_ARGS_TARGET} POST_BUILD + COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${OBJCOPY_COMPRESS_DEBUG_SECTIONS_PARAM} ${SPLITDEBUG_SOURCE} ${SPLITDEBUG_TARGET} + COMMAND ${CMAKE_STRIP} ${SPLITDEBUG_SOURCE} + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink="${SPLITDEBUG_TARGET}" ${SPLITDEBUG_SOURCE} + ) + + # Set the target property to allow installation + set_target_properties(${PARSED_ARGS_TARGET} PROPERTIES + SPLIT_DEBUG_INFO_FILE ${SPLITDEBUG_TARGET} + ) + + # Make sure the file is deleted on `make clean` + set_property(DIRECTORY APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${SPLITDEBUG_TARGET} + ) +endfunction() diff --git a/mp/src/game/client/CMakeLists.txt b/mp/src/game/client/CMakeLists.txt index 34a4b69e9..cba85b4d3 100644 --- a/mp/src/game/client/CMakeLists.txt +++ b/mp/src/game/client/CMakeLists.txt @@ -2,7 +2,11 @@ add_library(client SHARED) set_target_properties(client PROPERTIES PREFIX "") -add_dependencies(client get_build_info) +if(NEO_USE_SEPARATE_BUILD_INFO) + split_debug_information(TARGET client) +endif() + +add_library_copy_target(TARGET client) target_include_directories(client PRIVATE @@ -1550,6 +1554,8 @@ target_sources_grouped( ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.cpp ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.h ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.cpp + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.cpp + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.h ) target_sources_grouped( @@ -1688,5 +1694,3 @@ target_sources_grouped( hl2mp/ui/hl2mptextwindow.cpp hl2mp/ui/hl2mptextwindow.h ) - -add_library_copy_and_symlink(TARGET client CREATE_SRV) diff --git a/mp/src/game/server/CMakeLists.txt b/mp/src/game/server/CMakeLists.txt index 92495889d..22f4c143c 100644 --- a/mp/src/game/server/CMakeLists.txt +++ b/mp/src/game/server/CMakeLists.txt @@ -2,7 +2,15 @@ add_library(server SHARED) set_target_properties(server PROPERTIES PREFIX "") -add_dependencies(server get_build_info) +if(NEO_USE_SEPARATE_BUILD_INFO) + split_debug_information(TARGET server) +endif() + +add_library_copy_target(TARGET server CREATE_SRV) + +if(NEO_DEDICATED AND OS_LINUX) + set_target_properties(server PROPERTIES OUTPUT_NAME server_srv) +endif() target_include_directories(server PRIVATE @@ -1317,6 +1325,8 @@ target_sources_grouped( ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.cpp ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.h ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.cpp + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.cpp + ${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version_info.h neo/neo_client.cpp neo/neo_detpack.cpp neo/neo_detpack.h @@ -1462,5 +1472,3 @@ target_sources_grouped( hl2mp/te_hl2mp_shotgun_shot.cpp hl2mp/te_hl2mp_shotgun_shot.h ) - -add_library_copy_and_symlink(TARGET server CREATE_SRV) diff --git a/mp/src/game/shared/neo/neo_version.cpp b/mp/src/game/shared/neo/neo_version.cpp index a8b8211da..091ec306e 100644 --- a/mp/src/game/shared/neo/neo_version.cpp +++ b/mp/src/game/shared/neo/neo_version.cpp @@ -13,13 +13,13 @@ void neoVersionCallback() #endif Msg("%s\n" "Build version: %s_%s\n" - "Build datetime: %s\n" + "Build date: %s\n" "Git hash: %s\n" "OS: %s\n" "Compiler: %s %s\n", HEADER, - BUILD_DATE, GIT_HASH, - BUILD_DATETIME, + BUILD_DATE_SHORT, GIT_HASH, + BUILD_DATE_LONG, GIT_LONGHASH, OS_BUILD, COMPILER_ID, COMPILER_VERSION); diff --git a/mp/src/game/shared/neo/neo_version_info.cpp.in b/mp/src/game/shared/neo/neo_version_info.cpp.in new file mode 100644 index 000000000..44aa5d05a --- /dev/null +++ b/mp/src/game/shared/neo/neo_version_info.cpp.in @@ -0,0 +1,12 @@ +/* NEO NOTE/WARNING (nullsystem): + * neo_version_info.cpp is char*generated by CMake, the actual file to + * edit is neo_version_info.cpp.in which takes defined CMake variables + */ + +const char* BUILD_DATE_SHORT = "@BUILD_DATE_SHORT@"; +const char* BUILD_DATE_LONG = "@BUILD_DATE_LONG@"; +const char* GIT_HASH = "@GIT_HASH@"; +const char* GIT_LONGHASH = "@GIT_LONGHASH@"; +const char* OS_BUILD = "@OS_BUILD@"; +const char* COMPILER_ID = "@COMPILER_ID@"; +const char* COMPILER_VERSION = "@COMPILER_VERSION@"; diff --git a/mp/src/game/shared/neo/neo_version_info.h b/mp/src/game/shared/neo/neo_version_info.h new file mode 100644 index 000000000..ee07c9e5e --- /dev/null +++ b/mp/src/game/shared/neo/neo_version_info.h @@ -0,0 +1,9 @@ +#pragma once + +extern const char* BUILD_DATE_SHORT; +extern const char* BUILD_DATE_LONG; +extern const char* GIT_HASH; +extern const char* GIT_LONGHASH; +extern const char* OS_BUILD; +extern const char* COMPILER_ID; +extern const char* COMPILER_VERSION; diff --git a/mp/src/game/shared/neo/neo_version_info.preproc.h b/mp/src/game/shared/neo/neo_version_info.preproc.h deleted file mode 100644 index cf5c7e232..000000000 --- a/mp/src/game/shared/neo/neo_version_info.preproc.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -/* NEO NOTE/WARNING (nullsystem): - * neo_version_info.h is autogenerated by cmake, the actual file to - * edit is neo_version_info.preproc.h which takes defined cmake variables - */ -static constexpr char BUILD_DATE[] = "@BUILD_DATE@"; -static constexpr char BUILD_DATETIME[] = "@BUILD_DATETIME@"; -static constexpr char GIT_HASH[] = "@GIT_HASH@"; -static constexpr char GIT_LONGHASH[] = "@GIT_LONGHASH@"; -static constexpr char OS_BUILD[] = "@OS_BUILD@"; -static constexpr char COMPILER_ID[] = "@COMPILER_ID@"; -static constexpr char COMPILER_VERSION[] = "@COMPILER_VERSION@"; - diff --git a/mp/src/materialsystem/stdshaders/CMakeLists.txt b/mp/src/materialsystem/stdshaders/CMakeLists.txt index ff2911d63..c330f1479 100644 --- a/mp/src/materialsystem/stdshaders/CMakeLists.txt +++ b/mp/src/materialsystem/stdshaders/CMakeLists.txt @@ -2,6 +2,12 @@ add_library(game_shader_dx9 SHARED) set_target_properties(game_shader_dx9 PROPERTIES PREFIX "") +if(NEO_USE_SEPARATE_BUILD_INFO) + split_debug_information(TARGET game_shader_dx9) +endif() + +add_library_copy_target(TARGET game_shader_dx9) + target_include_directories(game_shader_dx9 PRIVATE ${CMAKE_SOURCE_DIR}/common @@ -112,5 +118,3 @@ target_sources_grouped( Neo_refract_dx9_helper.cpp Neo_refract_dx9_helper.h ) - -add_library_copy_and_symlink(TARGET game_shader_dx9) From c5a6266460e8dc7db3aea15f21f8cbacfc01cb3a Mon Sep 17 00:00:00 2001 From: Masterkatze Date: Tue, 9 Jul 2024 18:37:19 +0300 Subject: [PATCH 2/4] Change RelWithDebInfo archive name to Release --- mp/src/CMakeLists.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mp/src/CMakeLists.txt b/mp/src/CMakeLists.txt index 04e17ff82..16e5f7468 100644 --- a/mp/src/CMakeLists.txt +++ b/mp/src/CMakeLists.txt @@ -411,8 +411,14 @@ add_custom_target( ) if(NEO_INSTALL_LIBRARIES) + if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + set(BUILD_TYPE_NAME "Release") + else() + set(BUILD_TYPE_NAME "${CMAKE_BUILD_TYPE}") + endif() + if(NEO_DEDICATED) - set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") install( TARGETS server @@ -420,7 +426,7 @@ if(NEO_INSTALL_LIBRARIES) RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" ) - set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-debuginfo-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-debuginfo-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") if(OS_WINDOWS) install( @@ -437,7 +443,7 @@ if(NEO_INSTALL_LIBRARIES) ) endif() else() - set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") install( TARGETS client game_shader_dx9 server @@ -445,7 +451,7 @@ if(NEO_INSTALL_LIBRARIES) RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" ) - set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-debuginfo-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}/bin") + set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-debuginfo-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") if(OS_WINDOWS) install( From 2681c529051d9282a7c7e4d71694fb07380fdc83 Mon Sep 17 00:00:00 2001 From: Masterkatze Date: Tue, 9 Jul 2024 23:55:39 +0300 Subject: [PATCH 3/4] Set correct install path for libraries Also skip install of separate debug info if it's not enabled --- mp/src/CMakeLists.txt | 96 ++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/mp/src/CMakeLists.txt b/mp/src/CMakeLists.txt index 16e5f7468..a55f4eb1d 100644 --- a/mp/src/CMakeLists.txt +++ b/mp/src/CMakeLists.txt @@ -410,15 +410,18 @@ add_custom_target( VERBATIM ) -if(NEO_INSTALL_LIBRARIES) - if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - set(BUILD_TYPE_NAME "Release") - else() - set(BUILD_TYPE_NAME "${CMAKE_BUILD_TYPE}") - endif() +if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + set(BUILD_TYPE_NAME "Release") +else() + set(BUILD_TYPE_NAME "${CMAKE_BUILD_TYPE}") +endif() + +set(INSTALL_PATH_PREFIX "neo-${BUILD_DATE_SHORT}-${GIT_HASH}") +set(INSTALL_PATH_SUFFIX "${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/neo/bin") +if(NEO_INSTALL_LIBRARIES) if(NEO_DEDICATED) - set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") + set(LIBRARY_INSTALL_PATH "${INSTALL_PATH_PREFIX}-dedicated-${INSTALL_PATH_SUFFIX}") install( TARGETS server @@ -426,24 +429,24 @@ if(NEO_INSTALL_LIBRARIES) RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" ) - set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-dedicated-debuginfo-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") - - if(OS_WINDOWS) - install( - FILES "$" - DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" - #OPTIONAL - ) - else() - get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) - install( - FILES ${SERVER_SPLIT_DEBUG_INFO_FILE} - DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" - OPTIONAL - ) + if(NEO_USE_SEPARATE_BUILD_INFO) + set(SPLIT_DEBUG_INFO_INSTALL_PATH "${INSTALL_PATH_PREFIX}-dedicated-debuginfo-${INSTALL_PATH_SUFFIX}") + + if(OS_WINDOWS) + install( + FILES "$" + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + ) + else() + get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) + install( + FILES ${SERVER_SPLIT_DEBUG_INFO_FILE} + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + ) + endif() endif() else() - set(LIBRARY_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") + set(LIBRARY_INSTALL_PATH "${INSTALL_PATH_PREFIX}-libraries-${INSTALL_PATH_SUFFIX}") install( TARGETS client game_shader_dx9 server @@ -451,28 +454,29 @@ if(NEO_INSTALL_LIBRARIES) RUNTIME DESTINATION "${LIBRARY_INSTALL_PATH}" ) - set(SPLIT_DEBUG_INFO_INSTALL_PATH "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-libraries-debuginfo-${CMAKE_SYSTEM_NAME}-${BUILD_TYPE_NAME}/bin") - - if(OS_WINDOWS) - install( - FILES - $ - $ - $ - DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" - ) - else() - get_target_property(CLIENT_SPLIT_DEBUG_INFO_FILE client SPLIT_DEBUG_INFO_FILE) - get_target_property(SHADER_SPLIT_DEBUG_INFO_FILE game_shader_dx9 SPLIT_DEBUG_INFO_FILE) - get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) - install( - FILES - ${CLIENT_SPLIT_DEBUG_INFO_FILE} - ${SHADER_SPLIT_DEBUG_INFO_FILE} - ${SERVER_SPLIT_DEBUG_INFO_FILE} - DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" - OPTIONAL - ) + if(NEO_USE_SEPARATE_BUILD_INFO) + set(SPLIT_DEBUG_INFO_INSTALL_PATH "${INSTALL_PATH_PREFIX}-libraries-debuginfo-${INSTALL_PATH_SUFFIX}") + + if(OS_WINDOWS) + install( + FILES + $ + $ + $ + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + ) + else() + get_target_property(CLIENT_SPLIT_DEBUG_INFO_FILE client SPLIT_DEBUG_INFO_FILE) + get_target_property(SHADER_SPLIT_DEBUG_INFO_FILE game_shader_dx9 SPLIT_DEBUG_INFO_FILE) + get_target_property(SERVER_SPLIT_DEBUG_INFO_FILE server SPLIT_DEBUG_INFO_FILE) + install( + FILES + ${CLIENT_SPLIT_DEBUG_INFO_FILE} + ${SHADER_SPLIT_DEBUG_INFO_FILE} + ${SERVER_SPLIT_DEBUG_INFO_FILE} + DESTINATION "${SPLIT_DEBUG_INFO_INSTALL_PATH}" + ) + endif() endif() endif() endif() @@ -480,6 +484,6 @@ endif() if(NEO_INSTALL_RESOURCES) install( DIRECTORY ${CMAKE_SOURCE_DIR}/../game/ - DESTINATION "neo-${BUILD_DATE_SHORT}-${GIT_HASH}-resources" + DESTINATION "${INSTALL_PATH_PREFIX}-resources" ) endif() From 57031bf2aaedd4d8136e3fabe565da9e55ccb800 Mon Sep 17 00:00:00 2001 From: Masterkatze Date: Sat, 13 Jul 2024 02:13:22 +0300 Subject: [PATCH 4/4] Add CI build mode Some small improvements --- .github/workflows/cibuild.yml | 1 + mp/src/CMakeLists.txt | 26 ++++++++++++++------------ mp/src/cmake/FindBitmap.cmake | 1 + mp/src/cmake/FindChoreoObjects.cmake | 1 + mp/src/cmake/FindDMXLoader.cmake | 1 + mp/src/cmake/FindMatSysControls.cmake | 1 + mp/src/cmake/FindMathlib.cmake | 1 + mp/src/cmake/FindParticles.cmake | 1 + mp/src/cmake/FindSteamAPI.cmake | 1 + mp/src/cmake/FindTier0.cmake | 1 + mp/src/cmake/FindTier1.cmake | 1 + mp/src/cmake/FindTier2.cmake | 1 + mp/src/cmake/FindTier3.cmake | 1 + mp/src/cmake/FindVGUIControls.cmake | 1 + mp/src/cmake/FindVSTDLib.cmake | 1 + mp/src/cmake/FindVTF.cmake | 1 + mp/src/cmake/utils.cmake | 7 ++++--- 17 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cibuild.yml b/.github/workflows/cibuild.yml index 2970c509b..52b192689 100644 --- a/.github/workflows/cibuild.yml +++ b/.github/workflows/cibuild.yml @@ -70,6 +70,7 @@ jobs: cmake --preset ${{ env.preset_name }} -DCMAKE_INSTALL_PREFIX=${{ env.install_dir }} + -DNEO_CI_BUILD=ON -DNEO_USE_CCACHE=OFF -DNEO_COPY_LIBRARIES=OFF -DNEO_USE_SEPARATE_BUILD_INFO=ON diff --git a/mp/src/CMakeLists.txt b/mp/src/CMakeLists.txt index a55f4eb1d..09cd9aefe 100644 --- a/mp/src/CMakeLists.txt +++ b/mp/src/CMakeLists.txt @@ -7,18 +7,18 @@ set(CMAKE_VERBOSE_MAKEFILE TRUE) message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}") string(TIMESTAMP BUILD_DATETIME UTC) -message(STATUS "${BUILD_DATETIME}") +message(STATUS "TIMESTAMP: ${BUILD_DATETIME}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(cmake/utils.cmake) include(cmake/build_info.cmake) -include(cmake/packaging.cmake) if(NOT OS_WINDOWS AND NOT OS_LINUX AND NOT OS_MACOS) message(FATAL_ERROR "Unknown OS") endif() +option(NEO_CI_BUILD "CI build mode" OFF) option(NEO_CHROOT_BUILD "chroot build mode" OFF) option(NEO_USE_CCACHE "Use ccache" ${OS_LINUX}) option(NEO_USE_VALVE_BINDIR "Use /valve bindir" OFF) # NOTE probably should be used with NEO_DEDICATED @@ -30,21 +30,17 @@ option(NEO_RAD_TELEMETRY_DISABLED "Telemetry disabled" ON) option(NEO_QUICKTIME_VIDEO "Use Quicktime video on Windows" OFF) option(NEO_BUILD_REPLAY "Build replay system" OFF) # NOTE not implemented for neo option(NEO_BUILD_WEAPON_PBK56S "Build PBK56S weapon" OFF) -if(OS_WINDOWS) - set(NEO_BUILD_TIER1 ON CACHE BOOL "" FORCE) - set(NEO_BUILD_MATHLIB ON CACHE BOOL "" FORCE) - set(NEO_BUILD_VGUI_CONTROLS ON CACHE BOOL "" FORCE) -else() - option(NEO_BUILD_TIER1 "Build tier1 library" ON) - option(NEO_BUILD_MATHLIB "Build mathlib library" ON) - option(NEO_BUILD_VGUI_CONTROLS "Build vgui_controls library" ON) -endif() +option(NEO_BUILD_TIER1 "Build tier1 library" ON) +option(NEO_BUILD_MATHLIB "Build mathlib library" ON) +option(NEO_BUILD_VGUI_CONTROLS "Build vgui_controls library" ON) option(NEO_COPY_LIBRARIES "Copy libraries to bin directory by default" ON) set(NEO_OUTPUT_LIBRARY_PATH "${CMAKE_SOURCE_DIR}/../game/neo/bin" CACHE PATH "Directory for output libraries") option(NEO_INSTALL_LIBRARIES "Install game libraries" OFF) option(NEO_INSTALL_RESOURCES "Install game resources" OFF) option(NEO_USE_SEPARATE_BUILD_INFO "Use separate build info on Linux" OFF) +option(NEO_ENABLE_CPACK "Enable CPack" OFF) +message(STATUS "CI build mode: ${NEO_CI_BUILD}") message(STATUS "chroot build mode: ${NEO_CHROOT_BUILD}") message(STATUS "Use ccache: ${NEO_USE_CCACHE}") message(STATUS "Use /valve bindir: ${NEO_USE_VALVE_BINDIR}") @@ -64,11 +60,17 @@ message(STATUS "Directory for output libraries: ${NEO_OUTPUT_LIBRARY_PATH}") message(STATUS "Install game libraries: ${NEO_INSTALL_LIBRARIES}") message(STATUS "Install game resources: ${NEO_INSTALL_RESOURCES}") message(STATUS "Use separate build info on Linux: ${NEO_USE_SEPARATE_BUILD_INFO}") +message(STATUS "Enable CPack: ${NEO_ENABLE_CPACK}") +message("") if(NEO_COPY_LIBRARIES) file(MAKE_DIRECTORY "${NEO_OUTPUT_LIBRARY_PATH}") endif() +if(NEO_ENABLE_CPACK) + include(cmake/packaging.cmake) +endif() + if(CMAKE_VERBOSE_MAKEFILE) set(CMAKE_EXECUTE_PROCESS_COMMAND_ECHO STDOUT) endif() @@ -410,7 +412,7 @@ add_custom_target( VERBATIM ) -if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") +if(NEO_CI_BUILD AND "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") set(BUILD_TYPE_NAME "Release") else() set(BUILD_TYPE_NAME "${CMAKE_BUILD_TYPE}") diff --git a/mp/src/cmake/FindBitmap.cmake b/mp/src/cmake/FindBitmap.cmake index 62ee35308..ba40c23e7 100644 --- a/mp/src/cmake/FindBitmap.cmake +++ b/mp/src/cmake/FindBitmap.cmake @@ -7,6 +7,7 @@ endif() find_file(BITMAP_LIBRARY NAMES ${BITMAP_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindChoreoObjects.cmake b/mp/src/cmake/FindChoreoObjects.cmake index 8d6a2da8a..cd9804054 100644 --- a/mp/src/cmake/FindChoreoObjects.cmake +++ b/mp/src/cmake/FindChoreoObjects.cmake @@ -7,6 +7,7 @@ endif() find_file(CHOREO_OBJECTS_LIBRARY NAMES ${CHOREO_OBJECTS_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindDMXLoader.cmake b/mp/src/cmake/FindDMXLoader.cmake index 2e05945f9..9f695f8c9 100644 --- a/mp/src/cmake/FindDMXLoader.cmake +++ b/mp/src/cmake/FindDMXLoader.cmake @@ -7,6 +7,7 @@ endif() find_file(DMX_LOADER_LIBRARY NAMES ${DMX_LOADER_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindMatSysControls.cmake b/mp/src/cmake/FindMatSysControls.cmake index d814b1e9c..2bceb9472 100644 --- a/mp/src/cmake/FindMatSysControls.cmake +++ b/mp/src/cmake/FindMatSysControls.cmake @@ -7,6 +7,7 @@ endif() find_file(MATSYS_CONTROLS_LIBRARY NAMES ${MATSYS_CONTROLS_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindMathlib.cmake b/mp/src/cmake/FindMathlib.cmake index 70cdaf93e..c2793efa8 100644 --- a/mp/src/cmake/FindMathlib.cmake +++ b/mp/src/cmake/FindMathlib.cmake @@ -1,6 +1,7 @@ find_library(MATHLIB_LIBRARY NAMES mathlib.a PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindParticles.cmake b/mp/src/cmake/FindParticles.cmake index 3ad6de26d..4ff637716 100644 --- a/mp/src/cmake/FindParticles.cmake +++ b/mp/src/cmake/FindParticles.cmake @@ -7,6 +7,7 @@ endif() find_file(PARTICLES_LIBRARY NAMES ${PARTICLES_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindSteamAPI.cmake b/mp/src/cmake/FindSteamAPI.cmake index ba00c877f..e91b4090d 100644 --- a/mp/src/cmake/FindSteamAPI.cmake +++ b/mp/src/cmake/FindSteamAPI.cmake @@ -9,6 +9,7 @@ endif() find_file(STEAM_API_LIBRARY NAMES ${STEAM_API_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindTier0.cmake b/mp/src/cmake/FindTier0.cmake index 92d1aebb1..8f24ce0b2 100644 --- a/mp/src/cmake/FindTier0.cmake +++ b/mp/src/cmake/FindTier0.cmake @@ -9,6 +9,7 @@ endif() find_file(TIER0_LIBRARY NAMES ${TIER0_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindTier1.cmake b/mp/src/cmake/FindTier1.cmake index e115d8b43..15ea36b97 100644 --- a/mp/src/cmake/FindTier1.cmake +++ b/mp/src/cmake/FindTier1.cmake @@ -7,6 +7,7 @@ endif() find_library(TIER1_LIBRARY NAMES ${TIER1_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindTier2.cmake b/mp/src/cmake/FindTier2.cmake index 554eb3b49..36cca4b45 100644 --- a/mp/src/cmake/FindTier2.cmake +++ b/mp/src/cmake/FindTier2.cmake @@ -7,6 +7,7 @@ endif() find_library(TIER2_LIBRARY NAMES ${TIER2_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindTier3.cmake b/mp/src/cmake/FindTier3.cmake index 4a5c443b6..84b335423 100644 --- a/mp/src/cmake/FindTier3.cmake +++ b/mp/src/cmake/FindTier3.cmake @@ -7,6 +7,7 @@ endif() find_library(TIER3_LIBRARY NAMES ${TIER3_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindVGUIControls.cmake b/mp/src/cmake/FindVGUIControls.cmake index c3a18c309..f8a96665c 100644 --- a/mp/src/cmake/FindVGUIControls.cmake +++ b/mp/src/cmake/FindVGUIControls.cmake @@ -7,6 +7,7 @@ endif() find_file(VGUI_CONTROLS_LIBRARY NAMES ${VGUI_CONTROLS_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindVSTDLib.cmake b/mp/src/cmake/FindVSTDLib.cmake index 3d313bffd..378240328 100644 --- a/mp/src/cmake/FindVSTDLib.cmake +++ b/mp/src/cmake/FindVSTDLib.cmake @@ -9,6 +9,7 @@ endif() find_library(VSTDLIB_LIBRARY NAMES ${VSTDLIB_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/FindVTF.cmake b/mp/src/cmake/FindVTF.cmake index a7a1ab635..2b912eae8 100644 --- a/mp/src/cmake/FindVTF.cmake +++ b/mp/src/cmake/FindVTF.cmake @@ -7,6 +7,7 @@ endif() find_file(VTF_LIBRARY NAMES ${VTF_LIBRARY_NAME} PATHS "${LIBPUBLIC}" + NO_CACHE NO_DEFAULT_PATH REQUIRED ) diff --git a/mp/src/cmake/utils.cmake b/mp/src/cmake/utils.cmake index 01fc1ab7b..7671d8695 100644 --- a/mp/src/cmake/utils.cmake +++ b/mp/src/cmake/utils.cmake @@ -149,8 +149,9 @@ function(split_debug_information) SPLIT_DEBUG_INFO_FILE ${SPLITDEBUG_TARGET} ) - # Make sure the file is deleted on `make clean` - set_property(DIRECTORY APPEND - PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${SPLITDEBUG_TARGET} + # Make sure the file is deleted when cleaning + set_target_properties(${PARSED_ARGS_TARGET} + PROPERTIES + ADDITIONAL_CLEAN_FILES ${SPLITDEBUG_TARGET} ) endfunction()