Define Git and date constants in executables only (#4681)

This commit is contained in:
nerix
2023-06-17 19:43:39 +02:00
committed by GitHub
parent aff9342647
commit 4b40b9a310
7 changed files with 78 additions and 43 deletions
+21 -22
View File
@@ -1,4 +1,5 @@
set(LIBRARY_PROJECT "${PROJECT_NAME}-lib")
set(VERSION_PROJECT "${LIBRARY_PROJECT}-version")
set(EXECUTABLE_PROJECT "${PROJECT_NAME}")
add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x050F00)
@@ -46,8 +47,6 @@ set(SOURCE_FILES
common/NetworkResult.hpp
common/QLogging.cpp
common/QLogging.hpp
common/Version.cpp
common/Version.hpp
common/WindowDescriptors.cpp
common/WindowDescriptors.hpp
@@ -799,15 +798,26 @@ set_target_properties(${LIBRARY_PROJECT}
AUTOUIC ON
)
# Used to provide a date of build in the About page (for nightly builds). Getting the actual time of
# compilation in CMake is a more involved, as documented in https://stackoverflow.com/q/24292898.
# For CI runs, however, the date of build file generation should be consistent with the date of
# compilation so this approximation is "good enough" for our purpose.
if (DEFINED ENV{CHATTERINO_SKIP_DATE_GEN})
set(cmake_gen_date "1970-01-01")
else ()
string(TIMESTAMP cmake_gen_date "%Y-%m-%d")
endif ()
# The version project has definitions about the build.
# To avoid recompilations because of changing preprocessor definitions,
# this is its own project.
set(VERSION_SOURCE_FILES common/Version.cpp common/Version.hpp)
add_library(${VERSION_PROJECT} STATIC ${VERSION_SOURCE_FILES})
# source group for IDEs
source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${VERSION_SOURCE_FILES})
target_include_directories(${VERSION_PROJECT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${VERSION_PROJECT} PRIVATE Qt${MAJOR_QT_VERSION}::Core)
target_compile_definitions(${VERSION_PROJECT} PRIVATE
CHATTERINO_GIT_HASH=\"${GIT_HASH}\"
CHATTERINO_GIT_RELEASE=\"${GIT_RELEASE}\"
CHATTERINO_GIT_COMMIT=\"${GIT_COMMIT}\"
CHATTERINO_GIT_MODIFIED=${GIT_MODIFIED}
CHATTERINO_CMAKE_GEN_DATE=\"${cmake_gen_date}\"
)
target_link_libraries(${LIBRARY_PROJECT} PRIVATE ${VERSION_PROJECT})
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CHATTERINO
@@ -815,18 +825,7 @@ target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
AB_CUSTOM_SETTINGS
IRC_STATIC
IRC_NAMESPACE=Communi
CHATTERINO_GIT_HASH=\"${GIT_HASH}\"
CHATTERINO_GIT_RELEASE=\"${GIT_RELEASE}\"
CHATTERINO_GIT_COMMIT=\"${GIT_COMMIT}\"
CHATTERINO_CMAKE_GEN_DATE=\"${cmake_gen_date}\"
)
if (GIT_MODIFIED)
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CHATTERINO_GIT_MODIFIED
)
endif ()
if (USE_SYSTEM_QTKEYCHAIN)
target_compile_definitions(${LIBRARY_PROJECT} PUBLIC
CMAKE_BUILD