Fix Standalone Example build when crosscompiling
Added qt_examples_begin() and qt_examples_end() macros to setup the example list so it can be re-used in other projects. When cross-compiling, we also need to set CMAKE_FIND_ROOT_PATH_MODE_PACKAGE to BOTH in order for find_package() to work correctly. Removed support for building the whole qtbase/examples folder as a standalone project. Building examples is only supported when building the whole of qtbase (qtbase + examples together) or each individual example is built separately against an installed Qt version. Change-Id: I9d26b94b48b95af230b76ab618becb21d2d45581 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
ac16a1228c
commit
053766d796
@ -96,3 +96,34 @@ macro(qt_build_tests)
|
|||||||
add_subdirectory(benchmarks)
|
add_subdirectory(benchmarks)
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
macro(qt_examples_build_begin)
|
||||||
|
# It is part of a Qt build => Use the CMake config files from the binary dir
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
|
||||||
|
# Also make sure the CMake config files do not recreate the already-existing targets
|
||||||
|
set(QT_NO_CREATE_TARGETS TRUE)
|
||||||
|
set(BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${CMAKE_FIND_ROOT_PATH_MODE_PACKAGE})
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "BOTH")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(qt_examples_build_end)
|
||||||
|
# We use AUTOMOC/UIC/RCC in the examples. Make sure to not fail on a fresh Qt build, that e.g. the moc binary does not exist yet.
|
||||||
|
|
||||||
|
# This function gets all targets below this directory
|
||||||
|
function(get_all_targets _result _dir)
|
||||||
|
get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
|
||||||
|
foreach(_subdir IN LISTS _subdirs)
|
||||||
|
get_all_targets(${_result} "${_subdir}")
|
||||||
|
endforeach()
|
||||||
|
get_property(_sub_targets DIRECTORY "${_dir}" PROPERTY BUILDSYSTEM_TARGETS)
|
||||||
|
set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
get_all_targets(targets "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
foreach(target ${targets})
|
||||||
|
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "moc" "uic" "rcc")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE})
|
||||||
|
endmacro()
|
||||||
|
@ -1,21 +1,6 @@
|
|||||||
# special case begin
|
# special case begin
|
||||||
cmake_minimum_required(VERSION 3.14.0)
|
qt_examples_build_begin()
|
||||||
|
|
||||||
project(QtBaseExamples LANGUAGES CXX C ASM)
|
|
||||||
|
|
||||||
# Check whether this project is built as part of a Qt build
|
|
||||||
if (CMAKE_PROJECT_NAME STREQUAL "QtBaseExamples")
|
|
||||||
set(QT_STANDALONE_EXAMPLES_BUILD TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT QT_STANDALONE_EXAMPLES_BUILD)
|
|
||||||
# It is part of a Qt build => Use the CMake config files from the binary dir
|
|
||||||
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
|
|
||||||
# Also make sure the CMake config files do not recreate the already-existing targets
|
|
||||||
set(QT_NO_CREATE_TARGETS TRUE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_package(Qt5 COMPONENTS DBus Network Test Concurrent Sql Widgets Xml Gui)
|
|
||||||
# special case end
|
# special case end
|
||||||
|
|
||||||
# Generated from examples.pro.
|
# Generated from examples.pro.
|
||||||
@ -65,24 +50,5 @@ if(TARGET Qt::Gui)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# special case begin
|
# special case begin
|
||||||
if (NOT QT_STANDALONE_EXAMPLES_BUILD)
|
qt_examples_build_end()
|
||||||
# We use AUTOMOC/UIC/RCC in the examples. Make sure to not fail on a fresh Qt build, that e.g. the moc binary does not exist yet.
|
|
||||||
|
|
||||||
# This function gets all targets below this directory
|
|
||||||
function(get_all_targets _result _dir)
|
|
||||||
get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
|
|
||||||
foreach(_subdir IN LISTS _subdirs)
|
|
||||||
get_all_targets(${_result} "${_subdir}")
|
|
||||||
endforeach()
|
|
||||||
get_property(_sub_targets DIRECTORY "${_dir}" PROPERTY BUILDSYSTEM_TARGETS)
|
|
||||||
set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
get_all_targets(targets "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
||||||
|
|
||||||
foreach(target ${targets})
|
|
||||||
qt_autogen_tools(${target} ENABLE_AUTOGEN_TOOLS "moc" "uic" "rcc")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
endif()
|
|
||||||
# special case end
|
# special case end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user