1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 10:42:29 +01:00

Change cpp defines to CMakeVariables.h.in vars

This commit is contained in:
Elias Steurer 2023-11-09 10:32:28 +01:00
parent 0855928cef
commit 55996b2914
12 changed files with 109 additions and 93 deletions

View File

@ -1,5 +1,11 @@
#pragma once
#define SCREENPLAY_SOURCE_DIR "@SOURCE_DIR@"
#define SCREENPLAY_GODOT_VERSION "@GODOT_VERSION@"
#define SCREENPLAY_SOURCE_DIR "@SCREENPLAY_SOURCE_DIR@"
#define SCREENPLAY_GODOT_VERSION "@SCREENPLAY_GODOT_VERSION@"
#define SCREENPLAY_GODOT_RELEASE_TYPE "@SCREENPLAY_GODOT_RELEASE_TYPE@"
#define SCREENPLAY_BUILD_TYPE "@SCREENPLAY_BUILD_TYPE@"
#define SCREENPLAY_GIT_BRANCH_NAME "@SCREENPLAY_GIT_BRANCH_NAME@"
#define SCREENPLAY_GIT_COMMIT_HASH "@SCREENPLAY_GIT_COMMIT_HASH@"
#define SCREENPLAY_DEPLOY_VERSION @SCREENPLAY_DEPLOY_VERSION@
#define SCREENPLAY_BUILD_DATE "@SCREENPLAY_BUILD_DATE@"
#define SCREENPLAY_STEAM_VERSION @SCREENPLAY_STEAM_VERSION@

View File

@ -7,9 +7,23 @@
#
function(generate_cmake_variable_header TARGET)
# NOTE: Also add to CMakeVariables.h.in !
set(SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(SCREENPLAY_SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(SCREENPLAY_GODOT_VERSION ${GODOT_VERSION})
set(SCREENPLAY_GODOT_RELEASE_TYPE ${GODOT_RELEASE_TYPE})
set(SCREENPLAY_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
set(SCREENPLAY_BUILD_DATE "${BUILD_DATE}")
set(SCREENPLAY_GIT_BRANCH_NAME "${GIT_BRANCH_NAME}")
set(SCREENPLAY_GIT_COMMIT_HASH "${GIT_COMMIT_HASH}")
set(SCREENPLAY_DEPLOY_VERSION 0)
if(${SCREENPLAY_DEPLOY})
set(SCREENPLAY_DEPLOY_VERSION 1)
endif()
set(SCREENPLAY_STEAM_VERSION 0)
if(${SCREENPLAY_STEAM})
set(SCREENPLAY_STEAM_VERSION 1)
endif()
# Specify the configuration file from which the header file will be generated
configure_file(${CMAKE_SOURCE_DIR}/CMake/CMakeVariables.h.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/CMakeVariables.h @ONLY)

View File

@ -20,33 +20,12 @@ elseif(APPLE)
set(VCPKG_ARCH "64-osx-universal") # Our own triplet for universal binaries
set(VCPKG_TARGET_ARCHITECTURE "arm64;x86_64")
endif()
# Godot Editor
set(GODOT_VERSION "v4.2")
set(GODOT_RELEASE_TYPE "beta4")
if(WIN32)
set(GODOT_EDITOR_NAME "Godot_${GODOT_VERSION}-${GODOT_RELEASE_TYPE}_win64.exe")
elseif(APPLE)
set(GODOT_EDITOR_NAME "Godot.app")
elseif(UNIX)
set(GODOT_EDITOR_NAME "Godot_${GODOT_VERSION}-${GODOT_RELEASE_TYPE}_linux.x86_64")
else()
message(FATAL_ERROR "Unsupported OS")
endif()
# This sets cmake to compile all dlls into the main directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_CXX_STANDARD 20)
set(THIRD_PARTY_PATH "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/modules")
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/find-modules")
list(APPEND CMAKE_MODULE_PATH "${THIRD_PARTY_PATH}/ecm/kde-modules")
message(STATUS "[PROJECT] CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
option(OSX_BUNDLE "Enable distribution macOS bundle" OFF)
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0")
# This is needed for OSX: Because we bundle ScreenPlay and ScreenPlayWallpaper into .app they both need other QML dependencies like
@ -72,12 +51,27 @@ set(VCPKG_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../vcpkg")
set(VCPKG_INSTALLED_PATH "${VCPKG_PATH}/installed/${VCPKG_ARCH}")
set(VCPKG_BIN_PATH "${VCPKG_INSTALLED_PATH}/bin")
# Godot Editor
set(GODOT_VERSION "v4.2")
set(GODOT_RELEASE_TYPE "beta4")
if(WIN32)
set(GODOT_EDITOR_NAME "Godot_${GODOT_VERSION}-${GODOT_RELEASE_TYPE}_win64.exe")
elseif(APPLE)
set(GODOT_EDITOR_NAME "Godot.app")
elseif(UNIX)
set(GODOT_EDITOR_NAME "Godot_${GODOT_VERSION}-${GODOT_RELEASE_TYPE}_linux.x86_64")
else()
message(FATAL_ERROR "Unsupported OS")
endif()
option(SCREENPLAY_OSX_BUNDLE "Enable distribution macOS bundle" OFF)
option(SCREENPLAY_STEAM "For FOSS distribution so we do not bundle proprietary code." ON)
option(SCREENPLAY_DEPLOY "Marks this version as an official deploy version. This version uses different import paths and other settings."
OFF)
option(SCREENPLAY_TESTS "Enables UI tests." ON)
option(SCREENPLAY_INSTALLER "Indicates whether an installer via the Qt Installer Framework is created." OFF)
option(SCREENPLAY_GODOT_SUPPORT "Compiles ScreenPlayGodotWallpaper." OFF)
option(SCREENPLAY_GODOT "Compiles ScreenPlayGodotWallpaper." ON)
# Gitlab CI has many ENV variables. We use this one to check if the current build happens inside the CI
if(DEFINED ENV{CI_COMMIT_MESSAGE})
@ -86,13 +80,6 @@ endif()
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
add_compile_definitions(COMPILE_INFO="Build Date: ${BUILD_DATE}. Git Hash: ${GIT_COMMIT_HASH}. ")
add_compile_definitions(SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
if(${SCREENPLAY_DEPLOY})
add_compile_definitions(DEPLOY_VERSION)
endif()
find_package(Git REQUIRED)
if(WIN32)
@ -127,25 +114,21 @@ execute_process(
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_compile_definitions(BUILD_TYPE="${CMAKE_BUILD_TYPE}")
add_compile_definitions(BUILD_DATE="${BUILD_DATE}")
add_compile_definitions(GIT_BRANCH_NAME="${GIT_BRANCH_NAME}")
add_compile_definitions(GIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
add_subdirectory(ThirdParty)
set(ECM_DIR "${THIRD_PARTY_PATH}/ecm")
add_subdirectory(CMake)
if(${SCREENPLAY_TESTS})
enable_testing()
endif()
if(UNIX AND NOT APPLE)
# Needs to be append, because we include ecm as third party on linux
set(ECM_DIR "${THIRD_PARTY_PATH}/ecm")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
list(APPEND CMAKE_MODULE_PATH "${ECM_DIR}")
list(APPEND CMAKE_MODULE_PATH "${ECM_DIR}/cmake")
else()
endif()
add_subdirectory(ThirdParty)
add_subdirectory(CMake)
add_subdirectory(Tools)
add_subdirectory(ScreenPlay)
add_subdirectory(ScreenPlaySDK)
add_subdirectory(ScreenPlayShader)
@ -154,14 +137,10 @@ add_subdirectory(ScreenPlayWidget)
add_subdirectory(ScreenPlayUtil)
add_subdirectory(ScreenPlayWeather)
if(${SCREENPLAY_GODOT_SUPPORT})
if(${SCREENPLAY_GODOT})
add_subdirectory(ScreenPlayWallpaper/Godot)
endif()
if(${SCREENPLAY_TESTS})
enable_testing()
endif()
# Only add target SteamSDKQtEnums
add_subdirectory(ScreenPlayWorkshop/SteamSDK)
@ -181,6 +160,7 @@ if(${SCREENPLAY_INSTALLER})
endif()
endif()
message(STATUS "[PROJECT] CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
message(STATUS "[PROJECT] PROJECT_VERSION = ${PROJECT_VERSION}")
message(STATUS "[PROJECT] CMAKE_VERSION = ${CMAKE_VERSION}")
message(STATUS "[PROJECT] SCREENPLAY_QML_MODULES_PATH = ${SCREENPLAY_QML_MODULES_PATH}")
@ -195,7 +175,7 @@ message(STATUS "[OPTION] SCREENPLAY_DEPLOY = ${SCREENPLAY_DEPLOY}")
message(STATUS "[OPTION] SCREENPLAY_INSTALLER = ${SCREENPLAY_INSTALLER}")
message(STATUS "[OPTION] SCREENPLAY_STEAM = ${SCREENPLAY_STEAM}")
message(STATUS "[OPTION] SCREENPLAY_TESTS = ${SCREENPLAY_TESTS}")
message(STATUS "[OPTION] SCREENPLAY_GODOT_SUPPORT = ${SCREENPLAY_GODOT_SUPPORT}")
message(STATUS "[OPTION] SCREENPLAY_GODOT = ${SCREENPLAY_GODOT}")
message(STATUS "[DEFINE] BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message(STATUS "[DEFINE] GIT_COMMIT_HASH = ${GIT_COMMIT_HASH}")
message(STATUS "[CPP DEFINE] DEPLOY_VERSION = ${DEPLOY_VERSION}")

View File

@ -73,6 +73,17 @@
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "windows-release-qt-6.6.0-release-deploy",
"inherits": "windows-release-qt-6.6.0",
"displayName": "MSVC SP Qt 6.6.0 Release Steam Deploy",
"binaryDir": "${sourceDir}/../build_ScreenPlay_Qt_6.6.0_MSVC_Release_Steam_Deploy",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"SCREENPLAY_DEPLOY": "ON",
"SCREENPLAY_STEAM": "ON"
}
},
{
"name": "linux-generic-debug",
"displayName": "ScreenPlay 64bit Debug Linux",

View File

@ -5,6 +5,9 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
# ##### USE CMAKE VARIABLES IN CODE #####
include(GenerateCMakeVariableHeader)
set(SOURCES
# cmake-format: sort
src/app.cpp
@ -319,13 +322,14 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ScreenPlayApp ScreenPlayAppplugin)
if(${SCREENPLAY_TESTS})
add_executable(tst_ScreenPlay tests/tst_main.cpp)
target_link_libraries(tst_ScreenPlay PRIVATE ScreenPlayApp ScreenPlayAppplugin Qt6::Test)
generate_cmake_variable_header(tst_ScreenPlay)
if(${SCREENPLAY_STEAM})
target_compile_definitions(tst_ScreenPlay PRIVATE SCREENPLAY_STEAM)
target_link_libraries(tst_ScreenPlay PUBLIC ScreenPlayWorkshopplugin ScreenPlayWorkshop)
endif()
endif()
if(APPLE AND NOT OSX_BUNDLE)
if(APPLE AND NOT SCREENPLAY_OSX_BUNDLE)
set_source_files_properties(
${TS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/translations")
else()
@ -376,7 +380,7 @@ if(WIN32)
endif()
if(APPLE AND OSX_BUNDLE)
if(APPLE AND SCREENPLAY_OSX_BUNDLE)
# Set the installation destination
install(TARGETS "ScreenPlay" DESTINATION /Applications)
@ -399,7 +403,7 @@ if(APPLE AND OSX_BUNDLE)
endif()
if(APPLE AND NOT OSX_BUNDLE)
if(APPLE AND NOT SCREENPLAY_OSX_BUNDLE)
# Creates a ScreenPlay.app
set_target_properties(
${PROJECT_NAME}
@ -447,7 +451,6 @@ if(APPLE AND NOT OSX_BUNDLE)
endif()
# ##### USE CMAKE VARIABLES IN CODE #####
include(GenerateCMakeVariableHeader)
# Note: Must not be ${PROJECT_NAME}, but ScreenPlayApp to work!
# Note: We need the variables in the lib and exe!
generate_cmake_variable_header(${PROJECT_NAME})
generate_cmake_variable_header(ScreenPlayApp)

View File

@ -1,5 +1,6 @@
// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#include "ScreenPlay/CMakeVariables.h"
#include "ScreenPlay/app.h"
#include "ScreenPlayUtil/logginghandler.h"
#include <QCommandLineParser>
@ -27,13 +28,13 @@ int main(int argc, char* argv[])
#endif
QGuiApplication qtGuiApp(argc, argv);
std::unique_ptr<const ScreenPlayUtil::LoggingHandler> logging;
ScreenPlay::App app;
if (app.m_isAnotherScreenPlayInstanceRunning) {
return 0;
} else {
logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlay");
}
auto logging = std::make_unique<const ScreenPlayUtil::LoggingHandler>("ScreenPlay");
app.init();
const int status = qtGuiApp.exec();
#if defined(Q_OS_WIN)
@ -41,5 +42,4 @@ int main(int argc, char* argv[])
#endif
logging.reset();
return status;
}
}

View File

@ -235,11 +235,12 @@ void InstalledListModel::loadInstalledContent()
counter += 1;
}
};
#ifdef DEPLOY_VERSION
const QString defaultContentPath = QGuiApplication::instance()->applicationDirPath() + "/Content";
#else
const QString defaultContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
#endif
QString defaultContentPath;
if (SCREENPLAY_DEPLOY_VERSION) {
defaultContentPath = QGuiApplication::instance()->applicationDirPath() + "/Content";
} else {
defaultContentPath = QString(SCREENPLAY_SOURCE_DIR) + "/Content";
}
if (m_settings->showDefaultContent()) {
loadFiles(defaultContentPath);
}

View File

@ -48,13 +48,14 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
, m_globalVariables { globalVariables }
{
const QString qtVersion = QString("Qt Version: %1.%2.%3\n").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH);
const QString buildType = QString("Build type: %1\n").arg(BUILD_TYPE);
const QString buildDate = QString("Build date: %1\n").arg(BUILD_DATE);
const QString commitHash = QString("Git commit hash: %1").arg(GIT_COMMIT_HASH);
setBuildInfos(qtVersion + buildType + buildDate + commitHash);
#ifdef SCREENPLAY_STEAM
setSteamVersion(true);
#endif
const QString buildType = QString("Build type: %1\n").arg(QString(SCREENPLAY_BUILD_TYPE));
const QString buildDate = QString("Build date: %1\n").arg(QString(SCREENPLAY_BUILD_DATE));
const QString commitHash = QString("Git commit hash: %1\n").arg(QString(SCREENPLAY_GIT_COMMIT_HASH));
const QString isDeployVersion = QString("Is deploy version: %1\n").arg((SCREENPLAY_DEPLOY_VERSION ? QString("✅ Yes") : QString("❌ No")));
const QString isSteamVersion = QString("Is steam version: %1").arg((SCREENPLAY_STEAM_VERSION ? QString("✅ Yes") : QString("❌ No")));
setBuildInfos(qtVersion + buildType + buildDate + commitHash + isDeployVersion + isSteamVersion);
setSteamVersion(SCREENPLAY_STEAM);
#ifdef Q_OS_WIN
setDesktopEnvironment(DesktopEnvironment::Windows);
@ -74,7 +75,7 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
qmlRegisterUncreatableType<Settings>("Settings", 1, 0, "Settings", "Error only for enums");
// Lets not set the dev version as startup.
#ifdef DEPLOY_VERSION
if (SCREENPLAY_DEPLOY_VERSION)
if (desktopEnvironment() == DesktopEnvironment::Windows) {
QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
if (!settings.childGroups().contains("ScreenPlay", Qt::CaseSensitive)) {
@ -87,8 +88,6 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
}
}
#endif
setCheckWallpaperVisible(m_qSettings.value("CheckWallpaperVisible", false).toBool());
setHighPriorityStart(m_qSettings.value("ScreenPlayExecutable", false).toBool());
if (m_qSettings.contains("VideoFillMode")) {

View File

@ -3,6 +3,8 @@
#include "ScreenPlay/app.h"
#include "ScreenPlay/create.h"
#include "ScreenPlay/CMakeVariables.h"
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDebug>
@ -100,7 +102,7 @@ void ScreenPlayTest::import_convert_video()
auto* createWallpaperInit = m_window->findChild<QQuickItem*>("createWallpaperInit");
QVERIFY(createWallpaperInit);
const QString originalVideoPath = QString(SOURCE_DIR) + "/ScreenPlay/assets/tests/video_import.mp4";
const QString originalVideoPath = QString(SCREENPLAY_SOURCE_DIR) + "/ScreenPlay/assets/tests/video_import.mp4";
qInfo() << originalVideoPath;
QVERIFY(QMetaObject::invokeMethod(createWallpaperInit,

View File

@ -117,7 +117,7 @@ endif()
if(APPLE)
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Cocoa")
if(NOT OSX_BUNDLE)
if(NOT SCREENPLAY_OSX_BUNDLE)
add_custom_command(
TARGET ${PROJECT_NAME}
POST_BUILD

View File

@ -76,7 +76,7 @@ if(WIN32)
set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE true)
endif()
if(APPLE AND NOT OSX_BUNDLE)
if(APPLE AND NOT SCREENPLAY_OSX_BUNDLE)
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/ScreenPlay.app/Contents/MacOS/")
endif()

View File

@ -122,7 +122,7 @@ qt_add_qml_module(
${RESOURCES})
if(${SCREENPLAY_STEAM})
if(APPLE AND NOT OSX_BUNDLE)
if(APPLE AND NOT SCREENPLAY_OSX_BUNDLE)
set(MACOS_FRAMEWORKS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ScreenPlay.app/Contents/MacOS/)
file(MAKE_DIRECTORY ${MACOS_FRAMEWORKS_DIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/steam_appid.txt ${MACOS_FRAMEWORKS_DIR} COPYONLY)