summaryrefslogtreecommitdiff
path: root/cmake/QtConfig.cmake.in
blob: 46a5d11ff70b2314eb143a4154d5253175d79189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@PACKAGE_INIT@

if (CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT)
    # When cross compiling with CMake any calls to pkg_check_modules() will
    # search into the host system instead of the target sysroot.
    # The current work around is based on the discussion found at
    # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4478
    set(ENV{PKG_CONFIG_DIR} "")
    set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/pkgconfig")
    set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
endif()

# Slightly amended version of ./src/corelib/Qt6Config.cmake.in
if (CMAKE_VERSION VERSION_LESS 3.1.0)
    message(FATAL_ERROR "Qt requires at least CMake version 3.1.0")
endif()

get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(_qt_@PROJECT_VERSION_MAJOR@_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")

if (NOT QT_NO_CREATE_TARGETS)
    include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Targets.cmake")
    if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
        include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@VersionlessTargets.cmake")
    endif()
else()
    # For examples using `find_package(...)` inside their CMakeLists.txt files:
    # Make CMake's AUTOGEN detect this Qt version properly
    set_directory_properties(PROPERTIES
                             QT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
                             QT_VERSION_MINOR @PROJECT_VERSION_MINOR@
                             QT_VERSION_PATCH @PROJECT_VERSION_PATCH@)
endif()

# if (NOT @INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS)
#     set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "The Qt package requires at least one component")
#     set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
#     return()
# endif()

get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH)
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}")
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/extra-cmake-modules/find-modules")
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/kwin")

if(APPLE AND (NOT CMAKE_SYSTEM_NAME OR CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
    # Add module directory to pick up custom Info.plist template for macOS
    list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/macos")
endif()

# Find required dependencies, if any.
include(CMakeFindDependencyMacro)
set(@INSTALL_CMAKE_NAMESPACE@_DEPENDENCIES_FOUND TRUE)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@Dependencies.cmake")
endif()
if(NOT @INSTALL_CMAKE_NAMESPACE@_DEPENDENCIES_FOUND)
    set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
    message(FATAL_ERROR
    "Failed to find Qt Platform dependency:
    ${@INSTALL_CMAKE_NAMESPACE@_DEPENDENCY_NOT_FOUND_MESSAGE}")
endif()

foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS})
    find_package(@INSTALL_CMAKE_NAMESPACE@${module}
        ${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_QUIET}
        ${_@INSTALL_CMAKE_NAMESPACE@_FIND_PARTS_REQUIRED}
        PATHS ${_qt_cmake_dir} ${QT_EXAMPLES_CMAKE_PREFIX_PATH} NO_DEFAULT_PATH
    )
    if (NOT @INSTALL_CMAKE_NAMESPACE@${module}_FOUND)
        string(CONFIGURE ${_qt5_module_location_template} _expected_module_location @ONLY)

        if (@INSTALL_CMAKE_NAMESPACE@_FIND_REQUIRED_${module})
            set(_Qt_NOTFOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}Failed to find Qt component \"${module}\" config file at                                       \"${_expected_module_location}\"\n")
        elseif(NOT @INSTALL_CMAKE_NAMESPACE@_FIND_QUIETLY)
            message(WARNING "Failed to find Qt component \"${module}\" config file at \"${_expected_module_location}\"")
        endif()

        unset(_expected_module_location)
    endif()
endforeach()

if (_Qt_NOTFOUND_MESSAGE)
    set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}")
    set(@INSTALL_CMAKE_NAMESPACE@_FOUND False)
endif()