CMake: Get rid of useless underscores in QtFeature.cmake

Change-Id: I87eb55ed2ce01ab136dac3e2a587b43bd3f8a98e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Tobias Hunger 2018-12-11 16:02:39 +01:00
parent 42d6e5c5fa
commit 07dfa3013c

View File

@ -1,23 +1,23 @@
function(qt_feature_module_begin) function(qt_feature_module_begin)
qt_parse_all_arguments(_arg "qt_feature_module_begin" qt_parse_all_arguments(arg "qt_feature_module_begin"
"" "LIBRARY;PRIVATE_FILE;PUBLIC_FILE" "PUBLIC_DEPENDENCIES;PRIVATE_DEPENDENCIES" ${ARGN}) "" "LIBRARY;PRIVATE_FILE;PUBLIC_FILE" "PUBLIC_DEPENDENCIES;PRIVATE_DEPENDENCIES" ${ARGN})
if ("${_arg_LIBRARY}" STREQUAL "") if ("${arg_LIBRARY}" STREQUAL "")
message(FATAL_ERROR "qt_feature_begin_module needs a LIBRARY name!") message(FATAL_ERROR "qt_feature_begin_module needs a LIBRARY name!")
endif() endif()
if ("${_arg_PUBLIC_FILE}" STREQUAL "") if ("${arg_PUBLIC_FILE}" STREQUAL "")
message(FATAL_ERROR "qt_feature_begin_module needs a PUBLIC_FILE name!") message(FATAL_ERROR "qt_feature_begin_module needs a PUBLIC_FILE name!")
endif() endif()
if ("${_arg_PRIVATE_FILE}" STREQUAL "") if ("${arg_PRIVATE_FILE}" STREQUAL "")
message(FATAL_ERROR "qt_feature_begin_module needs a PRIVATE_FILE name!") message(FATAL_ERROR "qt_feature_begin_module needs a PRIVATE_FILE name!")
endif() endif()
set(__QtFeature_library "${_arg_LIBRARY}" PARENT_SCOPE) set(__QtFeature_library "${arg_LIBRARY}" PARENT_SCOPE)
set(__QtFeature_private_features "" PARENT_SCOPE) set(__QtFeature_private_features "" PARENT_SCOPE)
set(__QtFeature_public_features "" PARENT_SCOPE) set(__QtFeature_public_features "" PARENT_SCOPE)
set(__QtFeature_private_file "${_arg_PRIVATE_FILE}" PARENT_SCOPE) set(__QtFeature_private_file "${arg_PRIVATE_FILE}" PARENT_SCOPE)
set(__QtFeature_public_file "${_arg_PUBLIC_FILE}" PARENT_SCOPE) set(__QtFeature_public_file "${arg_PUBLIC_FILE}" PARENT_SCOPE)
set(__QtFeature_private_extra "" PARENT_SCOPE) set(__QtFeature_private_extra "" PARENT_SCOPE)
set(__QtFeature_public_extra "" PARENT_SCOPE) set(__QtFeature_public_extra "" PARENT_SCOPE)
@ -25,19 +25,19 @@ function(qt_feature_module_begin)
qt_push_features_into_parent_scope() qt_push_features_into_parent_scope()
endfunction() endfunction()
function(qt_feature _feature) function(qt_feature feature)
qt_parse_all_arguments(_arg "qt_feature" qt_parse_all_arguments(arg "qt_feature"
"PRIVATE;PUBLIC" "PRIVATE;PUBLIC"
"LABEL;PURPOSE;SECTION;" "AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF" ${ARGN}) "LABEL;PURPOSE;SECTION;" "AUTODETECT;CONDITION;ENABLE;DISABLE;EMIT_IF" ${ARGN})
set(_QT_FEATURE_DEFINITION_${_feature} ${ARGN} PARENT_SCOPE) set(_QT_FEATURE_DEFINITION_${feature} ${ARGN} PARENT_SCOPE)
# Register feature for future use: # Register feature for future use:
if (_arg_PUBLIC) if (arg_PUBLIC)
list(APPEND __QtFeature_public_features "${_feature}") list(APPEND __QtFeature_public_features "${feature}")
endif() endif()
if (_arg_PRIVATE) if (arg_PRIVATE)
list(APPEND __QtFeature_private_features "${_feature}") list(APPEND __QtFeature_private_features "${feature}")
endif() endif()
set(__QtFeature_public_features ${__QtFeature_public_features} PARENT_SCOPE) set(__QtFeature_public_features ${__QtFeature_public_features} PARENT_SCOPE)
@ -185,133 +185,132 @@ macro(qt_feature_set_value feature cache emit_if condition label)
set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE) set(QT_FEATURE_${feature} "${result}" PARENT_SCOPE)
endmacro() endmacro()
function(qt_evaluate_feature _feature) function(qt_evaluate_feature feature)
# If the feature was set explicitly by the user to be on or off, in the cache, then # If the feature was set explicitly by the user to be on or off, in the cache, then
# there's nothing for us to do. # there's nothing for us to do.
if(DEFINED "QT_FEATURE_${_feature}") if(DEFINED "QT_FEATURE_${feature}")
return() return()
endif() endif()
if(NOT DEFINED _QT_FEATURE_DEFINITION_${_feature}) if(NOT DEFINED _QT_FEATURE_DEFINITION_${feature})
qt_debug_print_variables(DEDUP MATCH "^QT_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()
cmake_parse_arguments(_arg cmake_parse_arguments(arg
"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_${_feature}) if(DEFINED QT_FEATURE_${feature})
return() return()
endif() endif()
if("${_arg_ENABLE}" STREQUAL "") if("${arg_ENABLE}" STREQUAL "")
set(_arg_ENABLE OFF) set(arg_ENABLE OFF)
endif() endif()
if("${_arg_DISABLE}" STREQUAL "") if("${arg_DISABLE}" STREQUAL "")
set(_arg_DISABLE OFF) set(arg_DISABLE OFF)
endif() endif()
if("${_arg_AUTODETECT}" STREQUAL "") if("${arg_AUTODETECT}" STREQUAL "")
set(_arg_AUTODETECT ON) set(arg_AUTODETECT ON)
endif() endif()
if("${_arg_CONDITION}" STREQUAL "") if("${arg_CONDITION}" STREQUAL "")
set(condition ON) set(condition ON)
else() else()
qt_evaluate_config_expression(condition ${_arg_CONDITION}) qt_evaluate_config_expression(condition ${arg_CONDITION})
endif() endif()
if(${_arg_DISABLE}) if(${arg_DISABLE})
set(result OFF) set(result OFF)
elseif((${_arg_ENABLE}) OR (${_arg_AUTODETECT})) elseif((${arg_ENABLE}) OR (${arg_AUTODETECT}))
set(result ${condition}) set(result ${condition})
else() else()
# feature not auto-detected and not explicitly enabled # feature not auto-detected and not explicitly enabled
set(result OFF) set(result OFF)
endif() endif()
if("${_arg_EMIT_IF}" STREQUAL "") if("${arg_EMIT_IF}" STREQUAL "")
set(emit_if ON) set(emit_if ON)
else() else()
qt_evaluate_config_expression(emit_if ${_arg_EMIT_IF}) qt_evaluate_config_expression(emit_if ${arg_EMIT_IF})
endif() endif()
if (NOT (condition) AND (calculated)) if (NOT (condition) AND (calculated))
message(FATAL_ERROR "Sanity check failed: Feature ${_feature} is enabled but condition does not hold true.") message(FATAL_ERROR "Sanity check failed: Feature ${feature} is enabled but condition does not hold true.")
endif() endif()
qt_feature_set_cache_value(cache "${_feature}" "${emit_if}" "${result}" "${_arg_LABEL}") qt_feature_set_cache_value(cache "${feature}" "${emit_if}" "${result}" "${arg_LABEL}")
qt_feature_set_value("${_feature}" "${cache}" "${emit_if}" "${condition}" "${_arg_LABEL}") qt_feature_set_value("${feature}" "${cache}" "${emit_if}" "${condition}" "${arg_LABEL}")
endfunction() endfunction()
function(qt_feature_definition _feature _name) function(qt_feature_definition feature name)
qt_parse_all_arguments(_arg "qt_feature_definition" "NEGATE" "VALUE" "" ${ARGN}) qt_parse_all_arguments(arg "qt_feature_definition" "NEGATE" "VALUE" "" ${ARGN})
# Generate code: # Generate code:
set(_expected 1) set(expected 1)
if (_arg_NEGATE) if (arg_NEGATE)
set(_expected -1) set(expected -1)
endif() endif()
set(_msg "\n#if defined(QT_FEATURE_${_feature}) && QT_FEATURE_${_feature} == ${_expected}\n") set(msg "\n#if defined(QT_FEATURE_${feature}) && QT_FEATURE_${feature} == ${expected}\n")
if (_arg_VALUE) if (arg_VALUE)
string(APPEND _msg "# define ${_name} ${_arg_VALUE}\n") string(APPEND msg "# define ${name} ${arg_VALUE}\n")
else() else()
string(APPEND _msg "# define ${_name}\n") string(APPEND msg "# define ${name}\n")
endif() endif()
string(APPEND _msg "#endif\n") string(APPEND msg "#endif\n")
# Store for later use: # Store for later use:
list(FIND __QtFeature_public_features "${_feature}" _public_index) list(FIND __QtFeature_public_features "${feature}" public_index)
if (_public_index GREATER -1) if (public_index GREATER -1)
string(APPEND __QtFeature_public_extra "${_msg}") string(APPEND __QtFeature_public_extra "${msg}")
endif() endif()
list(FIND __QtFeature_private_features "${_feature}" _private_index) list(FIND __QtFeature_private_features "${feature}" private_index)
if (_private_index GREATER -1) if (private_index GREATER -1)
string(APPEND __QtFeature_private_extra "${_msg}") string(APPEND __QtFeature_private_extra "${msg}")
endif() endif()
set(__QtFeature_public_extra ${__QtFeature_public_extra} PARENT_SCOPE) set(__QtFeature_public_extra ${__QtFeature_public_extra} PARENT_SCOPE)
set(__QtFeature_private_extra ${__QtFeature_private_extra} PARENT_SCOPE) set(__QtFeature_private_extra ${__QtFeature_private_extra} PARENT_SCOPE)
endfunction() endfunction()
function(qt_extra_definition _name _value) function(qt_extra_definition name value)
qt_parse_all_arguments(_arg "qt_extra_definition" "PUBLIC;PRIVATE" "" "" ${ARGN}) qt_parse_all_arguments(arg "qt_extra_definition" "PUBLIC;PRIVATE" "" "" ${ARGN})
if (_arg_PUBLIC) if (arg_PUBLIC)
string(APPEND __QtFeature_public_extra "\n#define ${_name} ${_value}\n") string(APPEND __QtFeature_public_extra "\n#define ${name} ${value}\n")
elseif(_arg_PRIVATE) elseif(arg_PRIVATE)
string(APPEND __QtFeature_private_extra "\n#define ${_name} ${_value}\n") string(APPEND __QtFeature_private_extra "\n#define ${name} ${value}\n")
endif() endif()
set(__QtFeature_public_extra ${__QtFeature_public_extra} PARENT_SCOPE) set(__QtFeature_public_extra ${__QtFeature_public_extra} PARENT_SCOPE)
set(__QtFeature_private_extra ${__QtFeature_private_extra} PARENT_SCOPE) set(__QtFeature_private_extra ${__QtFeature_private_extra} PARENT_SCOPE)
endfunction() endfunction()
function(_qt_generate_feature_line _line _feature) function(qt_internal_generate_feature_line line feature)
set(_line "") if (QT_FEATURE_${feature} STREQUAL "ON")
if (QT_FEATURE_${_feature} STREQUAL "ON") set(line "#define QT_FEATURE_${feature} 1\n\n" PARENT_SCOPE)
set(_line "#define QT_FEATURE_${_feature} 1\n\n" PARENT_SCOPE) elseif(QT_FEATURE_${feature} STREQUAL "OFF")
elseif(QT_FEATURE_${_feature} STREQUAL "OFF") set(line "#define QT_FEATURE_${feature} -1\n\n" PARENT_SCOPE)
set(_line "#define QT_FEATURE_${_feature} -1\n\n" PARENT_SCOPE) elseif(QT_FEATURE_${feature} STREQUAL "UNSET")
elseif(QT_FEATURE_${_feature} STREQUAL "UNSET") set(line "#define QT_FEATURE_${feature} 0\n\n" PARENT_SCOPE)
set(_line "#define QT_FEATURE_${_feature} 0\n\n" PARENT_SCOPE)
else() else()
message(FATAL_ERROR "${_feature} has unexpected value \"${QT_FEATURE_${_feature}}\"!") message(FATAL_ERROR "${feature} has unexpected value \"${QT_FEATURE_${feature}}\"!")
endif() endif()
endfunction() endfunction()
function(_qt_feature_write_file _file _features _extra) function(qt_internal_feature_write_file file features extra)
message("Generating file ${_file}.") message("Generating file ${file}.")
set(_contents "") set(contents "")
foreach(_it ${_features}) foreach(it ${features})
_qt_generate_feature_line(_line "${_it}") qt_internal_generate_feature_line(line "${it}")
string(APPEND _contents "${_line}") string(APPEND contents "${line}")
endforeach() endforeach()
string(APPEND _contents "${_extra}") string(APPEND contents "${extra}")
file(GENERATE OUTPUT "${_file}" CONTENT "${_contents}") file(GENERATE OUTPUT "${file}" CONTENT "${contents}")
endfunction() endfunction()
function(qt_feature_module_end target) function(qt_feature_module_end target)
@ -347,12 +346,12 @@ function(qt_feature_module_end target)
unset(_QT_FEATURE_DEFINITION_${feature} PARENT_SCOPE) unset(_QT_FEATURE_DEFINITION_${feature} PARENT_SCOPE)
endforeach() endforeach()
_qt_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_private_file}" qt_internal_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_private_file}"
"${__QtFeature_private_features}" "${__QtFeature_private_extra}" "${__QtFeature_private_features}" "${__QtFeature_private_extra}"
) )
qt_generate_forwarding_headers("${__QtFeature_library}" SOURCE "${__QtFeature_private_file}" PRIVATE) qt_generate_forwarding_headers("${__QtFeature_library}" SOURCE "${__QtFeature_private_file}" PRIVATE)
_qt_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_public_file}" qt_internal_feature_write_file("${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_public_file}"
"${__QtFeature_public_features}" "${__QtFeature_public_extra}" "${__QtFeature_public_features}" "${__QtFeature_public_extra}"
) )
qt_generate_forwarding_headers("${__QtFeature_library}" SOURCE "${__QtFeature_public_file}") qt_generate_forwarding_headers("${__QtFeature_library}" SOURCE "${__QtFeature_public_file}")
@ -387,10 +386,10 @@ function(qt_feature_module_end target)
endfunction() endfunction()
function(qt_config_compile_test name) function(qt_config_compile_test name)
cmake_parse_arguments(_arg "" "LABEL" "" ${ARGN}) cmake_parse_arguments(arg "" "LABEL" "" ${ARGN})
check_cxx_source_compiles("${_arg_UNPARSED_ARGUMENTS}" HAVE_${name}) check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS}" HAVE_${name})
set(TEST_${name} "${HAVE_${name}}" CACHE INTERNAL "${_arg_LABEL}") set(TEST_${name} "${HAVE_${name}}" CACHE INTERNAL "${arg_LABEL}")
endfunction() endfunction()
function(qt_config_compile_test_x86simd extension label) function(qt_config_compile_test_x86simd extension label)
@ -404,44 +403,44 @@ function(qt_config_compile_test_x86simd extension label)
endfunction() endfunction()
function(qt_pull_features_into_current_scope) function(qt_pull_features_into_current_scope)
cmake_parse_arguments(__arg "PUBLIC_FEATURES;PRIVATE_FEATURES" "FEATURE_PROPERTY_INFIX" "" ${ARGN}) cmake_parse_arguments(arg "PUBLIC_FEATURES;PRIVATE_FEATURES" "FEATURE_PROPERTY_INFIX" "" ${ARGN})
foreach(__target IN ITEMS ${__arg_UNPARSED_ARGUMENTS}) foreach(target IN ITEMS ${arg_UNPARSED_ARGUMENTS})
if(NOT TARGET ${__target}) if(NOT TARGET ${target})
continue() continue()
endif() 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 PUBLIC PRIVATE) foreach(visibility PUBLIC PRIVATE)
set(__value ON) set(value ON)
foreach(__state ENABLED DISABLED) foreach(state ENABLED DISABLED)
if(NOT ${__arg_${__visibility}_FEATURES}) if(NOT ${arg_${visibility}_FEATURES})
continue() continue()
endif() endif()
get_target_property(__features "${__target}" ${__property_prefix}QT_${__arg_FEATURE_PROPERTY_INFIX}${__state}_${__visibility}_FEATURES) get_target_property(features "${target}" ${property_prefix}QT_${arg_FEATURE_PROPERTY_INFIX}${state}_${visibility}_FEATURES)
if("${__features}" STREQUAL "__features-NOTFOUND") if("${features}" STREQUAL "features-NOTFOUND")
continue() continue()
endif() endif()
foreach(__feature ${__features}) foreach(feature ${features})
set(QT_FEATURE_${__feature} ${__value} PARENT_SCOPE) set(QT_FEATURE_${feature} ${value} PARENT_SCOPE)
endforeach() endforeach()
set(__value OFF) set(value OFF)
endforeach() endforeach()
endforeach() endforeach()
endforeach() endforeach()
endfunction() endfunction()
macro(qt_push_features_into_parent_scope) macro(qt_push_features_into_parent_scope)
get_cmake_property(__variableNames VARIABLES) get_cmake_property(_variableNames VARIABLES)
list (SORT __variableNames) list (SORT _variableNames)
list(REMOVE_DUPLICATES __variableNames) list(REMOVE_DUPLICATES _variableNames)
foreach(__var ${__variableNames}) foreach(_var ${_variableNames})
if(__var MATCHES "^QT_FEATURE_[a-z][a-z0-9_]*$") if(_var MATCHES "^QT_FEATURE_[a-z][a-z0-9_]*$")
set("${__var}" "${${__var}}" PARENT_SCOPE) set("${_var}" "${${_var}}" PARENT_SCOPE)
endif() endif()
endforeach() endforeach()
endmacro() endmacro()