From 7363a04d5db8a46b2b65808e738f5abd5c1fac55 Mon Sep 17 00:00:00 2001 From: Masterkatze Date: Wed, 20 Mar 2024 17:05:08 +0300 Subject: [PATCH] Specify quotes in target_compile_definitions properly, fix potential issue with set_git_info --- cmake/utils.cmake | 4 ++-- src/xrCore/.GitInfo.cmd | 8 ++++---- src/xrCore/CMakeLists.txt | 14 +++++++------- src/xrCore/LocatorAPI.cpp | 2 +- src/xrCore/Threading/Lock.hpp | 1 + src/xrCore/xrCore.cpp | 23 ++++++++++++++--------- src/xrCore/xrCore.vcxproj | 2 +- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index b85beb3b043..bcb7f46f4f1 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -24,7 +24,7 @@ function(target_sources_grouped) source_group(${PARSED_ARGS_NAME} FILES ${PARSED_ARGS_FILES}) endfunction() -function(set_git_info) +macro(set_git_info) execute_process(COMMAND git rev-parse --verify HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE GIT_SHA1 @@ -40,7 +40,7 @@ function(set_git_info) OUTPUT_STRIP_TRAILING_WHITESPACE ) message(STATUS "git branch: ${GIT_BRANCH}") -endfunction() +endmacro() function(calculate_xray_build_id output) set(XRAY_START_DAY 31) diff --git a/src/xrCore/.GitInfo.cmd b/src/xrCore/.GitInfo.cmd index 63a571cd495..90e12457c57 100644 --- a/src/xrCore/.GitInfo.cmd +++ b/src/xrCore/.GitInfo.cmd @@ -1,5 +1,5 @@ -echo | set /p dummyName=#define GIT_INFO_CURRENT_COMMIT > .GitInfo.hpp -git rev-parse --verify HEAD >> .GitInfo.hpp +@FOR /f "delims=" %%i in ('git rev-parse --verify HEAD') DO set COMMIT=%%i +echo #define GIT_INFO_CURRENT_COMMIT "%COMMIT%" > .GitInfo.hpp -echo | set /p dummyName=#define GIT_INFO_CURRENT_BRANCH >> .GitInfo.hpp -git rev-parse --abbrev-ref HEAD >> .GitInfo.hpp +@FOR /f "delims=" %%i in ('git rev-parse --abbrev-ref HEAD') DO set BRANCH=%%i +echo #define GIT_INFO_CURRENT_BRANCH "%BRANCH%" >> .GitInfo.hpp diff --git a/src/xrCore/CMakeLists.txt b/src/xrCore/CMakeLists.txt index 83085473c2a..7c2874d306d 100644 --- a/src/xrCore/CMakeLists.txt +++ b/src/xrCore/CMakeLists.txt @@ -464,15 +464,15 @@ endif() target_compile_definitions(xrCore PRIVATE XRCORE_EXPORTS - CMAKE_INSTALL_FULL_LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR} - CMAKE_INSTALL_FULL_DATAROOTDIR=${CMAKE_INSTALL_FULL_DATAROOTDIR} + CMAKE_INSTALL_FULL_LIBDIR=\"${CMAKE_INSTALL_FULL_LIBDIR}\" + CMAKE_INSTALL_FULL_DATAROOTDIR=\"${CMAKE_INSTALL_FULL_DATAROOTDIR}\" CI=$ENV{CI} GITHUB_ACTIONS=$ENV{GITHUB_ACTIONS} - GITHUB_RUN_ID=$ENV{GITHUB_RUN_ID} - GITHUB_RUN_NUMBER=$ENV{GITHUB_RUN_NUMBER} - GITHUB_REPOSITORY=$ENV{GITHUB_REPOSITORY} - GIT_INFO_CURRENT_COMMIT=${GIT_SHA1} - GIT_INFO_CURRENT_BRANCH=${GIT_BRANCH} + GITHUB_RUN_ID=\"$ENV{GITHUB_RUN_ID}\" + GITHUB_RUN_NUMBER=\"$ENV{GITHUB_RUN_NUMBER}\" + GITHUB_REPOSITORY=\"$ENV{GITHUB_REPOSITORY}\" + GIT_INFO_CURRENT_COMMIT=\"${GIT_SHA1}\" + GIT_INFO_CURRENT_BRANCH=\"${GIT_BRANCH}\" ) if (MEMORY_ALLOCATOR STREQUAL "mimalloc") diff --git a/src/xrCore/LocatorAPI.cpp b/src/xrCore/LocatorAPI.cpp index b14f56bb490..ef8f9ce7db5 100644 --- a/src/xrCore/LocatorAPI.cpp +++ b/src/xrCore/LocatorAPI.cpp @@ -845,7 +845,7 @@ void CLocatorAPI::setup_fs_path(pcstr fs_name) * I propose adding shaders from /openxray/gamedata/shaders so that we remove unnecessary questions from users who want to start * the game using resources not from the proposed ~/.local/share/GSC Game World/Game in this case, this section of code can be safely removed */ chdir(pref_path); - static constexpr pcstr install_dir = MACRO_TO_STRING(CMAKE_INSTALL_FULL_DATAROOTDIR); + static constexpr pcstr install_dir = CMAKE_INSTALL_FULL_DATAROOTDIR; string_path tmp, tmp_link; xr_sprintf(tmp, "%sfsgame.ltx", pref_path); struct stat statbuf; diff --git a/src/xrCore/Threading/Lock.hpp b/src/xrCore/Threading/Lock.hpp index c9474fb8213..ddc0234cd78 100644 --- a/src/xrCore/Threading/Lock.hpp +++ b/src/xrCore/Threading/Lock.hpp @@ -4,6 +4,7 @@ #include "Common/Noncopyable.hpp" #ifdef CONFIG_PROFILE_LOCKS +#include "xrCore.h" typedef void (*add_profile_portion_callback)(LPCSTR id, const u64& time); void XRCORE_API set_add_profile_portion(add_profile_portion_callback callback); diff --git a/src/xrCore/xrCore.cpp b/src/xrCore/xrCore.cpp index 42bdb0bf71f..a5da98c6221 100644 --- a/src/xrCore/xrCore.cpp +++ b/src/xrCore/xrCore.cpp @@ -62,8 +62,8 @@ static u32 init_counter = 0; void SDLLogOutput(void* userdata, int category, SDL_LogPriority priority, const char* message); const pcstr xrCore::buildDate = __DATE__; -const pcstr xrCore::buildCommit = MACRO_TO_STRING(GIT_INFO_CURRENT_COMMIT); -const pcstr xrCore::buildBranch = MACRO_TO_STRING(GIT_INFO_CURRENT_BRANCH); +const pcstr xrCore::buildCommit = GIT_INFO_CURRENT_COMMIT; +const pcstr xrCore::buildBranch = GIT_INFO_CURRENT_BRANCH; xrCore::xrCore() : ApplicationName{}, ApplicationPath{}, @@ -117,14 +117,14 @@ void xrCore::PrintBuildInfo() #if defined(CI) # if defined(APPVEYOR) name = "AppVeyor"; - buildUniqueId = MACRO_TO_STRING(APPVEYOR_BUILD_ID); - buildId = MACRO_TO_STRING(APPVEYOR_BUILD_VERSION); - builder = MACRO_TO_STRING(APPVEYOR_ACCOUNT_NAME); + buildUniqueId = APPVEYOR_BUILD_ID; + buildId = APPVEYOR_BUILD_VERSION; + builder = APPVEYOR_ACCOUNT_NAME; # elif defined(GITHUB_ACTIONS) name = "GitHub Actions"; - buildUniqueId = MACRO_TO_STRING(GITHUB_RUN_ID); - buildId = MACRO_TO_STRING(GITHUB_RUN_NUMBER); - builder = MACRO_TO_STRING(GITHUB_REPOSITORY); + buildUniqueId = GITHUB_RUN_ID; + buildId = GITHUB_RUN_NUMBER; + builder = GITHUB_REPOSITORY; #else # pragma TODO("PrintBuildInfo for other CIs") name = "CI"; @@ -271,8 +271,13 @@ void xrCore::Initialize(pcstr _ApplicationName, pcstr commandLine, LogCallback c flags &= ~CLocatorAPI::flCacheFiles; #endif // _EDITOR - if (xr_stricmp(ApplicationPath, MACRO_TO_STRING(CMAKE_INSTALL_FULL_DATAROOTDIR)) != 0) +// TODO Add proper check for CMake Windows build +#if defined(XR_PLATFORM_LINUX) || defined(XR_PLATFORM_BSD) || defined(XR_PLATFORM_APPLE) + if (xr_stricmp(ApplicationPath, CMAKE_INSTALL_FULL_DATAROOTDIR) != 0) flags |= CLocatorAPI::flScanAppRoot; +#endif + + #ifndef _EDITOR #ifndef ELocatorAPIH diff --git a/src/xrCore/xrCore.vcxproj b/src/xrCore/xrCore.vcxproj index a8f7dd0af87..c31c6f74cf1 100644 --- a/src/xrCore/xrCore.vcxproj +++ b/src/xrCore/xrCore.vcxproj @@ -23,7 +23,7 @@ $(xrExternals)lzo\include;$(xrSdkDir)include\mimalloc;%(AdditionalIncludeDirectories) - _USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_ID=$(APPVEYOR_BUILD_ID);APPVEYOR_BUILD_VERSION=$(APPVEYOR_BUILD_VERSION);APPVEYOR_ACCOUNT_NAME=$(APPVEYOR_ACCOUNT_NAME);GITHUB_ACTIONS=$(GITHUB_ACTIONS);GITHUB_RUN_ID=$(GITHUB_RUN_ID);GITHUB_RUN_NUMBER=$(GITHUB_RUN_NUMBER);GITHUB_REPOSITORY=$(GITHUB_REPOSITORY);%(PreprocessorDefinitions) + _USRDLL;XRCORE_EXPORTS;CRYPTO_BUILD;CI=$(CI);APPVEYOR=$(APPVEYOR);APPVEYOR_BUILD_ID="$(APPVEYOR_BUILD_ID)";APPVEYOR_BUILD_VERSION="$(APPVEYOR_BUILD_VERSION)";APPVEYOR_ACCOUNT_NAME="$(APPVEYOR_ACCOUNT_NAME)";GITHUB_ACTIONS=$(GITHUB_ACTIONS);GITHUB_RUN_ID="$(GITHUB_RUN_ID)";GITHUB_RUN_NUMBER="$(GITHUB_RUN_NUMBER)";GITHUB_REPOSITORY="$(GITHUB_REPOSITORY)";%(PreprocessorDefinitions) DbgHelp.lib;FaultRep.lib;jpeg-static.lib;%(AdditionalDependencies)