Skip to content

Commit

Permalink
cmake: Prefix all custom variables
Browse files Browse the repository at this point in the history
Generally, it is a good idea to prefix variables in CMake as subscripts can
accidentally use them. PROJECT_VERSION is a variable created by project()
call if you call with the VERSION argument, so it probably shouldn't be created
manually.

The specific reason for this change is to work around this bug:
https://bugreports.qt.io/browse/QTBUG-132421
  • Loading branch information
syyyr committed Dec 23, 2024
1 parent b6aa6a4 commit 6a0d7ae
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
40 changes: 20 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(ANDROID_OPENSSL_PATH "${ANDROID_SDK_ROOT}/android_openssl/ssl_3" CACHE STRING "Path to the folder with https://github.com/KDAB/android_openssl.git")
endif()

set(VERSION "0.0.0" CACHE STRING "This is where we start working with the version string as passed from the build script")
set(VERSION_RELEASEDATE "1970-01-01" CACHE STRING "Release date to be used in metadata, used in Linux appdata only for now.")
set(LITH_VERSION "0.0.0" CACHE STRING "This is where we start working with the version string as passed from the build script")
set(LITH_VERSION_RELEASEDATE "1970-01-01" CACHE STRING "Release date to be used in metadata, used in Linux appdata only for now.")

find_package(Git REQUIRED)
# rerun git metadata retrieval on each commit message change
Expand All @@ -57,13 +57,13 @@ set_property(
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE COMMIT_HASH
OUTPUT_VARIABLE LITH_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_STATE
OUTPUT_VARIABLE LITH_GIT_STATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
Expand All @@ -79,29 +79,29 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (VERSION AND NOT "${VERSION}" STREQUAL "0.0.0")
set(PROJECT_VERSION ${VERSION} CACHE STRING "" FORCE)
if (NOT "${VERSION_RELEASEDATE}" STREQUAL "1970-01-01")
set(PROJECT_VERSION_RELEASEDATE "${VERSION_RELEASEDATE}" CACHE STRING "" FORCE)
if (LITH_VERSION AND NOT "${LITH_VERSION}" STREQUAL "0.0.0")
set(LITH_PROJECT_VERSION ${LITH_VERSION} CACHE STRING "" FORCE)
if (NOT "${LITH_VERSION_RELEASEDATE}" STREQUAL "1970-01-01")
set(LITH_PROJECT_VERSION_RELEASEDATE "${LITH_VERSION_RELEASEDATE}" CACHE STRING "" FORCE)
else()
message("Release date was not supplied but version was, metadata will show today")
string(TIMESTAMP PROJECT_VERSION_RELEASEDATE "%Y-%m-%d")
string(TIMESTAMP LITH_PROJECT_VERSION_RELEASEDATE "%Y-%m-%d")
endif()
message("Building Lith version ${PROJECT_VERSION}, release date: ${PROJECT_VERSION_RELEASEDATE}")
message("Building Lith version ${LITH_PROJECT_VERSION}, release date: ${LITH_PROJECT_VERSION_RELEASEDATE}")
elseif(GIT_LAST_TAG)
set(PROJECT_VERSION "${GIT_LAST_TAG}" CACHE STRING "" FORCE)
set(PROJECT_VERSION_RELEASEDATE "${GIT_LAST_TAG_DATE}" CACHE STRING "" FORCE)
message("Version passed to CMake was empty, using last one retrieved from git: ${PROJECT_VERSION}, tagged on ${PROJECT_VERSION_RELEASEDATE}")
set(LITH_PROJECT_VERSION "${GIT_LAST_TAG}" CACHE STRING "" FORCE)
set(LITH_PROJECT_VERSION_RELEASEDATE "${GIT_LAST_TAG_DATE}" CACHE STRING "" FORCE)
message("Version passed to CMake was empty, using last one retrieved from git: ${LITH_PROJECT_VERSION}, tagged on ${LITH_PROJECT_VERSION_RELEASEDATE}")
else()
set(PROJECT_VERSION "0.0.0" CACHE STRING "" FORCE)
set(PROJECT_VERSION_RELEASEDATE "1970-01-01" CACHE STRING "" FORCE)
message(WARNING "Version passed to CMake was empty, this may have been done on accident, using ${PROJECT_VERSION}")
set(LITH_PROJECT_VERSION "0.0.0" CACHE STRING "" FORCE)
set(LITH_PROJECT_VERSION_RELEASEDATE "1970-01-01" CACHE STRING "" FORCE)
message(WARNING "Version passed to CMake was empty, this may have been done on accident, using ${LITH_PROJECT_VERSION}")
endif()

string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)
string(REPLACE "." ";" VERSION_LIST ${LITH_PROJECT_VERSION})
list(GET VERSION_LIST 0 LITH_PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 LITH_PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 LITH_PROJECT_VERSION_PATCH)

if(CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL Profile)
set(LITH_IS_DEBUG_BUILD ON CACHE STRING "")
Expand Down
4 changes: 2 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ set_target_properties(Lith PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE_GUI_IDENTIFIER cz.rtinbriza.ma.Lith
MACOSX_BUNDLE_BUNDLE_NAME Lith
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
MACOSX_BUNDLE_BUNDLE_VERSION ${LITH_PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${LITH_PROJECT_VERSION}
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/dist/ios/Info.plist.in"
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_WEAK YES
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER cz.rtinbriza.ma.Lith
Expand Down
8 changes: 4 additions & 4 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ int main(int argc, char* argv[]) {
QCoreApplication::setOrganizationName("Lith");
QCoreApplication::setOrganizationDomain("lith.app");
QCoreApplication::setApplicationName("Lith");
if (QStringLiteral(PROJECT_VERSION) == QStringLiteral("0.0.0")) {
if (QStringLiteral(GIT_STATE).isEmpty()) {
if (QStringLiteral(LITH_PROJECT_VERSION) == QStringLiteral("0.0.0")) {
if (QStringLiteral(LITH_GIT_STATE).isEmpty()) {
QCoreApplication::setApplicationVersion(QStringLiteral(
"Unknown version, please report this to https://github.com/LithApp/Lith and mention your platform and where you got this package."
));
} else {
QCoreApplication::setApplicationVersion(QStringLiteral(GIT_STATE));
QCoreApplication::setApplicationVersion(QStringLiteral(LITH_GIT_STATE));
}
} else {
QCoreApplication::setApplicationVersion(QStringLiteral(PROJECT_VERSION));
QCoreApplication::setApplicationVersion(QStringLiteral(LITH_PROJECT_VERSION));
}

QApplication app(argc, argv);
Expand Down
2 changes: 1 addition & 1 deletion dist/android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi

export QT_HOST_PATH="${QT_ROOT_DIR}/../gcc_64"
export CMAKE_PREFIX_PATH=${QT_ROOT_DIR}/lib/cmake
cmake .. -DQT_DEBUG_FIND_PACKAGE=ON -DCMAKE_BUILD_TYPE=Release -DIMGUR_API_KEY=$IMGUR_API_KEY -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake -DANDROID_OPENSSL_PATH="${ANDROID_OPENSSL_PATH}" -DQT_ANDROID_BUILD_ALL_ABIS=ON
cmake .. -DQT_DEBUG_FIND_PACKAGE=ON -DCMAKE_BUILD_TYPE=Release -DLITH_IMGUR_API_KEY=$IMGUR_API_KEY -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake -DANDROID_OPENSSL_PATH="${ANDROID_OPENSSL_PATH}" -DQT_ANDROID_BUILD_ALL_ABIS=ON

cmake --build . --target Lith -- -j2
cmake --build . --target apk -- -j2
Expand Down
4 changes: 2 additions & 2 deletions dist/ios/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}</string>
<string>${LITH_PROJECT_VERSION_MAJOR}.${LITH_PROJECT_VERSION_MINOR}</string>
<key>CFBundleVersion</key>
<string>${VERSION}</string>
<string>${LITH_VERSION}</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>CFBundleIconName</key>
Expand Down
2 changes: 1 addition & 1 deletion dist/ios/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mkdir build_ios
cd build_ios

export QT_HOST_PATH="${QT_ROOT_DIR}/../macos"
cmake .. -GXcode -DCMAKE_PREFIX_PATH=$QT_ROOT_DIR -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DVERSION=$VERSION_NAME -DIOS_DEVELOPMENT_TEAM_ID=Z52EFCPL6D -DIMGUR_API_KEY=$IMGUR_API_KEY
cmake .. -GXcode -DCMAKE_PREFIX_PATH=$QT_ROOT_DIR -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLITH_VERSION=$VERSION_NAME -DIOS_DEVELOPMENT_TEAM_ID=Z52EFCPL6D -DLITH_IMGUR_API_KEY=$IMGUR_API_KEY

xcodebuild -project Lith.xcodeproj -destination generic/platform=iOS -scheme Lith -configuration RelWithDebInfo DEVELOPMENT_TEAM=Z52EFCPL6D build
xcodebuild -project Lith.xcodeproj -scheme Lith -configuration RelWithDebInfo archive -archivePath Lith.xcarchive DEVELOPMENT_TEAM=Z52EFCPL6D
Expand Down
2 changes: 1 addition & 1 deletion dist/linux/app.lith.Lith.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
<update_contact>[email protected]</update_contact>
<content_rating type="oars-1.1"/>
<releases>
<release version="${PROJECT_VERSION}" date="${PROJECT_VERSION_RELEASEDATE}"/>
<release version="${LITH_PROJECT_VERSION}" date="${LITH_PROJECT_VERSION_RELEASEDATE}"/>
</releases>
</component>
2 changes: 1 addition & 1 deletion dist/macos/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
mkdir build_macos
cd build_macos
export CMAKE_PREFIX_PATH=$QT_ROOT_DIR/lib/cmake
cmake .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_BUILD_TYPE=Release -DIMGUR_API_KEY=$IMGUR_API_KEY -DVERSION=$VERSION_NAME -DCMAKE_INSTALL_PREFIX=installed
cmake .. -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_BUILD_TYPE=Release -DLITH_IMGUR_API_KEY=$IMGUR_API_KEY -DLITH_VERSION=$VERSION_NAME -DCMAKE_INSTALL_PREFIX=installed
cmake --build . --parallel
2 changes: 1 addition & 1 deletion dist/wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pushd build_wasm

export QT_HOST_PATH="${QT_ROOT_DIR}/../gcc_64"
export CMAKE_PREFIX_PATH=$QT_ROOT_DIR/lib/cmake
cmake .. -DCMAKE_BUILD_TYPE=Release -DIMGUR_API_KEY=$IMGUR_API_KEY -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake
cmake .. -DCMAKE_BUILD_TYPE=Release -DLITH_IMGUR_API_KEY=$IMGUR_API_KEY -DCMAKE_INSTALL_PREFIX=installed -DCMAKE_TOOLCHAIN_FILE=$QT_ROOT_DIR/lib/cmake/Qt6/qt.toolchain.cmake
cmake --build .
cmake --install .
20 changes: 10 additions & 10 deletions modules/Lith/Core/cmakedefs.h.in
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#ifndef CMAKEDEFS_H_IN
#define CMAKEDEFS_H_IN

#define PROJECT_VERSION "${PROJECT_VERSION}"
#define PROJECT_VERSION_MAJOR \
#define LITH_PROJECT_VERSION "${LITH_PROJECT_VERSION}"
#define LITH_PROJECT_VERSION_MAJOR \
$ { \
PROJECT_VERSION_MAJOR \
LITH_PROJECT_VERSION_MAJOR \
}
#define PROJECT_VERSION_MINOR \
#define LITH_PROJECT_VERSION_MINOR \
$ { \
PROJECT_VERSION_MINOR \
LITH_PROJECT_VERSION_MINOR \
}
#define PROJECT_VERSION_PATCH \
#define LITH_PROJECT_VERSION_PATCH \
$ { \
PROJECT_VERSION_PATCH \
LITH_PROJECT_VERSION_PATCH \
}

#define COMMIT_HASH "${COMMIT_HASH}"
#define GIT_STATE "${GIT_STATE}"
#define LITH_COMMIT_HASH "${LITH_COMMIT_HASH}"
#define LITH_GIT_STATE "${LITH_GIT_STATE}"

#cmakedefine01 LITH_IS_DEBUG_BUILD
#define CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}"

#define IMGUR_API_KEY "${IMGUR_API_KEY}"
#define LITH_IMGUR_API_KEY "${LITH_IMGUR_API_KEY}"

#define LITH_INSTALL_MODULEDIR "${LITH_INSTALL_MODULEDIR}"

Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/Core/lith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ NotificationHandler* Lith::notificationHandler() {
}

QString Lith::gitVersion() {
return QStringLiteral(GIT_STATE);
return QStringLiteral(LITH_GIT_STATE);
}

bool Lith::debugVersion() {
Expand Down
2 changes: 1 addition & 1 deletion modules/Lith/Core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class LITHCORE_EXPORT Settings : public QObject {
// This is hidden for now
SETTING(bool, terminalLikeChat, true)

SETTING(QString, imgurApiKey, QStringLiteral(IMGUR_API_KEY))
SETTING(QString, imgurApiKey, QStringLiteral(LITH_IMGUR_API_KEY))

// UNUSED SETTINGS
// determine what to do about these later
Expand Down

0 comments on commit 6a0d7ae

Please sign in to comment.