From d26590c38eb83b04bdc3c07ef5987aa6a2e42fd0 Mon Sep 17 00:00:00 2001 From: Mathias Gibbens Date: Fri, 8 Jan 2021 21:08:30 +0000 Subject: [PATCH] Fix cmake compile_definitions edge case (#13732) If cmake variables contain just empty strings, don't add them to the compile definitions, as this can result in incorrect version strings in the compiled program Signed-off-by: Mathias Gibbens Co-authored-by: Mathias Gibbens --- src/openrct2/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/openrct2/CMakeLists.txt b/src/openrct2/CMakeLists.txt index aff74307f9..25c02d64a2 100644 --- a/src/openrct2/CMakeLists.txt +++ b/src/openrct2/CMakeLists.txt @@ -207,17 +207,19 @@ include_directories(${PROJECT_NAME} SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../thirdpar # To avoid unnecessary rebuilds set the current branch and # short sha1 only for the two files that use these # definitions: Version.cpp and Crash/Platform.cpp -set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp - PROPERTY COMPILE_DEFINITIONS - OPENRCT2_VERSION_TAG="${OPENRCT2_VERSION_TAG}") +if (NOT OPENRCT2_VERSION_TAG STREQUAL "") + set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp + PROPERTY COMPILE_DEFINITIONS + OPENRCT2_VERSION_TAG="${OPENRCT2_VERSION_TAG}") +endif() -if (NOT OPENRCT2_BRANCH STREQUAL "master") +if (NOT OPENRCT2_BRANCH STREQUAL "master" AND NOT OPENRCT2_BRANCH STREQUAL "") set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp APPEND PROPERTY COMPILE_DEFINITIONS OPENRCT2_BRANCH="${OPENRCT2_BRANCH}") endif() -if (NOT OPENRCT2_COMMIT_SHA1_SHORT STREQUAL "HEAD") +if (NOT OPENRCT2_COMMIT_SHA1_SHORT STREQUAL "HEAD" AND NOT OPENRCT2_COMMIT_SHA1_SHORT STREQUAL "") set_property(SOURCE ${CMAKE_CURRENT_LIST_DIR}/Version.cpp ${CMAKE_CURRENT_LIST_DIR}/Crash/Platform.cpp APPEND PROPERTY COMPILE_DEFINITIONS OPENRCT2_COMMIT_SHA1_SHORT="${OPENRCT2_COMMIT_SHA1_SHORT}")