diff options
author | Tobias Hunger <tobias.hunger@gmail.com> | 2018-11-02 11:42:58 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2018-11-05 15:01:58 +0000 |
commit | b7b4af575f119ddabe0f7f3e8c075306b347dda3 (patch) | |
tree | d96a47efdaf6065921da7a29dce573f662ba1c6f /cmake | |
parent | da7811dc758a99b4aee5737713d90a5c12959fc9 (diff) |
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>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 28 | ||||
-rw-r--r-- | cmake/QtFeature.cmake | 52 |
2 files changed, 30 insertions, 50 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 25cfe7e8ba..3a4f2fbc9c 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -442,10 +442,8 @@ function(extend_target target) # caller as well as to the local scope for configure.cmake evaluation. 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}) endif() - qt_push_features_into_parent_scope(PUBLIC_FEATURES ${depTarget}) qt_pull_features_into_current_scope(PUBLIC_FEATURES ${depTarget}) if(TARGET "${dep}") continue() @@ -462,6 +460,8 @@ function(extend_target target) target_compile_definitions("${target}" PUBLIC ${_arg_PUBLIC_DEFINES} PRIVATE ${_arg_DEFINES}) target_link_libraries("${target}" PUBLIC ${_arg_PUBLIC_LIBRARIES} PRIVATE ${_arg_LIBRARIES}) endif() + + qt_push_features_into_parent_scope() endfunction() @@ -549,20 +549,18 @@ function(add_qt_module name) # Import global features 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() # Fetch features from dependencies and make them available to the # 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") set(publicDep ${CMAKE_MATCH_1}) - qt_push_features_into_parent_scope(PRIVATE_FEATURES ${publicDep}) qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep}) else() set(publicDep ${dep}) endif() - qt_push_features_into_parent_scope(PUBLIC_FEATURES ${publicDep}) qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep}) endforeach() @@ -602,7 +600,7 @@ function(add_qt_module name) ) include(${configureFile}) 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 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}") 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" 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}/${module}> ) + + qt_push_features_into_parent_scope() endfunction() @@ -748,19 +748,17 @@ function(add_qt_plugin name) set_target_properties("${module}" PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}") # 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 # caller as well as to the local scope for configure.cmake evaluation. foreach(dep ${_arg_LIBRARIES} ${_arg_PUBLIC_LIBRARIES}) if("${dep}" MATCHES "(Qt::.+)Private") set(publicDep ${CMAKE_MATCH_1}) - qt_push_features_into_parent_scope(PRIVATE_FEATURES ${publicDep}) qt_pull_features_into_current_scope(PRIVATE_FEATURES ${publicDep}) else() set(publicDep ${dep}) endif() - qt_push_features_into_parent_scope(PUBLIC_FEATURES ${publicDep}) qt_pull_features_into_current_scope(PUBLIC_FEATURES ${publicDep}) endforeach() @@ -806,6 +804,8 @@ function(add_qt_plugin name) endif() qt_internal_add_linker_version_script(${module}) + + qt_push_features_into_parent_scope() endfunction() @@ -838,6 +838,8 @@ function(add_qt_executable name) WIN32_EXECUTABLE "${_arg_GUI}" MACOSX_BUNDLE "${_arg_GUI}" ) + + qt_push_features_into_parent_scope() endfunction() @@ -862,6 +864,8 @@ function(add_qt_test name) 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 "QT_PLUGIN_PATH=${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}") + + qt_push_features_into_parent_scope() endfunction() @@ -869,6 +873,7 @@ endfunction() # tests launch separate programs to test certainly input/output behavior. function(add_qt_test_helper name) add_qt_executable("${name}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ${ARGN}) + qt_push_features_into_parent_scope() endfunction() @@ -899,6 +904,7 @@ function(add_qt_tool name) endif() install(TARGETS "${name}" EXPORT "Qt${PROJECT_VERSION_MAJOR}ToolsTargets" DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) + qt_push_features_into_parent_scope() endfunction() diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 0a19fcd6bb..6330200fd1 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -22,8 +22,7 @@ function(qt_feature_module_begin) set(__QtFeature_private_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(PRIVATE_FEATURES ${_arg_PRIVATE_DEPENDENCIES}) + qt_push_features_into_parent_scope() endfunction() 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.") endif() - set(_QT_FEATURE_VALUE_${feature} "${result}" CACHE INTERNAL "${_arg_LABEL}") set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE) endmacro() @@ -193,6 +191,7 @@ function(qt_evaluate_feature _feature) endif() 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") endif() @@ -200,8 +199,7 @@ function(qt_evaluate_feature _feature) "PRIVATE;PUBLIC" "LABEL;PURPOSE;SECTION;" "AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF" ${_QT_FEATURE_DEFINITION_${_feature}}) - if(DEFINED _QT_FEATURE_VALUE_${_feature}) - set(QT_FEATURE_${_feature} ${_QT_FEATURE_VALUE_${_feature}} PARENT_SCOPE) + if(DEFINED QT_FEATURE_${_feature}) return() endif() @@ -319,13 +317,7 @@ function(qt_feature_module_end target) list(REMOVE_DUPLICATES all_features) foreach(feature ${all_features}) - unset(_QT_FEATURE_VALUE_${feature} CACHE) - endforeach() - - foreach(feature ${all_features}) qt_evaluate_feature(${feature}) - - set(QT_FEATURE_${feature} ${QT_FEATURE_${feature}} PARENT_SCOPE) endforeach() set(enabled_public_features "") @@ -350,8 +342,7 @@ function(qt_feature_module_end target) endforeach() foreach(feature ${all_features}) - unset(_QT_FEATURE_VALUE_${feature} CACHE) - unset(_QT_FEATURE_DEFINITION_${feature} CACHE) + unset(_QT_FEATURE_DEFINITION_${feature} PARENT_SCOPE) endforeach() _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_public_extra PARENT_SCOPE) + + qt_push_features_into_parent_scope() endfunction() function(qt_config_compile_test name) @@ -440,33 +433,14 @@ function(qt_pull_features_into_current_scope) endfunction() macro(qt_push_features_into_parent_scope) - cmake_parse_arguments(__arg "PUBLIC_FEATURES;PRIVATE_FEATURES" "FEATURE_PROPERTY_INFIX" "" ${ARGN}) - foreach(__target IN ITEMS ${__arg_UNPARSED_ARGUMENTS}) - if(NOT TARGET ${__target}) - continue() - endif() - get_target_property(__target_type "${__target}" TYPE) - if("${__target_type}" STREQUAL "INTERFACE_LIBRARY") - set(__property_prefix "INTERFACE_") - else() - set(__property_prefix "") + get_cmake_property(__variableNames VARIABLES) + list (SORT __variableNames) + list(REMOVE_DUPLICATES __variableNames) + + foreach(__var ${__variableNames}) + if(__var MATCHES "^QT_FEATURE_[a-z][a-z0-9_]*$") + set("${__var}" "${${__var}}" PARENT_SCOPE) 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() endmacro() |