Skip to content

Commit

Permalink
cmake: reimplement the build-config.yaml mechanism
Browse files Browse the repository at this point in the history
Also make sure to extend only existing targets

Change-Id: I4b61240568502f86a1f7b8631e6b17791d4a75f7
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
  • Loading branch information
rgriebl committed Jun 30, 2021
1 parent f4c512a commit 28db22b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 31 deletions.
77 changes: 77 additions & 0 deletions cmake/QtAppManBuildConfig.cmake
@@ -0,0 +1,77 @@
# This function adds the current build configuration to the specified target
# as a YAML file named ":/build-config.yaml" via a Qt resource file.
function(qtam_internal_add_build_config target)
if(NOT TARGET "${target}")
message(FATAL_ERROR "Trying to extend non-existing target \"${target}\".")
endif()

# get the git version, if available
file(READ ${CMAKE_SOURCE_DIR}/.tag GIT_VERSION)
STRING(REGEX REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
if(GIT_VERSION STREQUAL "\$Format:%H\$")
set(GIT_VERSION "unknown")
if(EXISTS ${CMAKE_SOURCE_DIR}/.git)
execute_process(
COMMAND git describe --tags --always --dirty
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
endif()

# generate the necessary strings to be backward compatible with qmake
string(TIMESTAMP _DATE_ UTC)
set(SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(BUILD_DIR ${CMAKE_BINARY_DIR})
set(MODULE_VERSION ${PROJECT_VERSION})
set(INSTALL_PREFIX ${QT6_INSTALL_PREFIX})
set(QT_ARCH ${CMAKE_SYSTEM_PROCESSOR})
set(QT_VERSION ${Qt6_VERSION})
get_target_property(DEFINES ${target} COMPILE_DEFINITIONS)
set(DEFINES_TYPE "array")

get_cmake_property(ALL_VARS VARIABLES)
foreach (VAR ${ALL_VARS})
if (VAR MATCHES "^QT_FEATURE_([a-z])")
list(APPEND QT_FEATURES "${VAR}")
endif()
endforeach()
set(QT_FEATURES_TYPE "dict")

set(build_config "${CMAKE_CURRENT_BINARY_DIR}/build-config.yaml")
file(WRITE "${build_config}" "---\n")
foreach(VAR _DATE_ MODULE_VERSION GIT_VERSION SOURCE_DIR BUILD_DIR INSTALL_PREFIX
QT_ARCH QT_VERSION QT_FEATURES DEFINES)
if(NOT VAR)
file(APPEND "${build_config}" "${VAR}: ~\n")
elseif("${${VAR}_TYPE}" STREQUAL "array")
file(APPEND "${build_config}" "${VAR}:\n")
foreach(VAL ${${VAR}})
file(APPEND "${build_config}" " - '${VAL}'\n")
endforeach()
elseif("${${VAR}_TYPE}" STREQUAL "dict")
file(APPEND "${build_config}" "${VAR}:\n")
foreach(SUBVAR ${${VAR}})
set(VAL ${${SUBVAR}})
if(VAL STREQUAL "ON")
set(VAL "yes")
elseif(VAL STREQUAL "OFF")
set(VAL "no")
else()
set(VAL "'${VAL}'")
endif()
file(APPEND "${build_config}" " ${SUBVAR}: ${VAL}\n")
endforeach()
else()
file(APPEND "${build_config}" "${VAR}: '${${VAR}}'\n")
endif()
endforeach()

qt_internal_add_resource(${target} "build-config"
PREFIX "/"
FILES "${build_config}"
BASE "${CMAKE_CURRENT_BINARY_DIR}"
)
endfunction()
18 changes: 4 additions & 14 deletions src/tools/appman/CMakeLists.txt
Expand Up @@ -15,18 +15,8 @@ qt_internal_add_tool(${target_name}
Qt::AppManMainPrivate
)

#### Keys ignored in scope 1:.:.:appman.pro:<TRUE>:
# GIT_VERSION = "$$cat($$SOURCE_DIR/.tag, lines)"
# TEMPLATE = "app"
if (TARGET ${target_name})
include(QtAppManBuildConfig)

## Scopes:
#####################################################################

#### Keys ignored in scope 4:.:.:appman.pro:UNIX AND EXISTS _ss_SOURCE_DIR/.git:
# GIT_VERSION = "$$system(cd "$$SOURCE_DIR" && git describe --tags --always --dirty 2>/dev/null)"

#### Keys ignored in scope 5:.:.:appman.pro:else:
# GIT_VERSION = "unknown"

#### Keys ignored in scope 6:.:.:appman.pro:ANDROID:
# INSTALLS = <EMPTY>
qtam_internal_add_build_config(${target_name})
endif()
17 changes: 10 additions & 7 deletions src/tools/controller/CMakeLists.txt
Expand Up @@ -17,13 +17,16 @@ qt_internal_add_tool(${target_name}
Qt::Network
Qt::AppManCommonPrivate
)
qt_internal_extend_target(${target_name}
DBUS_INTERFACE_SOURCES

if (TARGET ${target_name})
qt_internal_extend_target(${target_name}
DBUS_INTERFACE_SOURCES
../../dbus-lib/io.qt.packagemanager.xml
)
qt_internal_extend_target(${target_name}
DBUS_INTERFACE_SOURCES
)
qt_internal_extend_target(${target_name}
DBUS_INTERFACE_SOURCES
../../dbus-lib/io.qt.applicationmanager.xml
DBUS_INTERFACE_FLAGS
DBUS_INTERFACE_FLAGS
-i dbus-utilities.h
)
)
endif()
14 changes: 4 additions & 10 deletions src/tools/testrunner/CMakeLists.txt
Expand Up @@ -21,14 +21,8 @@ qt_internal_add_tool(${target_name}
Qt::AppManMainPrivate
)

## Scopes:
#####################################################################

#### Keys ignored in scope 2:.:.:testrunner.pro:ANDROID:
# INSTALLS = <EMPTY>

#### Keys ignored in scope 6:.:../appman:../appman/appman.pro:UNIX AND EXISTS _ss_SOURCE_DIR/.git:
# GIT_VERSION = "$$system(cd "$$SOURCE_DIR" && git describe --tags --always --dirty 2>/dev/null)"
if (TARGET ${target_name})
include(QtAppManBuildConfig)

#### Keys ignored in scope 7:.:../appman:../appman/appman.pro:else:
# GIT_VERSION = "unknown"
qtam_internal_add_build_config(${target_name})
endif()

0 comments on commit 28db22b

Please sign in to comment.