Skip to content

Commit

Permalink
sync to upstream KDAB and KDE cmake files
Browse files Browse the repository at this point in the history
  • Loading branch information
winterz committed Apr 4, 2024
1 parent c81aed3 commit 8b03afd
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 124 deletions.
16 changes: 8 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

if(BUILD_QT6)
set(Qt_VERSION_MAJOR 6)
set(QT_VERSION_MAJOR 6)
set(QT_MIN_VERSION "6.1.0")
find_package(
Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Quick QuickControls2 QuickWidgets Test Widgets StateMachine
Expand All @@ -109,25 +109,25 @@ if(BUILD_QT6)
)
set(KDSME_LIBRARY_QTID "-qt6")
else()
set(Qt_VERSION_MAJOR 5)
set(QT_VERSION_MAJOR 5)
set(QT_MIN_VERSION "5.15")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Quick QuickWidgets Test Widgets)
set(KDSME_LIBRARY_QTID "")
include(ECMGeneratePriFile)
include(KDQtInstallPaths) #to set QT_INSTALL_FOO variables
endif()
include(KDQtInstallPaths) #to set QT_INSTALL_FOO variables

find_package(Qt${Qt_VERSION_MAJOR}RemoteObjects ${QT_MIN_VERSION} CONFIG QUIET)
find_package(Qt${QT_VERSION_MAJOR}RemoteObjects ${QT_MIN_VERSION} CONFIG QUIET)
set_package_properties(
Qt${Qt_VERSION_MAJOR}RemoteObjects PROPERTIES
Qt${QT_VERSION_MAJOR}RemoteObjects PROPERTIES
TYPE OPTIONAL
DESCRIPTION "Qt Remote Objects module"
PURPOSE "Needed for the QStateMachine/QtSCXML adapter and remote debugging capabilities"
)

find_package(Qt${Qt_VERSION_MAJOR}Scxml ${QT_MIN_VERSION} CONFIG QUIET)
find_package(Qt${QT_VERSION_MAJOR}Scxml ${QT_MIN_VERSION} CONFIG QUIET)
set_package_properties(
Qt${Qt_VERSION_MAJOR}Scxml PROPERTIES
Qt${QT_VERSION_MAJOR}Scxml PROPERTIES
TYPE OPTIONAL
DESCRIPTION "Qt SCXML module"
PURPOSE "Needed for the Qt SCXML adapter (adapter itself depends on Qt RemoteObjects)"
Expand Down Expand Up @@ -212,7 +212,7 @@ set(INSTALL_TARGETS_DEFAULT_ARGS
Devel
BUNDLE
DESTINATION
"/Applications/Qt${Qt_VERSION_MAJOR}"
"/Applications/Qt${QT_VERSION_MAJOR}"
)

# search for Graphviz
Expand Down
97 changes: 61 additions & 36 deletions cmake/ECM/modules/ECMAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,82 @@ Convenience functions for adding tests.

::

ecm_add_tests(<sources> LINK_LIBRARIES <library> [<library> [...]]
[NAME_PREFIX <prefix>]
[GUI]
[TARGET_NAMES_VAR <target_names_var>]
[TEST_NAMES_VAR <test_names_var>])
ecm_add_tests(<sources>
LINK_LIBRARIES <library> [<library> [...]]
[NAME_PREFIX <prefix>]
[GUI]
[TARGET_NAMES_VAR <target_names_var>]
[TEST_NAMES_VAR <test_names_var>]
[WORKING_DIRECTORY <dir>] # Since 5.111
)

A convenience function for adding multiple tests, each consisting of a
single source file. For each file in <sources>, an executable target will be
created (the name of which will be the basename of the source file). This
will be linked against the libraries given with LINK_LIBRARIES. Each
will be linked against the libraries given with ``LINK_LIBRARIES``. Each
executable will be added as a test with the same name.

If NAME_PREFIX is given, this prefix will be prepended to the test names, but
If ``NAME_PREFIX`` is given, this prefix will be prepended to the test names, but
not the target names. As a result, it will not prevent clashes between tests
with the same name in different parts of the project, but it can be used to
give an indication of where to look for a failing test.

If the flag GUI is passed the test binaries will be GUI executables, otherwise
If the flag ``GUI`` is passed the test binaries will be GUI executables, otherwise
the resulting binaries will be console applications (regardless of the value
of CMAKE_WIN32_EXECUTABLE or CMAKE_MACOSX_BUNDLE). Be aware that this changes
of ``CMAKE_WIN32_EXECUTABLE`` or ``CMAKE_MACOSX_BUNDLE``). Be aware that this changes
the executable entry point on Windows (although some frameworks, such as Qt,
abstract this difference away).

The tests will be build with -DQT_FORCE_ASSERTS to enable assertions in the
The tests will be build with ``-DQT_FORCE_ASSERTS`` to enable assertions in the
test executable even for release builds.

The TARGET_NAMES_VAR and TEST_NAMES_VAR arguments, if given, should specify a
The ``TARGET_NAMES_VAR`` and ``TEST_NAMES_VAR`` arguments, if given, should specify a
variable name to receive the list of generated target and test names,
respectively. This makes it convenient to apply properties to them as a
whole, for example, using set_target_properties() or set_tests_properties().
whole, for example, using ``set_target_properties()`` or ``set_tests_properties()``.

The generated target executables will have the effects of ecm_mark_as_test()
The generated target executables will have the effects of ``ecm_mark_as_test()``
(from the :module:`ECMMarkAsTest` module) applied to it.

::
``WORKING_DIRECTORY`` sets the test property `WORKING_DIRECTORY
<https://cmake.org/cmake/help/latest/prop_test/WORKING_DIRECTORY.html>`_
in which to execute the test. By default the test will be run in
``${CMAKE_CURRENT_BINARY_DIR}``. The working directory can be specified using
generator expressions. Since 5.111.

ecm_add_test(<sources> LINK_LIBRARIES <library> [<library> [...]]
[TEST_NAME <name>]
[NAME_PREFIX <prefix>]
[GUI])
::

This is a single-test form of ecm_add_tests that allows multiple source files
to be used for a single test. If using multiple source files, TEST_NAME must
ecm_add_test(
<sources>
LINK_LIBRARIES <library> [<library> [...]]
[TEST_NAME <name>]
[NAME_PREFIX <prefix>]
[GUI]
[WORKING_DIRECTORY <dir>] # Since 5.111
)

This is a single-test form of ``ecm_add_tests`` that allows multiple source files
to be used for a single test. If using multiple source files, ``TEST_NAME`` must
be given; this will be used for both the target and test names (and, as with
ecm_add_tests(), the NAME_PREFIX argument will be prepended to the test name).
``ecm_add_tests()``, the ``NAME_PREFIX`` argument will be prepended to the test name).

``WORKING_DIRECTORY`` sets the test property `WORKING_DIRECTORY
<https://cmake.org/cmake/help/latest/prop_test/WORKING_DIRECTORY.html>`_
in which to execute the test. By default the test will be run in
``${CMAKE_CURRENT_BINARY_DIR}``. The working directory can be specified using
generator expressions. Since 5.111.

Since pre-1.0.0.
#]=======================================================================]

include(CMakeParseArguments)
include(ECMMarkAsTest)
include(ECMMarkNonGuiExecutable)

function(ecm_add_test)
set(options GUI)
# TARGET_NAME_VAR and TEST_NAME_VAR are undocumented args used by
# ecm_add_tests
set(oneValueArgs TEST_NAME NAME_PREFIX TARGET_NAME_VAR TEST_NAME_VAR)
set(oneValueArgs TEST_NAME NAME_PREFIX TARGET_NAME_VAR TEST_NAME_VAR WORKING_DIRECTORY)
set(multiValueArgs LINK_LIBRARIES)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(_sources ${ARG_UNPARSED_ARGUMENTS})
Expand All @@ -93,23 +110,26 @@ function(ecm_add_test)
if(NOT ARG_GUI)
ecm_mark_nongui_executable(${_targetname})
endif()
add_test(NAME ${_testname} COMMAND ${_targetname})
set(test_args)
if(DEFINED ARG_WORKING_DIRECTORY)
list(APPEND test_args WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY})
endif()
add_test(NAME ${_testname} COMMAND ${_targetname} ${test_args})
target_link_libraries(${_targetname} ${ARG_LINK_LIBRARIES})
target_compile_definitions(${_targetname} PRIVATE -DQT_FORCE_ASSERTS)
ecm_mark_as_test(${_targetname})
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# https://stackoverflow.com/questions/59862894/how-do-i-make-a-list-in-cmake-with-the-semicolon-value
set(PATHSEP "\\\;") # Don't want cmake to treat it like a list
else() # e.g. Linux
set(PATHSEP ":")
set(_plugin_path ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
if (DEFINED ENV{QT_PLUGIN_PATH})
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# https://stackoverflow.com/questions/59862894/how-do-i-make-a-list-in-cmake-with-the-semicolon-value
set(PATHSEP "\\\;") # Don't want cmake to treat it like a list
else() # e.g. Linux
set(PATHSEP ":")
endif()
set(_plugin_path "${_plugin_path}${PATHSEP}$ENV{QT_PLUGIN_PATH}")
endif()
if(DEFINED QT_PLUGIN_PATH)
set(_plugin_path "$ENV{QT_PLUGIN_PATH}")
else()
set(_plugin_path "")
endif()
set_property(TEST ${_testname} PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}${PATHSEP}${_plugin_path}")
set_property(TEST ${_testname} PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${_plugin_path}")
endif()
if (ARG_TARGET_NAME_VAR)
set(${ARG_TARGET_NAME_VAR} "${_targetname}" PARENT_SCOPE)
Expand All @@ -121,14 +141,18 @@ endfunction()

function(ecm_add_tests)
set(options GUI)
set(oneValueArgs NAME_PREFIX TARGET_NAMES_VAR TEST_NAMES_VAR)
set(oneValueArgs NAME_PREFIX TARGET_NAMES_VAR TEST_NAMES_VAR WORKING_DIRECTORY)
set(multiValueArgs LINK_LIBRARIES)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(ARG_GUI)
set(_exe_type GUI)
else()
set(_exe_type "")
endif()
set(test_args)
if(DEFINED ARG_WORKING_DIRECTORY)
list(APPEND test_args WORKING_DIRECTORY ${ARG_WORKING_DIRECTORY})
endif()
set(test_names)
set(target_names)
foreach(_test_source ${ARG_UNPARSED_ARGUMENTS})
Expand All @@ -138,6 +162,7 @@ function(ecm_add_tests)
TARGET_NAME_VAR target_name
TEST_NAME_VAR test_name
${_exe_type}
${test_args}
)
list(APPEND _test_names "${test_name}")
list(APPEND _target_names "${target_name}")
Expand Down
34 changes: 17 additions & 17 deletions cmake/ECM/modules/ECMGeneratePriFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ library convenient for them, in much the same way that CMake config files make
things convenient for CMake-based applications. ``ecm_generate_pri_file()``
generates just such a file.

VERSION specifies the version of the library the ``.pri`` file describes. If
``VERSION`` specifies the version of the library the ``.pri`` file describes. If
not set, the value is taken from the context variable ``PROJECT_VERSION``.
This variable is usually set by the ``project(... VERSION ...)`` command or,
if CMake policy CMP0048 is not NEW, by :module:`ECMSetupVersion`.
if CMake policy CMP0048 is not ``NEW``, by :module:`ECMSetupVersion`.
For backward-compatibility with older ECM versions the
``PROJECT_VERSION_STRING`` variable as set by :module:`ECMSetupVersion`
will be preferred over ``PROJECT_VERSION`` if set, unless the minimum
required version of ECM is 5.83 and newer. Since 5.83.

BASE_NAME specifies the name qmake project (.pro) files should use to refer to
the library (eg: KArchive). LIB_NAME is the name of the actual library to
link to (ie: the first argument to add_library()). DEPS is a space-separated
``BASE_NAME`` specifies the name qmake project (.pro) files should use to refer to
the library (eg: KArchive). ``LIB_NAME`` is the name of the actual library to
link to (ie: the first argument to add_library()). ``DEPS`` is a space-separated
list of the base names of other libraries (for Qt libraries, use the same
names you use with the ``QT`` variable in a qmake project file, such as "core"
for QtCore). FILENAME_VAR specifies the name of a variable to store the path
for QtCore). ``FILENAME_VAR`` specifies the name of a variable to store the path
to the generated file in.

INCLUDE_INSTALL_DIRS are the paths (relative to ``CMAKE_INSTALL_PREFIX``) that
``INCLUDE_INSTALL_DIRS`` are the paths (relative to ``CMAKE_INSTALL_PREFIX``) that
include files will be installed to. It defaults to
``${INCLUDE_INSTALL_DIR}/<baseName>`` if the ``INCLUDE_INSTALL_DIR`` variable
is set. If that variable is not set, the ``CMAKE_INSTALL_INCLUDEDIR`` variable
is used instead, and if neither are set ``include`` is used. LIB_INSTALL_DIR
is used instead, and if neither are set ``include`` is used. ``LIB_INSTALL_DIR``
operates similarly for the installation location for libraries; it defaults to
``${LIB_INSTALL_DIR}``, ``${CMAKE_INSTALL_LIBDIR}`` or ``lib``, in that order.

INCLUDE_INSTALL_DIR is the old variant of INCLUDE_INSTALL_DIRS, taking only one
``INCLUDE_INSTALL_DIR`` is the old variant of ``INCLUDE_INSTALL_DIRS``, taking only one
directory.

Example usage:
Expand All @@ -89,19 +89,19 @@ Since pre-1.0.0.

# Replicate the logic from KDEInstallDirs.cmake as we can't depend on it
# Ask qmake if we're using the same prefix as Qt
set(_askqmake OFF)
set(_should_query_qt OFF)
if(NOT DEFINED KDE_INSTALL_USE_QT_SYS_PATHS)
include(ECMQueryQmake)
query_qmake(qt_install_prefix_dir QT_INSTALL_PREFIX TRY)
include(ECMQueryQt)
ecm_query_qt(qt_install_prefix_dir QT_INSTALL_PREFIX TRY)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
set(_askqmake ON)
set(_should_query_qt ON)
endif()
endif()

if(KDE_INSTALL_USE_QT_SYS_PATHS OR _askqmake)
include(ECMQueryQmake)
query_qmake(qt_install_prefix_dir QT_INSTALL_PREFIX)
query_qmake(qt_host_data_dir QT_HOST_DATA)
if(KDE_INSTALL_USE_QT_SYS_PATHS OR _should_query_qt)
include(ECMQueryQt)
ecm_query_qt(qt_install_prefix_dir QT_INSTALL_PREFIX)
ecm_query_qt(qt_host_data_dir QT_HOST_DATA)
if(qt_install_prefix_dir STREQUAL "${CMAKE_INSTALL_PREFIX}")
file(RELATIVE_PATH qt_host_data_dir ${qt_install_prefix_dir} ${qt_host_data_dir})
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/ECM/modules/ECMMarkAsTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Marks a target as only being required for tests.
ecm_mark_as_test(<target1> [<target2> [...]])

This will cause the specified targets to not be built unless either
BUILD_TESTING is set to ON or the user invokes the ``buildtests`` target.
``BUILD_TESTING`` is set to ``ON`` or the user invokes the ``buildtests`` target.

BUILD_TESTING is created as a cache variable by the CTest module and by the
``BUILD_TESTING`` is created as a cache variable by the CTest module and by the
:kde-module:`KDECMakeSettings` module.

Since pre-1.0.0.
Expand Down
4 changes: 4 additions & 0 deletions cmake/ECM/modules/ECMQueryQmake.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (${ECM_GLOBAL_FIND_VERSION} VERSION_GREATER_EQUAL 5.93)
message(DEPRECATION "ECMQueryQmake.cmake is deprecated since 5.93, please use ECMQueryQt.cmake instead.")
endif()

include(${CMAKE_CURRENT_LIST_DIR}/QtVersionOption.cmake)
find_package(Qt${QT_MAJOR_VERSION}Core QUIET)

Expand Down
Loading

0 comments on commit 8b03afd

Please sign in to comment.