CMake: Store Qt features in CMake Cache
This is less self-contained than what we have, but significantly speeds up cmake configure/generate runs. This patch also warns when a feature is already defined. Change-Id: I8cab63e208ba98756b47d362a39b462f5ec55e20 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
3ec578020c
commit
6a1ee4de07
@ -272,27 +272,6 @@ function(extend_target target)
|
|||||||
list(APPEND dbus_sources "${sources}")
|
list(APPEND dbus_sources "${sources}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(dep ${arg_FEATURE_DEPENDENCIES} ${arg_LIBRARIES} ${arg_PUBLIC_LIBRARIES})
|
|
||||||
if("${dep}" MATCHES "^Qt::((.+)(Private)|(.+))$")
|
|
||||||
if (${CMAKE_MATCH_COUNT} EQUAL 3)
|
|
||||||
set(depTarget ${CMAKE_MATCH_2})
|
|
||||||
else()
|
|
||||||
set(depTarget ${CMAKE_MATCH_4})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Fetch features from dependencies and make them available to the
|
|
||||||
# caller as well as to the local scope for configure.cmake evaluation.
|
|
||||||
if(NOT TARGET "${dep}")
|
|
||||||
find_package(Qt${PROJECT_VERSION_MAJOR}${depTarget} REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if("x${CMAKE_MATCH_3}" STREQUAL "xPrivate")
|
|
||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES "Qt::${depTarget}")
|
|
||||||
endif()
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES "Qt::${depTarget}")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set_target_properties("${target}" PROPERTIES
|
set_target_properties("${target}" PROPERTIES
|
||||||
AUTOMOC ON
|
AUTOMOC ON
|
||||||
AUTOMOC_EXECUTABLE "$<TARGET_FILE:Qt::moc>"
|
AUTOMOC_EXECUTABLE "$<TARGET_FILE:Qt::moc>"
|
||||||
@ -309,8 +288,6 @@ function(extend_target target)
|
|||||||
target_include_directories("${target}" PUBLIC ${arg_PUBLIC_INCLUDE_DIRECTORIES} PRIVATE ${arg_INCLUDE_DIRECTORIES})
|
target_include_directories("${target}" PUBLIC ${arg_PUBLIC_INCLUDE_DIRECTORIES} PRIVATE ${arg_INCLUDE_DIRECTORIES})
|
||||||
target_compile_definitions("${target}" PUBLIC ${arg_PUBLIC_DEFINES} PRIVATE ${arg_DEFINES})
|
target_compile_definitions("${target}" PUBLIC ${arg_PUBLIC_DEFINES} PRIVATE ${arg_DEFINES})
|
||||||
target_link_libraries("${target}" PUBLIC ${arg_PUBLIC_LIBRARIES} PRIVATE ${arg_LIBRARIES})
|
target_link_libraries("${target}" PUBLIC ${arg_PUBLIC_LIBRARIES} PRIVATE ${arg_LIBRARIES})
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@ -545,8 +522,6 @@ function(add_qt_module target)
|
|||||||
$<INSTALL_INTERFACE:include/${module}/${PROJECT_VERSION}>
|
$<INSTALL_INTERFACE:include/${module}/${PROJECT_VERSION}>
|
||||||
$<INSTALL_INTERFACE:include/${module}/${PROJECT_VERSION}/${module}>
|
$<INSTALL_INTERFACE:include/${module}/${PROJECT_VERSION}/${module}>
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -611,8 +586,6 @@ function(add_qt_plugin target)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
qt_internal_add_linker_version_script(${target})
|
qt_internal_add_linker_version_script(${target})
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -645,8 +618,6 @@ function(add_qt_executable name)
|
|||||||
WIN32_EXECUTABLE "${arg_GUI}"
|
WIN32_EXECUTABLE "${arg_GUI}"
|
||||||
MACOSX_BUNDLE "${arg_GUI}"
|
MACOSX_BUNDLE "${arg_GUI}"
|
||||||
)
|
)
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -671,8 +642,6 @@ function(add_qt_test name)
|
|||||||
set_tests_properties("${name}" PROPERTIES RUN_SERIAL "${arg_RUN_SERIAL}")
|
set_tests_properties("${name}" PROPERTIES RUN_SERIAL "${arg_RUN_SERIAL}")
|
||||||
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "PATH=${path}${QT_PATH_SEPARATOR}${CMAKE_CURRENT_BINARY_DIR}${QT_PATH_SEPARATOR}$ENV{PATH}")
|
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "PATH=${path}${QT_PATH_SEPARATOR}${CMAKE_CURRENT_BINARY_DIR}${QT_PATH_SEPARATOR}$ENV{PATH}")
|
||||||
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
|
set_property(TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}")
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -680,7 +649,6 @@ endfunction()
|
|||||||
# tests launch separate programs to test certainly input/output behavior.
|
# tests launch separate programs to test certainly input/output behavior.
|
||||||
function(add_qt_test_helper name)
|
function(add_qt_test_helper name)
|
||||||
add_qt_executable("${name}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ${ARGN})
|
add_qt_executable("${name}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ${ARGN})
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -706,7 +674,6 @@ function(add_qt_tool name)
|
|||||||
qt_internal_add_target_aliases("${name}")
|
qt_internal_add_target_aliases("${name}")
|
||||||
|
|
||||||
install(TARGETS "${name}" EXPORT "Qt${PROJECT_VERSION_MAJOR}ToolsTargets" DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS})
|
install(TARGETS "${name}" EXPORT "Qt${PROJECT_VERSION_MAJOR}ToolsTargets" DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,7 +180,10 @@ macro(qt_feature_set_value feature cache emit_if condition label)
|
|||||||
message(SEND_ERROR "Feature \"${feature}\": Forcing to \"${cache}\" breaks its condition.")
|
message(SEND_ERROR "Feature \"${feature}\": Forcing to \"${cache}\" breaks its condition.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE)
|
if (DEFINED "QT_FEATURE_${feature}")
|
||||||
|
message(FATAL_ERROR "Feature ${feature} is already defined when evaluating configure.cmake features for ${target}.")
|
||||||
|
endif()
|
||||||
|
set(QT_FEATURE_${feature} "${result}" CACHE INTERNAL "Qt feature: ${feature}")
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
function(qt_evaluate_feature feature)
|
function(qt_evaluate_feature feature)
|
||||||
@ -379,8 +382,6 @@ function(qt_feature_module_end target)
|
|||||||
|
|
||||||
unset(__QtFeature_private_extra PARENT_SCOPE)
|
unset(__QtFeature_private_extra PARENT_SCOPE)
|
||||||
unset(__QtFeature_public_extra PARENT_SCOPE)
|
unset(__QtFeature_public_extra PARENT_SCOPE)
|
||||||
|
|
||||||
qt_push_features_into_parent_scope()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(qt_config_compile_test name)
|
function(qt_config_compile_test name)
|
||||||
@ -400,55 +401,35 @@ function(qt_config_compile_test_x86simd extension label)
|
|||||||
set(TEST_subarch_${extension} "${TEST_X86SIMD_${extension}}" CACHE INTERNAL "${label}" )
|
set(TEST_subarch_${extension} "${TEST_X86SIMD_${extension}}" CACHE INTERNAL "${label}" )
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(qt_pull_features_into_current_scope)
|
function(qt_make_features_available target)
|
||||||
cmake_parse_arguments(arg "PUBLIC_FEATURES;PRIVATE_FEATURES" "" "" ${ARGN})
|
if(NOT "${target}" MATCHES "^Qt::[a-zA-z][a-zA-Z0-9_]*$")
|
||||||
foreach(target IN ITEMS ${arg_UNPARSED_ARGUMENTS})
|
message(FATAL_ERROR "${target} does not match Qt::[a-zA-z][a-zA-Z0-9_]*. INVALID NAME.")
|
||||||
if(NOT "${target}" MATCHES "^Qt::[a-zA-z][a-zA-Z0-9_]*$")
|
endif()
|
||||||
message(FATAL_ERROR "${target} does not match Qt::[a-zA-z][a-zA-Z0-9_]*. INVALID NAME.")
|
if(NOT TARGET ${target})
|
||||||
endif()
|
message(FATAL_ERROR "${target} not found.")
|
||||||
if(NOT TARGET ${target})
|
endif()
|
||||||
message(FATAL_ERROR "${target} not found.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
get_target_property(target_type "${target}" TYPE)
|
get_target_property(target_type "${target}" TYPE)
|
||||||
if("${target_type}" STREQUAL "INTERFACE_LIBRARY")
|
if("${target_type}" STREQUAL "INTERFACE_LIBRARY")
|
||||||
set(property_prefix "INTERFACE_")
|
set(property_prefix "INTERFACE_")
|
||||||
else()
|
else()
|
||||||
set(property_prefix "")
|
set(property_prefix "")
|
||||||
endif()
|
endif()
|
||||||
foreach(visibility IN ITEMS PUBLIC PRIVATE)
|
foreach(visibility IN ITEMS PUBLIC PRIVATE)
|
||||||
if(NOT ${arg_${visibility}_FEATURES})
|
set(value ON)
|
||||||
|
foreach(state IN ITEMS ENABLED DISABLED)
|
||||||
|
get_target_property(features "${target}" ${property_prefix}QT_${state}_${visibility}_FEATURES)
|
||||||
|
if("${features}" STREQUAL "features-NOTFOUND")
|
||||||
continue()
|
continue()
|
||||||
endif()
|
endif()
|
||||||
|
foreach(feature IN ITEMS ${features})
|
||||||
set(value ON)
|
if (DEFINED "QT_FEATURE_${feature}")
|
||||||
foreach(state IN ITEMS ENABLED DISABLED)
|
message(FATAL_ERROR "Feature ${feature} is already defined when importing features from ${target}.")
|
||||||
get_target_property(features "${target}" ${property_prefix}QT_${state}_${visibility}_FEATURES)
|
|
||||||
if("${features}" STREQUAL "features-NOTFOUND")
|
|
||||||
continue()
|
|
||||||
endif()
|
endif()
|
||||||
foreach(feature IN ITEMS ${features})
|
set(QT_FEATURE_${feature} "${value}" CACHE INTERNAL "Qt feature: ${feature}")
|
||||||
set(QT_FEATURE_${feature} ${value} PARENT_SCOPE)
|
|
||||||
endforeach()
|
|
||||||
set(value OFF)
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
set(value OFF)
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
macro(qt_push_features_into_parent_scope)
|
|
||||||
get_cmake_property(_variableNames VARIABLES)
|
|
||||||
|
|
||||||
foreach(_var IN ITEMS ${_variableNames})
|
|
||||||
if(_var MATCHES "^QT_FEATURE_[a-z][a-z0-9_]*$")
|
|
||||||
set("${_var}" "${${_var}}" PARENT_SCOPE)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
macro(qt_load_global_features)
|
|
||||||
if(NOT TARGET Qt::GlobalConfig)
|
|
||||||
find_package(Qt${PROJECT_VERSION_MAJOR}GlobalConfig QUIET)
|
|
||||||
endif()
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES PRIVATE_FEATURES Qt::GlobalConfig)
|
|
||||||
endmacro()
|
|
||||||
|
@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
find_package(Qt@PROJECT_VERSION_MAJOR@ QUIET)
|
find_package(Qt@PROJECT_VERSION_MAJOR@ QUIET)
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@versioned_module_name@Targets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/@module_versioned@Targets.cmake")
|
||||||
|
|
||||||
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/@versioned_module_name@Macros.cmake")
|
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/@module_versioned@Macros.cmake")
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/@versioned_module_name@Macros.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/@module_versioned@Macros.cmake")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include QtFeature
|
||||||
|
|
||||||
|
qt_make_features_available(Qt::@module@)
|
||||||
|
@ -58,7 +58,6 @@ add_subdirectory(tools)
|
|||||||
if(QT_FEATURE_gui)
|
if(QT_FEATURE_gui)
|
||||||
add_subdirectory(gui)
|
add_subdirectory(gui)
|
||||||
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES Qt::Gui)
|
|
||||||
if(QT_FEATURE_widgets)
|
if(QT_FEATURE_widgets)
|
||||||
add_subdirectory(widgets)
|
add_subdirectory(widgets)
|
||||||
if(QT_FEATURE_opengl)
|
if(QT_FEATURE_opengl)
|
||||||
|
@ -6,8 +6,6 @@ find_library(FWCoreGraphics CoreGraphics)
|
|||||||
## Gui Module:
|
## Gui Module:
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
qt_load_global_features()
|
|
||||||
|
|
||||||
if (QT_FEATURE_gui)
|
if (QT_FEATURE_gui)
|
||||||
if (WINRT)
|
if (WINRT)
|
||||||
set(_default_platform "winrt")
|
set(_default_platform "winrt")
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Generated from platformsupport.pro.
|
# Generated from platformsupport.pro.
|
||||||
|
|
||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES Qt::Gui)
|
|
||||||
add_subdirectory(themes)
|
add_subdirectory(themes)
|
||||||
add_subdirectory(edid)
|
add_subdirectory(edid)
|
||||||
add_subdirectory(eventdispatchers)
|
add_subdirectory(eventdispatchers)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES Qt::Gui)
|
|
||||||
|
|
||||||
if(QT_FEATURE_xcb)
|
if(QT_FEATURE_xcb)
|
||||||
add_subdirectory(xcb)
|
add_subdirectory(xcb)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
# Generated from printsupport.pro.
|
|
||||||
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES Qt::PrintSupport)
|
|
||||||
add_subdirectory(dialogs)
|
add_subdirectory(dialogs)
|
||||||
add_subdirectory(kernel)
|
add_subdirectory(kernel)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES Qt::Gui)
|
|
||||||
|
|
||||||
add_qt_test("tst_qmdiarea" RUN_SERIAL SOURCES tst_qmdiarea.cpp
|
add_qt_test("tst_qmdiarea" RUN_SERIAL SOURCES tst_qmdiarea.cpp
|
||||||
DEFINES
|
DEFINES
|
||||||
QT_NO_CAST_TO_ASCII
|
QT_NO_CAST_TO_ASCII
|
||||||
@ -10,5 +8,4 @@ add_qt_test("tst_qmdiarea" RUN_SERIAL SOURCES tst_qmdiarea.cpp
|
|||||||
)
|
)
|
||||||
|
|
||||||
extend_target("tst_qmdiarea" CONDITION TARGET Qt::OpenGL LIBRARIES Qt::OpenGL)
|
extend_target("tst_qmdiarea" CONDITION TARGET Qt::OpenGL LIBRARIES Qt::OpenGL)
|
||||||
|
|
||||||
extend_target("tst_qmdiarea" CONDITION APPLE_OSX LIBRARIES FWSecurity)
|
extend_target("tst_qmdiarea" CONDITION APPLE_OSX LIBRARIES FWSecurity)
|
||||||
|
@ -823,23 +823,9 @@ def handle_app_or_lib(scope: Scope, cm_fh: typing.IO[str], *,
|
|||||||
scope.currentdir())))
|
scope.currentdir())))
|
||||||
|
|
||||||
|
|
||||||
def handle_qt_for_config(scope: Scope, cm_fh: typing.IO[str], *,
|
|
||||||
indent: int = 0) -> None:
|
|
||||||
for config in scope.get("QT_FOR_CONFIG") or []:
|
|
||||||
lib = map_qt_library(config)
|
|
||||||
if lib.endswith("Private"):
|
|
||||||
cm_fh.write('{}qt_pull_features_into_current_scope'
|
|
||||||
'(PRIVATE_FEATURES {})\n'
|
|
||||||
.format(spaces(indent), lib[:-len("Private")]))
|
|
||||||
else:
|
|
||||||
cm_fh.write('{}qt_pull_features_into_current_scope'
|
|
||||||
'(PUBLIC_FEATURES {})\n'.format(spaces(indent), lib))
|
|
||||||
|
|
||||||
|
|
||||||
def cmakeify_scope(scope: Scope, cm_fh: typing.IO[str], *,
|
def cmakeify_scope(scope: Scope, cm_fh: typing.IO[str], *,
|
||||||
indent: int = 0) -> None:
|
indent: int = 0) -> None:
|
||||||
template = scope.getTemplate()
|
template = scope.getTemplate()
|
||||||
handle_qt_for_config(scope, cm_fh)
|
|
||||||
if template == 'subdirs':
|
if template == 'subdirs':
|
||||||
handle_subdir(scope, cm_fh, indent=indent)
|
handle_subdir(scope, cm_fh, indent=indent)
|
||||||
elif template in ('app', 'lib'):
|
elif template in ('app', 'lib'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user