CMake: Simplify Feature handling
Simplify the scope handling of features by providing a function that just pushes all QT_FEATURES into the parent scope. Use it. Change-Id: Ic6552fe495394d73fcec6becf6852745ec2d6d59 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
da7811dc75
commit
b7b4af575f
@ -442,10 +442,8 @@ function(extend_target target)
|
|||||||
# caller as well as to the local scope for configure.cmake evaluation.
|
# caller as well as to the local scope for configure.cmake evaluation.
|
||||||
|
|
||||||
if("x${CMAKE_MATCH_2}" STREQUAL "xPrivate")
|
if("x${CMAKE_MATCH_2}" STREQUAL "xPrivate")
|
||||||
qt_push_features_into_parent_scope(PRIVATE_FEATURES ${depTarget})
|
|
||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${depTarget})
|
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${depTarget})
|
||||||
endif()
|
endif()
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES ${depTarget})
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${depTarget})
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${depTarget})
|
||||||
if(TARGET "${dep}")
|
if(TARGET "${dep}")
|
||||||
continue()
|
continue()
|
||||||
@ -462,6 +460,8 @@ function(extend_target target)
|
|||||||
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})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
qt_push_features_into_parent_scope()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -549,20 +549,18 @@ function(add_qt_module name)
|
|||||||
|
|
||||||
# Import global features
|
# Import global features
|
||||||
if(NOT "${target}" STREQUAL "Core")
|
if(NOT "${target}" STREQUAL "Core")
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES PRIVATE_FEATURES FEATURE_PROPERTY_INFIX "GLOBAL_" Qt::Core)
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES PRIVATE_FEATURES FEATURE_PROPERTY_INFIX "GLOBAL_" Qt::Core)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Fetch features from dependencies and make them available to the
|
# Fetch features from dependencies and make them available to the
|
||||||
# caller as well as to the local scope for configure.cmake evaluation.
|
# caller as well as to the local scope for configure.cmake evaluation.
|
||||||
foreach(dep ${_arg_LIBRARIES} ${_arg_PUBLIC_LIBRARIES})
|
foreach(dep ${_arg_LIBRARIES} ${_arg_PUBLIC_LIBRARIES} ${_arg_FEATURE_DEPENDENCIES})
|
||||||
if("${dep}" MATCHES "(Qt::.+)Private")
|
if("${dep}" MATCHES "(Qt::.+)Private")
|
||||||
set(publicDep ${CMAKE_MATCH_1})
|
set(publicDep ${CMAKE_MATCH_1})
|
||||||
qt_push_features_into_parent_scope(PRIVATE_FEATURES ${publicDep})
|
|
||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep})
|
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep})
|
||||||
else()
|
else()
|
||||||
set(publicDep ${dep})
|
set(publicDep ${dep})
|
||||||
endif()
|
endif()
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES ${publicDep})
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep})
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@ -602,7 +600,7 @@ function(add_qt_module name)
|
|||||||
)
|
)
|
||||||
include(${configureFile})
|
include(${configureFile})
|
||||||
qt_feature_module_end("${target}")
|
qt_feature_module_end("${target}")
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES PRIVATE_FEATURES "${target}")
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES PRIVATE_FEATURES "${target}")
|
||||||
|
|
||||||
set_property(TARGET "${target}" APPEND PROPERTY PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/qt${_arg_CONFIG_MODULE_NAME}-config.h")
|
set_property(TARGET "${target}" APPEND PROPERTY PUBLIC_HEADER "${CMAKE_CURRENT_BINARY_DIR}/qt${_arg_CONFIG_MODULE_NAME}-config.h")
|
||||||
set_property(TARGET "${target}" APPEND PROPERTY PRIVATE_HEADER "${CMAKE_CURRENT_BINARY_DIR}/qt${_arg_CONFIG_MODULE_NAME}-config_p.h")
|
set_property(TARGET "${target}" APPEND PROPERTY PRIVATE_HEADER "${CMAKE_CURRENT_BINARY_DIR}/qt${_arg_CONFIG_MODULE_NAME}-config_p.h")
|
||||||
@ -665,7 +663,7 @@ function(add_qt_module name)
|
|||||||
qt_internal_add_linker_version_script("${target}")
|
qt_internal_add_linker_version_script("${target}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES PRIVATE_FEATURES ${_arg_FEATURE_DEPENDENCIES})
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES PRIVATE_FEATURES ${_arg_FEATURE_DEPENDENCIES})
|
||||||
|
|
||||||
install(TARGETS "${target}" "${target_private}" EXPORT "${versioned_module_name}Targets"
|
install(TARGETS "${target}" "${target_private}" EXPORT "${versioned_module_name}Targets"
|
||||||
LIBRARY DESTINATION ${INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${INSTALL_LIBDIR}
|
||||||
@ -726,6 +724,8 @@ function(add_qt_module name)
|
|||||||
$<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()
|
||||||
|
|
||||||
|
|
||||||
@ -748,19 +748,17 @@ function(add_qt_plugin name)
|
|||||||
set_target_properties("${module}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}")
|
set_target_properties("${module}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}")
|
||||||
|
|
||||||
# Import global features
|
# Import global features
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES PRIVATE_FEATURES FEATURE_PROPERTY_INFIX "GLOBAL_" Qt::Core)
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES PRIVATE_FEATURES FEATURE_PROPERTY_INFIX "GLOBAL_" Qt::Core)
|
||||||
|
|
||||||
# Fetch features from dependencies and make them available to the
|
# Fetch features from dependencies and make them available to the
|
||||||
# caller as well as to the local scope for configure.cmake evaluation.
|
# caller as well as to the local scope for configure.cmake evaluation.
|
||||||
foreach(dep ${_arg_LIBRARIES} ${_arg_PUBLIC_LIBRARIES})
|
foreach(dep ${_arg_LIBRARIES} ${_arg_PUBLIC_LIBRARIES})
|
||||||
if("${dep}" MATCHES "(Qt::.+)Private")
|
if("${dep}" MATCHES "(Qt::.+)Private")
|
||||||
set(publicDep ${CMAKE_MATCH_1})
|
set(publicDep ${CMAKE_MATCH_1})
|
||||||
qt_push_features_into_parent_scope(PRIVATE_FEATURES ${publicDep})
|
|
||||||
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep})
|
qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep})
|
||||||
else()
|
else()
|
||||||
set(publicDep ${dep})
|
set(publicDep ${dep})
|
||||||
endif()
|
endif()
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES ${publicDep})
|
|
||||||
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep})
|
qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
@ -806,6 +804,8 @@ function(add_qt_plugin name)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
qt_internal_add_linker_version_script(${module})
|
qt_internal_add_linker_version_script(${module})
|
||||||
|
|
||||||
|
qt_push_features_into_parent_scope()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
@ -838,6 +838,8 @@ 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()
|
||||||
|
|
||||||
|
|
||||||
@ -862,6 +864,8 @@ 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()
|
||||||
|
|
||||||
|
|
||||||
@ -869,6 +873,7 @@ 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()
|
||||||
|
|
||||||
|
|
||||||
@ -899,6 +904,7 @@ function(add_qt_tool name)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ function(qt_feature_module_begin)
|
|||||||
set(__QtFeature_private_extra "" PARENT_SCOPE)
|
set(__QtFeature_private_extra "" PARENT_SCOPE)
|
||||||
set(__QtFeature_public_extra "" PARENT_SCOPE)
|
set(__QtFeature_public_extra "" PARENT_SCOPE)
|
||||||
|
|
||||||
qt_push_features_into_parent_scope(PUBLIC_FEATURES ${_arg_PUBLIC_DEPENDENCIES})
|
qt_push_features_into_parent_scope()
|
||||||
qt_push_features_into_parent_scope(PRIVATE_FEATURES ${_arg_PRIVATE_DEPENDENCIES})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(qt_feature _feature)
|
function(qt_feature _feature)
|
||||||
@ -181,7 +180,6 @@ macro(qt_feature_set_value feature cache 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_VALUE_${feature} "${result}" CACHE INTERNAL "${_arg_LABEL}")
|
|
||||||
set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE)
|
set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -193,6 +191,7 @@ function(qt_evaluate_feature _feature)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT DEFINED _QT_FEATURE_DEFINITION_${_feature})
|
if(NOT DEFINED _QT_FEATURE_DEFINITION_${_feature})
|
||||||
|
qt_debug_print_variables(DEDUP MATCH "^QT_FEATURE")
|
||||||
message(FATAL_ERROR "Attempting to evaluate feature ${_feature} but its definition is missing. Either the feature does not exist or a dependency to the module that defines it is missing")
|
message(FATAL_ERROR "Attempting to evaluate feature ${_feature} but its definition is missing. Either the feature does not exist or a dependency to the module that defines it is missing")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -200,8 +199,7 @@ function(qt_evaluate_feature _feature)
|
|||||||
"PRIVATE;PUBLIC"
|
"PRIVATE;PUBLIC"
|
||||||
"LABEL;PURPOSE;SECTION;" "AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF" ${_QT_FEATURE_DEFINITION_${_feature}})
|
"LABEL;PURPOSE;SECTION;" "AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF" ${_QT_FEATURE_DEFINITION_${_feature}})
|
||||||
|
|
||||||
if(DEFINED _QT_FEATURE_VALUE_${_feature})
|
if(DEFINED QT_FEATURE_${_feature})
|
||||||
set(QT_FEATURE_${_feature} ${_QT_FEATURE_VALUE_${_feature}} PARENT_SCOPE)
|
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -318,14 +316,8 @@ function(qt_feature_module_end target)
|
|||||||
set(all_features ${__QtFeature_public_features} ${__QtFeature_private_features})
|
set(all_features ${__QtFeature_public_features} ${__QtFeature_private_features})
|
||||||
list(REMOVE_DUPLICATES all_features)
|
list(REMOVE_DUPLICATES all_features)
|
||||||
|
|
||||||
foreach(feature ${all_features})
|
|
||||||
unset(_QT_FEATURE_VALUE_${feature} CACHE)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
foreach(feature ${all_features})
|
foreach(feature ${all_features})
|
||||||
qt_evaluate_feature(${feature})
|
qt_evaluate_feature(${feature})
|
||||||
|
|
||||||
set(QT_FEATURE_${feature} ${QT_FEATURE_${feature}} PARENT_SCOPE)
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set(enabled_public_features "")
|
set(enabled_public_features "")
|
||||||
@ -350,8 +342,7 @@ function(qt_feature_module_end target)
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
foreach(feature ${all_features})
|
foreach(feature ${all_features})
|
||||||
unset(_QT_FEATURE_VALUE_${feature} CACHE)
|
unset(_QT_FEATURE_DEFINITION_${feature} PARENT_SCOPE)
|
||||||
unset(_QT_FEATURE_DEFINITION_${feature} CACHE)
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
_qt_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_private_file}"
|
_qt_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_private_file}"
|
||||||
@ -389,6 +380,8 @@ 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)
|
||||||
@ -440,33 +433,14 @@ function(qt_pull_features_into_current_scope)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
macro(qt_push_features_into_parent_scope)
|
macro(qt_push_features_into_parent_scope)
|
||||||
cmake_parse_arguments(__arg "PUBLIC_FEATURES;PRIVATE_FEATURES" "FEATURE_PROPERTY_INFIX" "" ${ARGN})
|
get_cmake_property(__variableNames VARIABLES)
|
||||||
foreach(__target IN ITEMS ${__arg_UNPARSED_ARGUMENTS})
|
list (SORT __variableNames)
|
||||||
if(NOT TARGET ${__target})
|
list(REMOVE_DUPLICATES __variableNames)
|
||||||
continue()
|
|
||||||
|
foreach(__var ${__variableNames})
|
||||||
|
if(__var MATCHES "^QT_FEATURE_[a-z][a-z0-9_]*$")
|
||||||
|
set("${__var}" "${${__var}}" PARENT_SCOPE)
|
||||||
endif()
|
endif()
|
||||||
get_target_property(__target_type "${__target}" TYPE)
|
|
||||||
if("${__target_type}" STREQUAL "INTERFACE_LIBRARY")
|
|
||||||
set(__property_prefix "INTERFACE_")
|
|
||||||
else()
|
|
||||||
set(__property_prefix "")
|
|
||||||
endif()
|
|
||||||
foreach(__visibility PUBLIC PRIVATE)
|
|
||||||
set(__value ON)
|
|
||||||
foreach(__state ENABLED DISABLED)
|
|
||||||
if(NOT ${__arg_${__visibility}_FEATURES})
|
|
||||||
continue()
|
|
||||||
endif()
|
|
||||||
get_target_property(__features "${__target}" ${__property_prefix}QT_${__arg_FEATURE_PROPERTY_INFIX}${__state}_${__visibility}_FEATURES)
|
|
||||||
if("${__features}" STREQUAL "__features-NOTFOUND")
|
|
||||||
continue()
|
|
||||||
endif()
|
|
||||||
foreach(__feature ${__features})
|
|
||||||
set(QT_FEATURE_${__feature} ${__value} PARENT_SCOPE)
|
|
||||||
endforeach()
|
|
||||||
set(__value OFF)
|
|
||||||
endforeach()
|
|
||||||
endforeach()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user