2018-10-24 13:20:27 +00:00
function ( qt_feature_module_begin )
2018-12-11 15:02:39 +00:00
qt_parse_all_arguments ( arg "qt_feature_module_begin"
2019-02-12 11:00:49 +00:00
" N O _ M O D U L E " " L I B R A R Y ; P R I V A T E _ F I L E ; P U B L I C _ F I L E " " P U B L I C _ D E P E N D E N C I E S ; P R I V A T E _ D E P E N D E N C I E S " $ { A R G N } )
2018-10-24 13:20:27 +00:00
2019-02-12 11:00:49 +00:00
if ( "${arg_LIBRARY}" STREQUAL "" AND ( NOT ${ arg_NO_MODULE } ) )
message ( FATAL_ERROR "qt_feature_begin_module needs a LIBRARY name! (or specify NO_MODULE)" )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_PUBLIC_FILE}" STREQUAL "" )
2018-10-24 13:20:27 +00:00
message ( FATAL_ERROR "qt_feature_begin_module needs a PUBLIC_FILE name!" )
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_PRIVATE_FILE}" STREQUAL "" )
2018-10-24 13:20:27 +00:00
message ( FATAL_ERROR "qt_feature_begin_module needs a PRIVATE_FILE name!" )
endif ( )
2018-12-11 15:02:39 +00:00
set ( __QtFeature_library "${arg_LIBRARY}" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
set ( __QtFeature_public_features "" PARENT_SCOPE )
2019-03-20 16:36:25 +00:00
set ( __QtFeature_private_features "" PARENT_SCOPE )
set ( __QtFeature_internal_features "" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
2018-12-11 15:02:39 +00:00
set ( __QtFeature_private_file "${arg_PRIVATE_FILE}" PARENT_SCOPE )
set ( __QtFeature_public_file "${arg_PUBLIC_FILE}" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
set ( __QtFeature_private_extra "" PARENT_SCOPE )
set ( __QtFeature_public_extra "" PARENT_SCOPE )
2019-03-14 10:27:38 +00:00
set ( __QtFeature_define_definitions "" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2018-12-11 15:02:39 +00:00
function ( qt_feature feature )
qt_parse_all_arguments ( arg "qt_feature"
2018-10-24 13:20:27 +00:00
" P R I V A T E ; P U B L I C "
" L A B E L ; P U R P O S E ; S E C T I O N ; " " A U T O D E T E C T ; C O N D I T I O N ; E N A B L E ; D I S A B L E ; E M I T _ I F " $ { A R G N } )
2018-12-11 15:02:39 +00:00
set ( _QT_FEATURE_DEFINITION_ ${ feature } ${ ARGN } PARENT_SCOPE )
2018-10-25 12:28:06 +00:00
2018-10-25 11:16:42 +00:00
# Register feature for future use:
2018-12-11 15:02:39 +00:00
if ( arg_PUBLIC )
list ( APPEND __QtFeature_public_features "${feature}" )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
if ( arg_PRIVATE )
list ( APPEND __QtFeature_private_features "${feature}" )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-20 16:36:25 +00:00
if ( NOT arg_PUBLIC AND NOT arg_PRIVATE )
list ( APPEND __QtFeature_internal_features "${feature}" )
endif ( )
2018-10-25 11:16:42 +00:00
2018-10-24 13:20:27 +00:00
set ( __QtFeature_public_features ${ __QtFeature_public_features } PARENT_SCOPE )
set ( __QtFeature_private_features ${ __QtFeature_private_features } PARENT_SCOPE )
2019-03-20 16:36:25 +00:00
set ( __QtFeature_internal_features ${ __QtFeature_internal_features } PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
function ( qt_evaluate_to_boolean expressionVar )
if ( ${ ${expressionVar } } )
set ( ${ expressionVar } ON PARENT_SCOPE )
else ( )
set ( ${ expressionVar } OFF PARENT_SCOPE )
endif ( )
endfunction ( )
function ( qt_evaluate_config_expression resultVar )
set ( result "" )
set ( nestingLevel 0 )
set ( skipNext OFF )
set ( expression "${ARGN}" )
list ( LENGTH expression length )
math ( EXPR length "${length}-1" )
foreach ( memberIdx RANGE ${ length } )
if ( ${ skipNext } )
set ( skipNext OFF )
continue ( )
endif ( )
list ( GET expression ${ memberIdx } member )
if ( "${member}" STREQUAL "(" )
if ( ${ nestingLevel } GREATER 0 )
list ( APPEND result ${ member } )
endif ( )
math ( EXPR nestingLevel "${nestingLevel} + 1" )
continue ( )
elseif ( "${member}" STREQUAL ")" )
math ( EXPR nestingLevel "${nestingLevel} - 1" )
if ( nestingLevel LESS 0 )
break ( )
endif ( )
if ( ${ nestingLevel } EQUAL 0 )
qt_evaluate_config_expression ( result ${ result } )
else ( )
list ( APPEND result ${ member } )
endif ( )
continue ( )
elseif ( ${ nestingLevel } GREATER 0 )
list ( APPEND result ${ member } )
continue ( )
elseif ( "${member}" STREQUAL "NOT" )
list ( APPEND result ${ member } )
continue ( )
elseif ( "${member}" STREQUAL "AND" )
qt_evaluate_to_boolean ( result )
if ( NOT ${ result } )
break ( )
endif ( )
set ( result "" )
elseif ( "${member}" STREQUAL "OR" )
qt_evaluate_to_boolean ( result )
if ( ${ result } )
break ( )
endif ( )
set ( result "" )
elseif ( "${member}" STREQUAL "STREQUAL" AND memberIdx LESS ${ length } )
# Unfortunately the semantics for STREQUAL in if() are broken when the
# RHS is an empty string and the parameters to if are coming through a variable.
2018-10-25 11:16:42 +00:00
# So we expect people to write the empty string with single quotes and then we
2018-10-24 13:20:27 +00:00
# do the comparison manually here.
list ( LENGTH result lhsIndex )
math ( EXPR lhsIndex "${lhsIndex}-1" )
list ( GET result ${ lhsIndex } lhs )
list ( REMOVE_AT result ${ lhsIndex } )
set ( lhs "${${lhs}}" )
math ( EXPR rhsIndex "${memberIdx}+1" )
set ( skipNext ON )
list ( GET expression ${ rhsIndex } rhs )
# We can't pass through an empty string with double quotes through various
# stages of substitution, so instead it is represented using single quotes
# and resolve here.
string ( REGEX REPLACE "'(.*)'" "\\1" rhs "${rhs}" )
string ( COMPARE EQUAL "${lhs}" "${rhs}" stringCompareResult )
list ( APPEND result ${ stringCompareResult } )
else ( )
string ( FIND "${member}" "QT_FEATURE_" idx )
if ( idx EQUAL 0 )
# Remove the QT_FEATURE_ prefix
string ( SUBSTRING "${member}" 11 -1 feature )
qt_evaluate_feature ( ${ feature } )
endif ( )
list ( APPEND result ${ member } )
endif ( )
endforeach ( )
2019-06-04 15:34:27 +00:00
# The 'TARGET Gui' case is handled by qt_evaluate_to_boolean, by passing those tokens verbatim
# to if().
2018-10-24 13:20:27 +00:00
if ( "${result}" STREQUAL "" )
set ( result ON )
else ( )
qt_evaluate_to_boolean ( result )
endif ( )
set ( ${ resultVar } ${ result } PARENT_SCOPE )
endfunction ( )
2018-10-26 09:49:58 +00:00
function ( qt_feature_set_cache_value resultVar feature emit_if calculated label )
if ( DEFINED "FEATURE_${feature}" )
# Must set up the cache
if ( NOT ( emit_if ) )
message ( FATAL_ERROR "Sanity check failed: FEATURE_${feature} that was not emitted was found in the CMakeCache." )
endif ( )
# Revisit value:
set ( cache "${FEATURE_${feature}}" )
if ( ( cache STREQUAL "ON" ) OR ( cache STREQUAL "OFF" ) )
set ( result "${cache}" )
else ( )
message ( FATAL_ERROR "Sanity check failed: FEATURE_${feature} has invalid value \" ${ cache } \"!")
endif ( )
# Fix-up user-provided values
set ( "FEATURE_${feature}" "${cache}" CACHE BOOL "${label}" )
else ( )
# Initial setup:
if ( emit_if )
set ( "FEATURE_${feature}" "${calculated}" CACHE BOOL "${label}" )
2018-11-14 13:24:34 +00:00
set ( result "${calculated}" )
else ( )
set ( result OFF )
2018-10-26 09:49:58 +00:00
endif ( )
endif ( )
set ( "${resultVar}" "${result}" PARENT_SCOPE )
endfunction ( )
2018-11-14 13:24:34 +00:00
macro ( qt_feature_set_value feature cache emit_if condition label )
2018-10-26 09:49:58 +00:00
set ( result "${cache}" )
if ( NOT ( condition ) AND ( cache ) )
message ( SEND_ERROR "Feature \" ${ feature } \": Forcing to \"${cache}\" breaks its condition. " )
endif ( )
2019-01-14 10:35:53 +00:00
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}" )
2018-10-26 09:49:58 +00:00
endmacro ( )
2018-12-11 15:02:39 +00:00
function ( qt_evaluate_feature feature )
2018-10-24 13:20:27 +00:00
# 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.
2018-12-11 15:02:39 +00:00
if ( DEFINED "QT_FEATURE_${feature}" )
2018-10-24 13:20:27 +00:00
return ( )
endif ( )
2018-12-11 15:02:39 +00:00
if ( NOT DEFINED _QT_FEATURE_DEFINITION_ ${ feature } )
2018-11-02 10:42:58 +00:00
qt_debug_print_variables ( DEDUP MATCH "^QT_FEATURE" )
2018-12-11 15:02:39 +00:00
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" )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
cmake_parse_arguments ( arg
2018-10-24 13:20:27 +00:00
" P R I V A T E ; P U B L I C "
2018-12-11 15:02:39 +00:00
" L A B E L ; P U R P O S E ; S E C T I O N ; " " A U T O D E T E C T ; C O N D I T I O N ; E N A B L E ; D I S A B L E ; E M I T _ I F " $ { _ Q T _ F E A T U R E _ D E F I N I T I O N _ $ { f e a t u r e } } )
2018-10-24 13:20:27 +00:00
2018-12-11 15:02:39 +00:00
if ( DEFINED QT_FEATURE_ ${ feature } )
2018-10-24 13:20:27 +00:00
return ( )
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_ENABLE}" STREQUAL "" )
set ( arg_ENABLE OFF )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_DISABLE}" STREQUAL "" )
set ( arg_DISABLE OFF )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_AUTODETECT}" STREQUAL "" )
set ( arg_AUTODETECT ON )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_CONDITION}" STREQUAL "" )
2018-10-25 12:28:06 +00:00
set ( condition ON )
else ( )
2018-12-11 15:02:39 +00:00
qt_evaluate_config_expression ( condition ${ arg_CONDITION } )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-13 12:55:56 +00:00
qt_evaluate_config_expression ( disable_result ${ arg_DISABLE } )
qt_evaluate_config_expression ( enable_result ${ arg_ENABLE } )
if ( ${ disable_result } )
2018-10-24 13:20:27 +00:00
set ( result OFF )
2019-03-13 12:55:56 +00:00
elseif ( ( ${ enable_result } ) OR ( ${ arg_AUTODETECT } ) )
2018-10-25 12:28:06 +00:00
set ( result ${ condition } )
2018-10-24 13:20:27 +00:00
else ( )
# feature not auto-detected and not explicitly enabled
set ( result OFF )
endif ( )
2018-12-11 15:02:39 +00:00
if ( "${arg_EMIT_IF}" STREQUAL "" )
2018-10-25 12:28:06 +00:00
set ( emit_if ON )
else ( )
2018-12-11 15:02:39 +00:00
qt_evaluate_config_expression ( emit_if ${ arg_EMIT_IF } )
2018-10-25 11:16:42 +00:00
endif ( )
2018-10-26 09:49:58 +00:00
if ( NOT ( condition ) AND ( calculated ) )
2018-12-11 15:02:39 +00:00
message ( FATAL_ERROR "Sanity check failed: Feature ${feature} is enabled but condition does not hold true." )
2018-10-25 11:16:42 +00:00
endif ( )
2018-10-25 12:28:06 +00:00
2018-12-11 15:02:39 +00:00
qt_feature_set_cache_value ( cache "${feature}" "${emit_if}" "${result}" "${arg_LABEL}" )
qt_feature_set_value ( "${feature}" "${cache}" "${emit_if}" "${condition}" "${arg_LABEL}" )
2018-10-24 13:20:27 +00:00
endfunction ( )
2018-12-11 15:02:39 +00:00
function ( qt_feature_definition feature name )
qt_parse_all_arguments ( arg "qt_feature_definition" "NEGATE" "VALUE" "" ${ ARGN } )
2018-10-24 13:20:27 +00:00
2019-03-14 10:27:38 +00:00
# Store all the define related info in a unique variable key.
set ( key_name "_QT_FEATURE_DEFINE_DEFINITION_${feature}_${name}" )
set ( ${ key_name } "FEATURE;${feature};NAME;${name};${ARGN}" PARENT_SCOPE )
# Store the key for later evaluation and subsequent define generation:
list ( APPEND __QtFeature_define_definitions "${key_name}" )
set ( __QtFeature_define_definitions ${ __QtFeature_define_definitions } PARENT_SCOPE )
endfunction ( )
function ( qt_evaluate_feature_definition key )
if ( NOT DEFINED ${ key } )
qt_debug_print_variables ( DEDUP MATCH "^_QT_FEATURE_DEFINE_DEFINITION" )
message ( FATAL_ERROR "Attempting to evaluate feature define ${key} but its definition is missing. " )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-14 10:27:38 +00:00
cmake_parse_arguments ( arg
" N E G A T E ; "
" F E A T U R E ; N A M E ; V A L U E ; " " " $ { $ { k e y } } )
set ( expected ON )
if ( arg_NEGATE )
set ( expected OFF )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-14 10:27:38 +00:00
set ( msg "" )
if ( QT_FEATURE_ ${ arg_FEATURE } STREQUAL expected )
if ( arg_VALUE )
string ( APPEND msg "#define ${arg_NAME} ${arg_VALUE}\n" )
else ( )
string ( APPEND msg "#define ${arg_NAME}\n" )
endif ( )
2018-12-11 15:02:39 +00:00
string ( APPEND __QtFeature_public_extra "${msg}" )
2018-10-24 13:20:27 +00:00
endif ( )
set ( __QtFeature_public_extra ${ __QtFeature_public_extra } PARENT_SCOPE )
endfunction ( )
2018-12-11 15:02:39 +00:00
function ( qt_extra_definition name value )
qt_parse_all_arguments ( arg "qt_extra_definition" "PUBLIC;PRIVATE" "" "" ${ ARGN } )
2018-10-24 13:20:27 +00:00
2018-12-11 15:02:39 +00:00
if ( arg_PUBLIC )
string ( APPEND __QtFeature_public_extra "\n#define ${name} ${value}\n" )
elseif ( arg_PRIVATE )
string ( APPEND __QtFeature_private_extra "\n#define ${name} ${value}\n" )
2018-10-24 13:20:27 +00:00
endif ( )
set ( __QtFeature_public_extra ${ __QtFeature_public_extra } PARENT_SCOPE )
set ( __QtFeature_private_extra ${ __QtFeature_private_extra } PARENT_SCOPE )
endfunction ( )
2018-12-11 15:02:39 +00:00
function ( qt_internal_generate_feature_line line feature )
if ( QT_FEATURE_ ${ feature } STREQUAL "ON" )
set ( line "#define QT_FEATURE_${feature} 1\n\n" PARENT_SCOPE )
elseif ( QT_FEATURE_ ${ feature } STREQUAL "OFF" )
set ( line "#define QT_FEATURE_${feature} -1\n\n" PARENT_SCOPE )
elseif ( QT_FEATURE_ ${ feature } STREQUAL "UNSET" )
set ( line "#define QT_FEATURE_${feature} 0\n\n" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
else ( )
2018-12-11 15:02:39 +00:00
message ( FATAL_ERROR "${feature} has unexpected value \" ${ QT_FEATURE_${feature } }\ "!" )
2018-10-24 13:20:27 +00:00
endif ( )
endfunction ( )
2018-12-11 15:02:39 +00:00
function ( qt_internal_feature_write_file file features extra )
message ( "Generating file ${file}." )
set ( contents "" )
foreach ( it ${ features } )
qt_internal_generate_feature_line ( line "${it}" )
string ( APPEND contents "${line}" )
2018-10-24 13:20:27 +00:00
endforeach ( )
2018-12-11 15:02:39 +00:00
string ( APPEND contents "${extra}" )
2018-10-24 13:20:27 +00:00
2018-12-11 15:02:39 +00:00
file ( GENERATE OUTPUT "${file}" CONTENT "${contents}" )
2018-10-24 13:20:27 +00:00
endfunction ( )
Implement developer / non-prefix builds
A non-prefix build is a build where you don't have to run
make install.
To do a non-prefix build, pass -DFEATURE_developer_build=ON when
invoking CMake on qtbase. Note that this of course also enables
developer build features (private tests, etc).
When doing a non-prefix build, the CMAKE_INSTALL_PREFIX cache variable
will point to the qtbase build directory.
Tests can be run without installing Qt (QPA plugins are picked up from
the build dir).
This patch stops installation of any files by forcing the
make "install" target be a no-op.
When invoking cmake on the qtsvg module (or any other module),
the CMAKE_INSTALL_PREFIX variable should be set to the qtbase build
directory.
The developer-build feature is propagated via the QtCore Config file,
so that when building other modules, you don't have to specify it
on the command line again.
As a result of the change, all libraries, plugins, tools, include dirs,
CMake Config files, CMake Targets files, Macro files, etc,
will be placed in the qtbase build directory, mimicking the file layout
of an installed Qt file layout.
Only examples and tests are kept in the separate module build
directories, which is equivalent to how qmake does it.
The following global variables contain paths for the
appropriate prefix or non prefix builds:
QT_BUILD_DIR, QT_INSTALL_DIR, QT_CONFIG_BUILD_DIR,
QT_CONFIG_INSTALL_DIR. These should be used by developers
when deciding where files should be placed.
All usages of install() are replaced by qt_install(), which has some
additional logic on how to handle associationg of CMake targets to
export names.
When installing files, some consideration should be taken if
qt_copy_or_install() needs to be used instead of qt_install(),
which takes care of copying files from the source dir to the build dir
when doing non-prefix builds.
Tested with qtbase and qtsvg, developer builds, non-developer builds
and static developer builds on Windows, Linux and macOS.
Task-number: QTBUG-75581
Change-Id: I0ed27fb6467662dd24fb23aee6b95dd2c9c4061f
Reviewed-by: Kevin Funk <kevin.funk@kdab.com>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-05-08 12:45:41 +00:00
function ( qt_feature_module_end )
set ( flags )
set ( options OUT_VAR_PREFIX )
set ( multiopts )
cmake_parse_arguments ( arg "${flags}" "${options}" "${multiopts}" ${ ARGN } )
set ( target ${ arg_UNPARSED_ARGUMENTS } )
# The value of OUT_VAR_PREFIX is used as a prefix for output variables that should be
# set in the parent scope.
if ( NOT arg_OUT_VAR_PREFIX )
set ( arg_OUT_VAR_PREFIX "" )
endif ( )
2019-03-20 16:36:25 +00:00
set ( all_features ${ __QtFeature_public_features } ${ __QtFeature_private_features } ${ __QtFeature_internal_features } )
2018-10-24 13:20:27 +00:00
list ( REMOVE_DUPLICATES all_features )
foreach ( feature ${ all_features } )
qt_evaluate_feature ( ${ feature } )
endforeach ( )
set ( enabled_public_features "" )
set ( disabled_public_features "" )
set ( enabled_private_features "" )
set ( disabled_private_features "" )
foreach ( feature ${ __QtFeature_public_features } )
if ( QT_FEATURE_ ${ feature } )
list ( APPEND enabled_public_features ${ feature } )
else ( )
list ( APPEND disabled_public_features ${ feature } )
endif ( )
endforeach ( )
foreach ( feature ${ __QtFeature_private_features } )
if ( QT_FEATURE_ ${ feature } )
list ( APPEND enabled_private_features ${ feature } )
else ( )
list ( APPEND disabled_private_features ${ feature } )
endif ( )
endforeach ( )
2019-03-14 10:27:38 +00:00
foreach ( key ${ __QtFeature_define_definitions } )
qt_evaluate_feature_definition ( ${ key } )
unset ( ${ key } PARENT_SCOPE )
endforeach ( )
2018-10-24 13:20:27 +00:00
foreach ( feature ${ all_features } )
2018-11-02 10:42:58 +00:00
unset ( _QT_FEATURE_DEFINITION_ ${ feature } PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endforeach ( )
2018-12-11 15:02:39 +00:00
qt_internal_feature_write_file ( "${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_private_file}"
2018-10-24 13:20:27 +00:00
" $ { _ _ Q t F e a t u r e _ p r i v a t e _ f e a t u r e s } " " $ { _ _ Q t F e a t u r e _ p r i v a t e _ e x t r a } "
)
2018-12-11 15:02:39 +00:00
qt_internal_feature_write_file ( "${CMAKE_CURRENT_BINARY_DIR}/${__QtFeature_public_file}"
2018-10-24 13:20:27 +00:00
" $ { _ _ Q t F e a t u r e _ p u b l i c _ f e a t u r e s } " " $ { _ _ Q t F e a t u r e _ p u b l i c _ e x t r a } "
)
Implement developer / non-prefix builds
A non-prefix build is a build where you don't have to run
make install.
To do a non-prefix build, pass -DFEATURE_developer_build=ON when
invoking CMake on qtbase. Note that this of course also enables
developer build features (private tests, etc).
When doing a non-prefix build, the CMAKE_INSTALL_PREFIX cache variable
will point to the qtbase build directory.
Tests can be run without installing Qt (QPA plugins are picked up from
the build dir).
This patch stops installation of any files by forcing the
make "install" target be a no-op.
When invoking cmake on the qtsvg module (or any other module),
the CMAKE_INSTALL_PREFIX variable should be set to the qtbase build
directory.
The developer-build feature is propagated via the QtCore Config file,
so that when building other modules, you don't have to specify it
on the command line again.
As a result of the change, all libraries, plugins, tools, include dirs,
CMake Config files, CMake Targets files, Macro files, etc,
will be placed in the qtbase build directory, mimicking the file layout
of an installed Qt file layout.
Only examples and tests are kept in the separate module build
directories, which is equivalent to how qmake does it.
The following global variables contain paths for the
appropriate prefix or non prefix builds:
QT_BUILD_DIR, QT_INSTALL_DIR, QT_CONFIG_BUILD_DIR,
QT_CONFIG_INSTALL_DIR. These should be used by developers
when deciding where files should be placed.
All usages of install() are replaced by qt_install(), which has some
additional logic on how to handle associationg of CMake targets to
export names.
When installing files, some consideration should be taken if
qt_copy_or_install() needs to be used instead of qt_install(),
which takes care of copying files from the source dir to the build dir
when doing non-prefix builds.
Tested with qtbase and qtsvg, developer builds, non-developer builds
and static developer builds on Windows, Linux and macOS.
Task-number: QTBUG-75581
Change-Id: I0ed27fb6467662dd24fb23aee6b95dd2c9c4061f
Reviewed-by: Kevin Funk <kevin.funk@kdab.com>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-05-08 12:45:41 +00:00
# Extra header injections which have to have forwarding headers created by
# qt_install_injections.
2019-05-16 07:46:29 +00:00
# Skip creating forwarding headers if qt_feature_module_begin was called with NO_MODULE, aka
# there is no include/<module_name> so there's no place to put the forwarding headers.
if ( __QtFeature_library )
set ( injections "" )
qt_compute_injection_forwarding_header ( "${__QtFeature_library}"
S O U R C E " $ { _ _ Q t F e a t u r e _ p u b l i c _ f i l e } "
O U T _ V A R i n j e c t i o n s )
qt_compute_injection_forwarding_header ( "${__QtFeature_library}"
S O U R C E " $ { _ _ Q t F e a t u r e _ p r i v a t e _ f i l e } " P R I V A T E
O U T _ V A R i n j e c t i o n s )
set ( ${ arg_OUT_VAR_PREFIX } extra_library_injections ${ injections } PARENT_SCOPE )
endif ( )
2018-10-24 13:20:27 +00:00
2019-02-12 11:00:49 +00:00
if ( NOT ( "${target}" STREQUAL "NO_MODULE" ) )
get_target_property ( targetType "${target}" TYPE )
if ( "${targetType}" STREQUAL "INTERFACE_LIBRARY" )
set ( propertyPrefix "INTERFACE_" )
else ( )
set ( propertyPrefix "" )
2019-06-05 08:08:44 +00:00
set_target_properties ( "${target}" PROPERTIES EXPORT_PROPERTIES "QT_ENABLED_PUBLIC_FEATURES;QT_DISABLED_PUBLIC_FEATURES;QT_ENABLED_PRIVATE_FEATURES;QT_DISABLED_PRIVATE_FEATURES;MODULE_PLUGIN_TYPES;QT_PLUGINS" )
2019-02-12 11:00:49 +00:00
endif ( )
foreach ( visibility public private )
string ( TOUPPER "${visibility}" capitalVisibility )
foreach ( state enabled disabled )
string ( TOUPPER "${state}" capitalState )
2018-10-24 13:20:27 +00:00
2019-02-12 11:00:49 +00:00
set_property ( TARGET "${target}" PROPERTY ${ propertyPrefix } QT_ ${ capitalState } _ ${ capitalVisibility } _FEATURES "${${state}_${visibility}_features}" )
endforeach ( )
2018-10-24 13:20:27 +00:00
endforeach ( )
2019-05-16 11:22:44 +00:00
qt_feature_copy_global_config_features_to_core ( ${ target } )
2019-02-12 11:00:49 +00:00
endif ( )
2018-10-24 13:20:27 +00:00
unset ( __QtFeature_library PARENT_SCOPE )
unset ( __QtFeature_public_features PARENT_SCOPE )
2019-03-20 16:36:25 +00:00
unset ( __QtFeature_private_features PARENT_SCOPE )
unset ( __QtFeature_internal_features PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
unset ( __QtFeature_private_file PARENT_SCOPE )
unset ( __QtFeature_public_file PARENT_SCOPE )
unset ( __QtFeature_private_extra PARENT_SCOPE )
unset ( __QtFeature_public_extra PARENT_SCOPE )
2019-03-14 10:27:38 +00:00
unset ( __QtFeature_define_definitions PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2019-05-16 11:22:44 +00:00
function ( qt_feature_copy_global_config_features_to_core target )
# CMake doesn't support setting custom properties on exported INTERFACE libraries
# See https://gitlab.kitware.com/cmake/cmake/issues/19261.
# To circumvent that, copy the properties from GlobalConfig to Core target.
# This way the global features actually get set in the generated CoreTargets.cmake file.
if ( target STREQUAL Core )
foreach ( visibility public private )
string ( TOUPPER "${visibility}" capitalVisibility )
foreach ( state enabled disabled )
string ( TOUPPER "${state}" capitalState )
set ( core_property_name "QT_${capitalState}_${capitalVisibility}_FEATURES" )
set ( global_property_name "INTERFACE_${core_property_name}" )
get_property ( core_values TARGET Core PROPERTY ${ core_property_name } )
get_property ( global_values TARGET GlobalConfig PROPERTY ${ global_property_name } )
set ( total_values ${ core_values } ${ global_values } )
set_property ( TARGET Core PROPERTY ${ core_property_name } ${ total_values } )
endforeach ( )
endforeach ( )
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
function ( qt_config_compile_test name )
2019-09-21 14:22:36 +00:00
cmake_parse_arguments ( arg "" "LABEL;PROJECT_PATH" "LIBRARIES;CODE" ${ ARGN } )
if ( arg_PROJECT_PATH )
2019-09-24 08:49:13 +00:00
message ( STATUS "Performing Test ${arg_LABEL}" )
2019-09-21 14:22:36 +00:00
try_compile ( HAVE_ ${ name } "${CMAKE_BINARY_DIR}/config.tests/${name}" "${arg_PROJECT_PATH}"
" $ { n a m e } " )
2019-09-24 08:49:13 +00:00
if ( ${ HAVE_${name } } )
set ( status_label "Success" )
else ( )
set ( status_label "Failed" )
endif ( )
message ( STATUS "Performing Test ${arg_LABEL} - ${status_label}" )
2019-09-21 14:22:36 +00:00
else ( )
foreach ( library IN ITEMS ${ arg_LIBRARIES } )
if ( NOT TARGET "${library}" )
# If the dependency looks like a cmake target, then make this compile test
# fail instead of cmake abort later via CMAKE_REQUIRED_LIBRARIES.
string ( FIND "${library}" "::" cmake_target_namespace_separator )
if ( NOT cmake_target_namespace_separator EQUAL -1 )
set ( HAVE_ ${ name } FALSE )
break ( )
endif ( )
2019-02-11 12:13:43 +00:00
endif ( )
2019-09-21 14:22:36 +00:00
endforeach ( )
2019-02-11 12:13:43 +00:00
2019-09-21 14:22:36 +00:00
if ( NOT DEFINED HAVE_ ${ name } )
set ( _save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" )
set ( CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}" )
check_cxx_source_compiles ( "${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_ ${ name } )
set ( CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}" )
endif ( )
2019-02-11 12:13:43 +00:00
endif ( )
2019-09-21 14:22:36 +00:00
2018-12-11 15:02:39 +00:00
set ( TEST_ ${ name } "${HAVE_${name}}" CACHE INTERNAL "${arg_LABEL}" )
2018-10-24 13:20:27 +00:00
endfunction ( )
function ( qt_config_compile_test_x86simd extension label )
2019-02-10 23:20:34 +00:00
if ( DEFINED TEST_X86SIMD_ ${ extension } )
return ( )
endif ( )
2019-09-24 08:49:13 +00:00
message ( STATUS "Performing SIMD Test ${label}" )
2019-03-12 20:55:58 +00:00
try_compile ( "TEST_X86SIMD_${extension}"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / c o n f i g . t e s t s / x 8 6 _ s i m d _ $ { e x t e n s i o n } "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c o n f i g . t e s t s / x 8 6 _ s i m d "
x 8 6 _ s i m d
C M A K E _ F L A G S " - D S I M D : s t r i n g = $ { e x t e n s i o n } " )
2019-09-19 17:12:57 +00:00
if ( ${ TEST_X86SIMD_${extension } } )
set ( status_label "Success" )
else ( )
set ( status_label "Failed" )
endif ( )
message ( STATUS "Performing SIMD Test ${label} - ${status_label}" )
2019-03-12 20:55:58 +00:00
set ( TEST_subarch_ ${ extension } "${TEST_X86SIMD_${extension}}" CACHE INTERNAL "${label}" )
2018-10-24 13:20:27 +00:00
endfunction ( )
2019-01-14 10:35:53 +00:00
function ( qt_make_features_available target )
2019-05-03 14:03:15 +00:00
if ( NOT "${target}" MATCHES "^${QT_CMAKE_EXPORT_NAMESPACE}::[a-zA-z][a-zA-Z0-9_-]*$" )
message ( FATAL_ERROR "${target} does not match ${QT_CMAKE_EXPORT_NAMESPACE}::[a-zA-z][a-zA-Z0-9_-]*. INVALID NAME." )
2019-01-14 10:35:53 +00:00
endif ( )
if ( NOT TARGET ${ target } )
message ( FATAL_ERROR "${target} not found." )
endif ( )
2019-01-10 09:50:38 +00:00
2019-01-14 10:35:53 +00:00
get_target_property ( target_type "${target}" TYPE )
if ( "${target_type}" STREQUAL "INTERFACE_LIBRARY" )
set ( property_prefix "INTERFACE_" )
else ( )
set ( property_prefix "" )
endif ( )
foreach ( visibility IN ITEMS PUBLIC PRIVATE )
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" )
2019-01-14 10:01:06 +00:00
continue ( )
endif ( )
2019-01-14 10:35:53 +00:00
foreach ( feature IN ITEMS ${ features } )
2019-02-11 09:55:07 +00:00
if ( DEFINED "QT_FEATURE_${feature}" AND NOT "${QT_FEATURE_${feature}}" STREQUAL "${value}" )
message ( FATAL_ERROR "Feature ${feature} is already defined and has a different value when importing features from ${target}." )
2018-10-24 13:20:27 +00:00
endif ( )
2019-02-10 21:34:42 +00:00
set ( QT_FEATURE_ ${ feature } "${value}" CACHE INTERNAL "Qt feature: ${feature} (from target ${target})" )
2018-10-24 13:20:27 +00:00
endforeach ( )
2019-01-14 10:35:53 +00:00
set ( value OFF )
2018-10-24 13:20:27 +00:00
endforeach ( )
endforeach ( )
endfunction ( )
2019-05-03 14:03:15 +00:00