From aeb3a83293587342ea4bd59cc6ea0921c4633ce3 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Wed, 28 Apr 2021 18:19:04 +1000 Subject: [PATCH] cmake: compile git hash into separate object Should improve incremental compile speeds --- CMakeLists.txt | 6 ------ app/CMakeLists.txt | 12 ++++++++++++ app/crashhandler/CMakeLists.txt | 1 + app/crashhandler/crashhandler.cpp | 3 ++- app/main.cpp | 13 +++++++------ app/version.cpp | 31 ++++++++++++++++++++++++++++++ app/version.h | 32 +++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 app/version.cpp create mode 100644 app/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a937ae93c..4be2eac0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,12 +165,6 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git") ) endif() endif() -if(DEFINED GIT_HASH) - message("Olive: Git hash = " "${GIT_HASH}") - list(APPEND OLIVE_DEFINITIONS -DGITHASH="${GIT_HASH}") -else() - message("Olive: No Git hash defined!") -endif() # Optional: Find Doxygen if requested if(BUILD_DOXYGEN) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index fc80a04ab..d656a674e 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -59,6 +59,17 @@ set(OLIVE_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/ts/translations.qrc ) +# Add version object +add_library(olive-version-obj + OBJECT + version.cpp + version.h +) +target_link_libraries(olive-version-obj PRIVATE Qt5::Core) +if(DEFINED GIT_HASH) + target_compile_options(olive-version-obj PRIVATE -DGITHASH="${GIT_HASH}") +endif() + # Add main library add_library(libolive-editor OBJECT @@ -73,6 +84,7 @@ set_target_properties(libolive-editor PROPERTIES PREFIX "") add_executable(olive-editor main.cpp $ + $ ) # Create docs if doxygen was found diff --git a/app/crashhandler/CMakeLists.txt b/app/crashhandler/CMakeLists.txt index a669d40b1..e05972a24 100644 --- a/app/crashhandler/CMakeLists.txt +++ b/app/crashhandler/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable( olive-crashhandler crashhandler.cpp crashhandler.h + $ ) # Disable console appearing on crash handler dialog diff --git a/app/crashhandler/crashhandler.cpp b/app/crashhandler/crashhandler.cpp index f23cae312..d0fbeda60 100644 --- a/app/crashhandler/crashhandler.cpp +++ b/app/crashhandler/crashhandler.cpp @@ -38,6 +38,7 @@ #include "common/crashpadutils.h" #include "common/filefunctions.h" +#include "version.h" namespace olive { @@ -227,7 +228,7 @@ void CrashHandlerDialog::SendErrorReport() QHttpPart commit_part; commit_part.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("text/plain; charset=UTF-8")); commit_part.setHeader(QNetworkRequest::ContentDispositionHeader, QStringLiteral("form-data; name=\"commit\"")); - commit_part.setBody(GITHASH); + commit_part.setBody(kGitHash); multipart->append(commit_part); // Create dump section diff --git a/app/main.cpp b/app/main.cpp index c96681865..38bdc6bf6 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -40,6 +40,7 @@ extern "C" { #include "core.h" #include "common/commandlineparser.h" #include "common/debug.h" +#include "version.h" #ifdef USE_CRASHPAD #include "common/crashpadinterface.h" @@ -52,12 +53,12 @@ int main(int argc, char *argv[]) // Generate version string QString app_version = APPVERSION; -#ifdef GITHASH - // Anything after the hyphen is considered "unimportant" information. Text BEFORE the hyphen is used in version - // checking project files and config files - app_version.append("-"); - app_version.append(GITHASH); -#endif + if (!olive::kGitHash.isEmpty()) { + // Anything after the hyphen is considered "unimportant" information. Text BEFORE the hyphen is + // used in version checking project files and config files + app_version.append("-"); + app_version.append(olive::kGitHash); + } // Set application metadata QCoreApplication::setOrganizationName("olivevideoeditor.org"); diff --git a/app/version.cpp b/app/version.cpp new file mode 100644 index 000000000..a87e1c7e8 --- /dev/null +++ b/app/version.cpp @@ -0,0 +1,31 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#include "version.h" + +namespace olive { + +#ifdef GITHASH +QString kGitHash = QStringLiteral(GITHASH); +#else +QString kGitHash; +#endif + +} diff --git a/app/version.h b/app/version.h new file mode 100644 index 000000000..6c4d126cf --- /dev/null +++ b/app/version.h @@ -0,0 +1,32 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2021 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef GITHASH_H +#define GITHASH_H + +#include + +namespace olive { + +extern QString kGitHash; + +} + +#endif // GITHASH_H