2018-10-24 13:20:27 +00:00
include ( CMakePackageConfigHelpers )
# Install locations:
set ( INSTALL_BINDIR "bin" CACHE PATH "Executables [PREFIX/bin]" )
set ( INSTALL_INCLUDEDIR "include" CACHE PATH "Header files [PREFIX/include]" )
set ( INSTALL_LIBDIR "lib" CACHE PATH "Libraries [PREFIX/lib]" )
set ( INSTALL_ARCHDATADIR "." CACHE PATH "Arch-dependent data [PREFIX]" )
set ( INSTALL_PLUGINSDIR "${INSTALL_ARCHDATADIR}/plugins" CACHE PATH
" P l u g i n s [ A R C H D A T A D I R / p l u g i n s ] " )
set ( INSTALL_TARGETS_DEFAULT_ARGS
R U N T I M E D E S T I N A T I O N " $ { I N S T A L L _ B I N D I R } "
L I B R A R Y D E S T I N A T I O N " $ { I N S T A L L _ L I B D I R } "
A R C H I V E D E S T I N A T I O N " $ { I N S T A L L _ L I B D I R } " C O M P O N E N T D e v e l
I N C L U D E S D E S T I N A T I O N " $ { I N S T A L L _ I N C L U D E D I R } "
)
if ( WIN32 )
set ( _default_libexec "${INSTALL_ARCHDATADIR}/bin" )
else ( )
set ( _default_libexec "${INSTALL_ARCHDATADIR}/libexec" )
endif ( )
set ( INSTALL_LIBEXECDIR "${_default_libexec}" CACHE PATH
" H e l p e r p r o g r a m s [ A R C H D A T A D I R / b i n o n W i n d o w s , A R C H D A T A D I R / l i b e x e c o t h e r w i s e ] " )
set ( INSTALL_IMPORTDIR "${INSTALL_ARCHDATADIR}/imports" CACHE PATH
" Q M L 1 i m p o r t s [ A R C H D A T A D I R / i m p o r t s ] " )
set ( INSTALL_QMLDIR "${INSTALL_ARCHDATADIR}/qml" CACHE PATH
" Q M L 2 i m p o r t s [ A R C H D A T A D I R / q m l ] " )
set ( INSTALL_DATADIR "." CACHE PATH "Arch-independent data [PREFIX]" )
set ( INSTALL_DOCDIR "${INSTALL_DATADIR}/doc" CACHE PATH "Documentation [DATADIR/doc]" )
set ( INSTALL_TRANSLATIONSDIR "${INSTALL_DATADIR}/translations" CACHE PATH
" T r a n s l a t i o n s [ D A T A D I R / t r a n s l a t i o n s ] " )
set ( INSTALL_SYSCONFDIR "etc/xdg" CACHE PATH
" S e t t i n g s u s e d b y Q t p r o g r a m s [ P R E F I X / e t c / x d g ] " )
set ( INSTALL_EXAMPLESDIR "examples" CACHE PATH "Examples [PREFIX/examples]" )
set ( INSTALL_TESTSDIR "tests" CACHE PATH "Tests [PREFIX/tests]" )
2019-02-11 10:34:35 +00:00
set ( INSTALL_CMAKE_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" CACHE STRING "CMake namespace [Qt${PROJECT_VERSION_MAJOR}]" )
2019-02-12 09:02:15 +00:00
set ( QT_CMAKE_EXPORT_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" CACHE STRING "CMake namespace used when exporting targets [Qt${PROJECT_VERSION_MAJOR}]" )
2019-02-13 08:45:18 +00:00
set ( QT_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" )
2019-02-12 09:02:15 +00:00
2019-02-11 14:45:56 +00:00
# the default RPATH to be used when installing, but only if it's not a system directory
LIST ( FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir )
IF ( "${isSystemDir}" STREQUAL "-1" )
SET ( _default_install_rpath "${CMAKE_INSTALL_PREFIX}/lib" )
ENDIF ( "${isSystemDir}" STREQUAL "-1" )
# Default rpath settings: Use rpath for build tree as well as a full path for the installed binaries.
# For origin builds, one needs to override CMAKE_INSTALL_RPATH for example with $ORIGIN/../lib
SET ( CMAKE_INSTALL_RPATH "${_default_install_rpath}" CACHE PATH "RPATH for installed binaries" )
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET ( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
2018-10-24 13:20:27 +00:00
# Platform define path, etc.
if ( WIN32 )
set ( QT_DEFAULT_PLATFORM_DEFINITIONS UNICODE _UNICODE WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE )
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
list ( APPEND QT_DEFAULT_PLATFORM_DEFINITIONS WIN64 _WIN64 )
endif ( )
if ( MSVC )
set ( QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/win32-msvc )
elseif ( CLANG )
set ( QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/win32-clang )
endif ( )
elseif ( LINUX )
if ( GCC )
set ( QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/linux-g++ )
elseif ( CLANG )
set ( QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/linux-clang )
endif ( )
elseif ( APPLE )
set ( QT_DEFAULT_PLATFORM_DEFINITION_DIR mkspecs/macx-clang )
endif ( )
if ( NOT DEFINED QT_DEFAULT_PLATFORM_DEFINITIONS )
set ( QT_DEFAULT_PLATFORM_DEFINITIONS "" )
endif ( )
set ( QT_PLATFORM_DEFINITIONS ${ QT_DEFAULT_PLATFORM_DEFINITIONS }
C A C H E S T R I N G " Q t p l a t f o r m s p e c i f i c p r e - p r o c e s s o r d e f i n e s " )
set ( QT_PLATFORM_DEFINITION_DIR ${ QT_DEFAULT_PLATFORM_DEFINITION_DIR }
C A C H E P A T H " P a t h t o d i r e c t o r y t h a t c o n t a i n s q p l a t f o r m d e f s . h " )
set ( QT_NAMESPACE "" CACHE STRING "Qt Namespace" )
2019-01-30 15:31:06 +00:00
if ( QT_NAMESPACE STREQUAL "" )
set ( QT_HAS_NAMESPACE OFF )
else ( )
set ( QT_HAS_NAMESPACE ON )
endif ( )
2018-10-24 13:20:27 +00:00
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
macro ( qt_internal_set_qt_known_modules )
set ( QT_KNOWN_MODULES ${ ARGN } CACHE INTERNAL "Known Qt modules" FORCE )
2018-11-08 21:29:54 +00:00
endmacro ( )
2018-10-24 13:20:27 +00:00
2018-11-08 21:29:54 +00:00
# Reset:
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
qt_internal_set_qt_known_modules ( "" )
set ( QT_KNOWN_MODULES_WITH_TOOLS "" CACHE INTERNAL "Known Qt modules with tools" FORCE )
macro ( qt_internal_append_known_modules_with_tools module )
if ( NOT ${ module } IN_LIST QT_KNOWN_MODULES_WITH_TOOLS )
set ( QT_KNOWN_MODULES_WITH_TOOLS "${QT_KNOWN_MODULES_WITH_TOOLS};${module}"
C A C H E I N T E R N A L " K n o w n Q t m o d u l e s w i t h t o o l s " F O R C E )
endif ( )
endmacro ( )
macro ( qt_internal_append_known_module_tool module tool )
if ( NOT ${ tool } IN_LIST QT_KNOWN_MODULE_ ${ module } _TOOLS )
list ( APPEND QT_KNOWN_MODULE_ ${ module } _TOOLS "${tool}" )
set ( QT_KNOWN_MODULE_ ${ module } _TOOLS "${QT_KNOWN_MODULE_${module}_TOOLS}"
C A C H E I N T E R N A L " K n o w n Q t m o d u l e $ { m o d u l e } t o o l s " F O R C E )
endif ( )
endmacro ( )
# Reset syncqt cache variable, to make sure it gets recomputed on reconfiguration, otherwise
# it might not get installed.
unset ( QT_SYNCQT CACHE )
2018-10-24 13:20:27 +00:00
# For adjusting variables when running tests, we need to know what
# the correct variable is for separating entries in PATH-alike
# variables.
if ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" )
set ( QT_PATH_SEPARATOR "\\;" )
else ( )
set ( QT_PATH_SEPARATOR ":" )
endif ( )
# Functions and macros:
2019-05-03 10:30:09 +00:00
function ( qt_internal_export_modern_cmake_config_targets_file )
cmake_parse_arguments ( __arg "" "EXPORT_NAME_PREFIX;CONFIG_INSTALL_DIR" "TARGETS" ${ ARGN } )
foreach ( target ${ __arg_TARGETS } )
if ( TARGET "${target}Versionless" )
continue ( )
endif ( )
add_library ( "${target}Versionless" INTERFACE )
target_link_libraries ( "${target}Versionless" INTERFACE "${target}" )
set_target_properties ( "${target}Versionless" PROPERTIES EXPORT_NAME "${target}" )
install ( TARGETS "${target}Versionless" EXPORT "${__arg_EXPORT_NAME_PREFIX}VersionlessTargets" )
endforeach ( )
install ( EXPORT "${__arg_EXPORT_NAME_PREFIX}VersionlessTargets" NAMESPACE Qt:: DESTINATION "${__arg_CONFIG_INSTALL_DIR}" )
endfunction ( )
2018-10-24 13:20:27 +00:00
# Print all variables defined in the current scope.
macro ( qt_debug_print_variables )
cmake_parse_arguments ( __arg "DEDUP" "" "MATCH;IGNORE" ${ ARGN } )
message ( "Known Variables:" )
get_cmake_property ( __variableNames VARIABLES )
list ( SORT __variableNames )
if ( __arg_DEDUP )
list ( REMOVE_DUPLICATES __variableNames )
endif ( )
foreach ( __var ${ __variableNames } )
set ( __ignore OFF )
foreach ( __i ${ __arg_IGNORE } )
if ( __var MATCHES "${__i}" )
set ( __ignore ON )
break ( )
endif ( )
endforeach ( )
if ( __ignore )
continue ( )
endif ( )
set ( __show OFF )
foreach ( __i ${ __arg_MATCH } )
if ( __var MATCHES "${__i}" )
set ( __show ON )
break ( )
endif ( )
endforeach ( )
if ( __show )
message ( " ${__var}=${${__var}}." )
endif ( )
endforeach ( )
endmacro ( )
macro ( assert )
if ( ${ ARGN } )
else ( )
message ( FATAL_ERROR "ASSERT: ${ARGN}." )
endif ( )
endmacro ( )
2019-05-03 13:21:30 +00:00
function ( qt_create_nolink_target target export_target )
2019-03-28 14:25:17 +00:00
if ( NOT TARGET "${target}" )
message ( FATAL_ERROR "${target} does not exist when trying to build a nolink target." )
endif ( )
get_target_property ( type "${target}" TYPE )
if ( type STREQUAL EXECUTABLE )
message ( FATAL_ERROR "${target} must be a library of some kind." )
endif ( )
if ( type STREQUAL OBJECT_LIBRARY )
message ( FATAL_ERROR "${target} must not be an object library." )
endif ( )
2019-05-03 13:21:30 +00:00
# Strip off the namespace prefix, so from Vulkan::Vulkan to Vulkan, and then append _nolink.
string ( REGEX REPLACE "^.*::" "" non_prefixed_target ${ target } )
set ( nolink_target "${non_prefixed_target}_nolink" )
# Create the nolink interface target, assign the properties from the original target,
# associate the nolink target with the same export which contains
# the target that uses the _nolink target.
# Also create a namespaced alias of the form {$target}::${target}_nolink which is used by
# our modules.
2019-03-28 14:25:17 +00:00
if ( NOT TARGET "${nolink_target}" )
2019-05-03 13:21:30 +00:00
add_library ( "${nolink_target}" INTERFACE )
set ( prefixed_nolink_target "${target}_nolink" )
2019-04-10 10:12:09 +00:00
set_target_properties ( "${nolink_target}" PROPERTIES
I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S >
I N T E R F A C E _ S Y S T E M _ I N C L U D E _ D I R E C T O R I E S
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N T E R F A C E _ S Y S T E M _ I N C L U D E _ D I R E C T O R I E S >
I N T E R F A C E _ C O M P I L E _ D E F I N I T I O N S
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N T E R F A C E _ C O M P I L E _ D E F I N I T I O N S >
I N T E R F A C E _ C O M P I L E _ O P T I O N S
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N T E R F A C E _ C O M P I L E _ O P T I O N S >
I N T E R F A C E _ C O M P I L E _ F E A T U R E S
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N T E R F A C E _ C O M P I L E _ F E A T U R E S > )
2019-05-03 13:21:30 +00:00
install ( TARGETS ${ nolink_target } EXPORT ${ export_target } )
add_library ( ${ prefixed_nolink_target } ALIAS ${ nolink_target } )
2019-03-28 14:25:17 +00:00
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
function ( qt_ensure_perl )
if ( DEFINED HOST_PERL )
return ( )
endif ( )
find_program ( HOST_PERL "perl" DOC "Perl binary" )
if ( NOT HOST_PERL )
message ( FATAL_ERROR "Perl needs to be available to build Qt." )
endif ( )
endfunction ( )
2018-12-07 13:04:42 +00:00
function ( qt_ensure_sync_qt )
qt_ensure_perl ( )
2019-02-12 21:39:35 +00:00
if ( DEFINED QT_SYNCQT )
return ( )
2018-12-07 13:04:42 +00:00
endif ( )
2019-02-12 21:39:35 +00:00
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
# When building qtbase, use the source syncqt, otherwise use the installed one.
if ( EXISTS "${PROJECT_SOURCE_DIR}/bin/syncqt.pl" )
set ( QT_SYNCQT "${PROJECT_SOURCE_DIR}/bin/syncqt.pl" CACHE FILEPATH "syncqt script" )
message ( STATUS "Using source syncqt found at: ${QT_SYNCQT}" )
install ( PROGRAMS "${PROJECT_SOURCE_DIR}/bin/syncqt.pl" DESTINATION "${INSTALL_LIBEXECDIR}" )
else ( )
get_filename_component ( syncqt_absolute_path
" $ { C M A K E _ I N S T A L L _ P R E F I X } / $ { I N S T A L L _ L I B E X E C D I R } / s y n c q t . p l "
A B S O L U T E )
set ( QT_SYNCQT "${syncqt_absolute_path}" CACHE FILEPATH "syncqt script" )
message ( STATUS "Using installed syncqt found at: ${QT_SYNCQT}" )
endif ( )
2018-12-07 13:04:42 +00:00
endfunction ( )
2018-10-24 13:20:27 +00:00
# A version of cmake_parse_arguments that makes sure all arguments are processed and errors out
# with a message about ${type} having received unknown arguments.
macro ( qt_parse_all_arguments result type flags options multiopts )
cmake_parse_arguments ( ${ result } "${flags}" "${options}" "${multiopts}" ${ ARGN } )
if ( DEFINED ${ result } _UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "Unknown arguments were passed to ${type} (${${result}_UNPARSED_ARGUMENTS})." )
endif ( )
endmacro ( )
2019-02-27 12:49:04 +00:00
function ( qt_internal_add_link_flags_no_undefined target )
if ( GCC OR CLANG )
if ( APPLE )
set ( no_undefined_flag "-Wl,-undefined,error" )
elseif ( LINUX )
set ( no_undefined_flag "-Wl,--no-undefined" )
else ( )
message ( FATAL_ERROR "Platform linker doesn't support erroring upon encountering undefined symbols. Target:\" ${ target } \".")
endif ( )
2019-03-04 12:05:54 +00:00
target_link_options ( "${target}" PRIVATE "${no_undefined_flag}" )
endif ( )
endfunction ( )
function ( qt_internal_add_link_flags_gc_sections target visibility )
set ( possible_visibilities PRIVATE INTERFACE PUBLIC )
list ( FIND possible_visibilities "${visibility}" known_visibility )
if ( known_visibility EQUAL "-1" )
message ( FATAL_ERROR "Visibitily setting must be one of PRIVATE, INTERFACE or PUBLIC." )
endif ( )
if ( GCC OR CLANG )
if ( APPLE )
set ( gc_sections_flag "-Wl,-dead_strip" )
elseif ( LINUX OR BSD OR SOLARIS OR WIN32 )
set ( gc_sections_flag "-Wl,--gc-sections" )
else ( )
message ( FATAL_ERROR "Platform linker doesn't support gc sections. Target:\" ${ target } \".")
endif ( )
target_link_options ( "${target}" ${ visibility } "${gc_sections_flag}" )
2019-02-27 12:49:04 +00:00
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
function ( qt_internal_add_linker_version_script target )
2018-12-07 12:13:24 +00:00
qt_parse_all_arguments ( arg "qt_internal_add_linker" "INTERNAL" "" "PRIVATE_HEADERS" ${ ARGN } )
2018-10-24 13:20:27 +00:00
if ( TEST_ld_version_script )
2018-12-07 12:13:24 +00:00
if ( arg_INTERNAL )
2018-10-24 13:20:27 +00:00
set ( contents "Qt_${PROJECT_VERSION_MAJOR}_PRIVATE_API { *; };" )
else ( )
set ( contents "Qt_${PROJECT_VERSION_MAJOR}_PRIVATE_API {\n qt_private_api_tag*;\n" )
2018-12-07 12:13:24 +00:00
foreach ( ph ${ arg_PRIVATE_HEADERS } )
2018-10-24 13:20:27 +00:00
string ( APPEND contents " @FILE:${ph}@\n" )
endforeach ( )
string ( APPEND contents "};\n" )
set ( current "Qt_${PROJECT_VERSION_MAJOR}" )
if ( QT_NAMESPACE STREQUAL "" )
set ( tag_symbol "qt_version_tag" )
else ( )
set ( tag_symbol "qt_version_tag_${QT_NAMESPACE}" )
endif ( )
string ( APPEND contents "${current} { *; };\n" )
foreach ( minor_version RANGE ${ PROJECT_VERSION_MINOR } )
set ( previous "${current}" )
set ( current "Qt_${PROJECT_VERSION_MAJOR}.${minor_version}" )
if ( minor_version EQUAL ${ PROJECT_VERSION_MINOR } )
string ( APPEND contents "${current} { ${tag_symbol}; } ${previous};\n" )
else ( )
string ( APPEND contents "${current} {} ${previous};\n" )
endif ( )
endforeach ( )
set ( infile "${CMAKE_CURRENT_BINARY_DIR}/${target}.version.in" )
set ( outfile "${CMAKE_CURRENT_BINARY_DIR}/${target}.version" )
file ( GENERATE OUTPUT "${infile}" CONTENT "${contents}" )
qt_ensure_perl ( )
add_custom_command ( TARGET "${target}" PRE_LINK
C O M M A N D " $ { H O S T _ P E R L } " " $ { P R O J E C T _ S O U R C E _ D I R } / m k s p e c s / f e a t u r e s / d a t a / u n i x / f i n d c l a s s l i s t . p l " < " $ { i n f i l e } " > " $ { o u t f i l e } "
B Y P R O D U C T S " $ { o u t f i l e } " D E P E N D S " $ { i n f i l e } "
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
C O M M E N T " G e n e r a t i n g v e r s i o n l i n k e r s c r i p t "
)
2019-03-04 12:05:54 +00:00
target_link_options ( "${target}" PRIVATE "-Wl,--version-script,${outfile}" )
2018-10-24 13:20:27 +00:00
endif ( )
endif ( )
endfunction ( )
2018-12-07 12:30:51 +00:00
# Get a set of Qt module related values based on the target name.
# When doing qt_internal_module_info(foo Core) this method will set
# the following variables in the caller's scope:
# * foo with the value "QtCore"
# * foo_versioned with the value "Qt5Core" (based on major Qt version)
# * foo_upper with the value "CORE"
# * foo_lower with the value "core"
2018-12-07 13:04:42 +00:00
# * foo_include_dir with the module's include directory in the binary tree
2018-12-07 12:30:51 +00:00
function ( qt_internal_module_info result target )
2018-12-07 13:04:42 +00:00
set ( module "Qt${target}" )
set ( "${result}" "${module}" PARENT_SCOPE )
2018-12-07 12:30:51 +00:00
set ( "${result}_versioned" "Qt${PROJECT_VERSION_MAJOR}${target}" PARENT_SCOPE )
string ( TOUPPER "${target}" upper )
string ( TOLOWER "${target}" lower )
set ( "${result}_upper" "${upper}" PARENT_SCOPE )
set ( "${result}_lower" "${lower}" PARENT_SCOPE )
2018-12-07 13:04:42 +00:00
set ( "${result}_include_dir" "${PROJECT_BINARY_DIR}/include/${module}" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2019-03-06 12:51:38 +00:00
set ( __default_private_args "SOURCES;LIBRARIES;INCLUDE_DIRECTORIES;DEFINES;DBUS_ADAPTOR_BASENAME;DBUS_ADAPTOR_FLAGS;DBUS_ADAPTOR_SOURCES;DBUS_INTERFACE_BASENAME;DBUS_INTERFACE_FLAGS;DBUS_INTERFACE_SOURCES;FEATURE_DEPENDENCIES;COMPILE_OPTIONS;LINK_OPTIONS;MOC_OPTIONS;DISABLE_AUTOGEN_TOOLS" )
2019-01-29 11:07:24 +00:00
set ( __default_public_args "PUBLIC_LIBRARIES;PUBLIC_INCLUDE_DIRECTORIES;PUBLIC_DEFINES;PUBLIC_COMPILE_OPTIONS;PUBLIC_LINK_OPTIONS" )
2018-10-24 13:20:27 +00:00
2019-01-30 15:36:30 +00:00
option ( QT_CMAKE_DEBUG_EXTEND_TARGET "Debug extend_target calls in Qt's build system" OFF )
2019-03-06 12:51:38 +00:00
# This function checks which autotools should be used: AUTOMOC/UIC/RCC
function ( qt_autogen_tools target )
qt_parse_all_arguments ( arg "qt_autogen_tools" "" "" "${__default_private_args}" ${ ARGN } )
set_property ( TARGET "${target}" PROPERTY INTERFACE_QT_MAJOR_VERSION ${ PROJECT_VERSION_MAJOR } )
set_property ( TARGET "${target}" APPEND PROPERTY
C O M P A T I B L E _ I N T E R F A C E _ S T R I N G Q T _ M A J O R _ V E R S I O N
)
list ( APPEND autogen_tools "moc" "uic" "rcc" )
if ( arg_DISABLE_AUTOGEN_TOOLS )
foreach ( disable_tool ${ arg_DISABLE_AUTOGEN_TOOLS } )
list ( REMOVE_ITEM autogen_tools "${disable_tool}" )
endforeach ( )
endif ( )
foreach ( autogen_tool ${ autogen_tools } )
string ( TOUPPER "${autogen_tool}" captitalAutogenTool )
set_target_properties ( "${target}"
P R O P E R T I E S
A U T O $ { c a p t i t a l A u t o g e n T o o l } O N
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
A U T O $ { c a p t i t a l A u t o g e n T o o l } _ E X E C U T A B L E
" $ < T A R G E T _ F I L E : $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : $ { a u t o g e n _ t o o l } > " )
set_property ( TARGET ${ target } APPEND PROPERTY
A U T O G E N _ T A R G E T _ D E P E N D S
$ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : $ { a u t o g e n _ t o o l } )
2019-03-06 12:51:38 +00:00
endforeach ( )
set_directory_properties ( PROPERTIES
Q T _ V E R S I O N _ M A J O R $ { P R O J E C T _ V E R S I O N _ M A J O R }
Q T _ V E R S I O N _ M I N O R $ { P R O J E C T _ V E R S I O N _ M I N O R } )
endfunction ( )
2018-10-24 13:20:27 +00:00
# This function can be used to add sources/libraries/etc. to the specified CMake target
# if the provided CONDITION evaluates to true.
function ( extend_target target )
if ( NOT TARGET "${target}" )
message ( FATAL_ERROR "Trying to extend non-existing target \" ${ target } \".")
endif ( )
2018-12-07 12:13:24 +00:00
qt_parse_all_arguments ( arg "extend_target" "" ""
2018-10-24 13:20:27 +00:00
" C O N D I T I O N ; $ { _ _ d e f a u l t _ p u b l i c _ a r g s } ; $ { _ _ d e f a u l t _ p r i v a t e _ a r g s } ; C O M P I L E _ F L A G S " $ { A R G N } )
2018-12-07 12:13:24 +00:00
if ( "x${arg_CONDITION}" STREQUAL x )
set ( arg_CONDITION ON )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-07 12:13:24 +00:00
qt_evaluate_config_expression ( result ${ arg_CONDITION } )
2018-10-24 13:20:27 +00:00
if ( ${ result } )
2019-01-30 15:36:30 +00:00
if ( QT_CMAKE_DEBUG_EXTEND_TARGET )
message ( "extend_target(${target} CONDITION ${arg_CONDITION} ...): Evaluated" )
endif ( )
2018-10-29 15:53:51 +00:00
set ( dbus_sources "" )
2018-12-07 12:13:24 +00:00
foreach ( adaptor ${ arg_DBUS_ADAPTOR_SOURCES } )
2019-01-30 13:06:48 +00:00
qt_create_qdbusxml2cpp_command ( "${target}" "${adaptor}" ADAPTOR BASENAME "${arg_DBUS_ADAPTOR_BASENAME}" FLAGS "${arg_DBUS_ADAPTOR_FLAGS}" )
2018-10-29 15:53:51 +00:00
list ( APPEND dbus_sources "${sources}" )
endforeach ( )
2018-12-11 10:38:20 +00:00
2018-12-07 12:13:24 +00:00
foreach ( interface ${ arg_DBUS_INTERFACE_SOURCES } )
2019-01-30 13:06:48 +00:00
qt_create_qdbusxml2cpp_command ( "${target}" "${interface}" INTERFACE BASENAME "${arg_DBUS_INTERFACE_BASENAME}" FLAGS "${arg_DBUS_INTERFACE_FLAGS}" )
2018-10-29 15:53:51 +00:00
list ( APPEND dbus_sources "${sources}" )
endforeach ( )
2018-10-24 13:20:27 +00:00
2019-03-28 14:25:17 +00:00
foreach ( lib ${ arg_PUBLIC_LIBRARIES } ${ arg_LIBRARIES } )
string ( REGEX REPLACE "_nolink$" "" base_lib "${lib}" )
if ( NOT base_lib STREQUAL lib )
2019-05-03 13:21:30 +00:00
set ( export_target "${INSTALL_CMAKE_NAMESPACE}${target}Targets" )
qt_create_nolink_target ( "${base_lib}" ${ export_target } )
2019-03-28 14:25:17 +00:00
endif ( )
endforeach ( )
2019-05-03 09:38:41 +00:00
# Find dependencies to internal libraries
get_target_property ( target_deps "${target}" _qt_target_deps )
if ( NOT target_deps )
set ( target_deps "" )
endif ( )
foreach ( lib ${ arg_LIBRARIES } )
if ( TARGET "${lib}" )
get_target_property ( _is_exported "${lib}" INTERFACE_QT_EXPORTED_LIBRARY )
if ( "${_is_exported}" )
list ( APPEND target_deps "${lib}\;${PROJECT_VERSION}" )
endif ( )
endif ( )
endforeach ( )
# Set-up the target
2018-12-07 12:13:24 +00:00
target_sources ( "${target}" PRIVATE ${ arg_SOURCES } ${ dbus_sources } )
if ( arg_COMPILE_FLAGS )
set_source_files_properties ( ${ arg_SOURCES } PROPERTIES COMPILE_FLAGS "${arg_COMPILE_FLAGS}" )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-07 12:13:24 +00:00
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_link_libraries ( "${target}" PUBLIC ${ arg_PUBLIC_LIBRARIES } PRIVATE ${ arg_LIBRARIES } )
2019-01-29 11:07:24 +00:00
target_compile_options ( "${target}" PUBLIC ${ arg_PUBLIC_COMPILE_OPTIONS } PRIVATE ${ arg_COMPILE_OPTIONS } )
target_link_options ( "${target}" PUBLIC ${ arg_PUBLIC_LINK_OPTIONS } PRIVATE ${ arg_LINK_OPTIONS } )
2019-05-03 09:38:41 +00:00
set_target_properties ( "${target}" PROPERTIES
A U T O M O C _ M O C _ O P T I O N S " $ { a r g _ M O C _ O P T I O N S } "
_ q t _ t a r g e t _ d e p s " $ { t a r g e t _ d e p s } "
)
2019-01-30 15:36:30 +00:00
else ( )
if ( QT_CMAKE_DEBUG_EXTEND_TARGET )
message ( "extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped" )
endif ( )
2018-11-08 21:29:55 +00:00
endif ( )
2018-10-24 13:20:27 +00:00
endfunction ( )
function ( qt_internal_library_deprecation_level result )
if ( WIN32 )
# On Windows, due to the way DLLs work, we need to export all functions,
# including the inlines
set ( "${result}" "QT_DISABLE_DEPRECATED_BEFORE=0x040800" PARENT_SCOPE )
else ( )
# On other platforms, Qt's own compilation goes needs to compile the Qt 5.0 API
set ( "${result}" "QT_DISABLE_DEPRECATED_BEFORE=0x050000" PARENT_SCOPE )
endif ( )
endfunction ( )
2019-02-11 16:09:03 +00:00
function ( qt_install_injections module )
set ( injections ${ ARGN } )
# examples:
# SYNCQT.INJECTIONS = src/corelib/global/qconfig.h:qconfig.h:QtConfig src/corelib/global/qconfig_p.h:5.12.0/QtCore/private/qconfig_p.h
# SYNCQT.INJECTIONS = src/gui/vulkan/qvulkanfunctions.h:^qvulkanfunctions.h:QVulkanFunctions:QVulkanDeviceFunctions src/gui/vulkan/qvulkanfunctions_p.h:^5.12.0/QtGui/private/qvulkanfunctions_p.h
separate_arguments ( injections UNIX_COMMAND "${injections}" )
foreach ( injection ${ injections } )
string ( REPLACE ":" ";" injection ${ injection } )
list ( GET injection 0 file )
list ( GET injection 1 destination )
string ( REGEX REPLACE "^\\^" "" destination "${destination}" )
list ( REMOVE_AT injection 0 1 )
set ( fwd_hdrs ${ injection } )
get_filename_component ( destinationdir ${ destination } DIRECTORY )
get_filename_component ( destinationname ${ destination } NAME )
2019-02-12 13:57:58 +00:00
install ( FILES ${ PROJECT_BINARY_DIR } / ${ file } DESTINATION ${ INSTALL_INCLUDEDIR } / ${ module } / ${ destinationdir } RENAME ${ destinationname } OPTIONAL )
2019-02-11 16:09:03 +00:00
foreach ( fwd_hdr ${ fwd_hdrs } )
file ( GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${fwd_hdr}" CONTENT "#include \" ${ destinationname } \"\n")
2019-02-12 13:57:58 +00:00
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/${fwd_hdr}" DESTINATION ${ INSTALL_INCLUDEDIR } / ${ module } / ${ destinationdir } OPTIONAL )
2019-02-11 16:09:03 +00:00
endforeach ( )
endforeach ( )
endfunction ( )
2018-12-07 13:04:42 +00:00
function ( qt_read_headers_pri target resultVarPrefix )
qt_internal_module_info ( module "${target}" )
file ( STRINGS "${module_include_dir}/headers.pri" headers_pri_contents )
2018-10-24 13:20:27 +00:00
foreach ( line ${ headers_pri_contents } )
if ( "${line}" MATCHES "SYNCQT.HEADER_FILES = (.*)" )
set ( public_module_headers "${CMAKE_MATCH_1}" )
separate_arguments ( public_module_headers UNIX_COMMAND "${public_module_headers}" )
elseif ( "${line}" MATCHES "SYNCQT.PRIVATE_HEADER_FILES = (.*)" )
set ( private_module_headers "${CMAKE_MATCH_1}" )
separate_arguments ( private_module_headers UNIX_COMMAND "${private_module_headers}" )
elseif ( "${line}" MATCHES "SYNCQT.GENERATED_HEADER_FILES = (.*)" )
set ( generated_module_headers "${CMAKE_MATCH_1}" )
separate_arguments ( generated_module_headers UNIX_COMMAND "${generated_module_headers}" )
foreach ( generated_header ${ generated_module_headers } )
2018-12-07 13:04:42 +00:00
list ( APPEND public_module_headers "${module_include_dir}/${generated_header}" )
2018-10-24 13:20:27 +00:00
endforeach ( )
2019-02-11 16:09:03 +00:00
elseif ( "${line}" MATCHES "SYNCQT.INJECTIONS = (.*)" )
set ( injections "${CMAKE_MATCH_1}" )
2018-10-24 13:20:27 +00:00
elseif ( "${line}" MATCHES "SYNCQT.([A-Z_]+)_HEADER_FILES = (.+)" )
set ( prefix "${CMAKE_MATCH_1}" )
string ( TOLOWER "${prefix}" prefix )
set ( entries "${CMAKE_MATCH_2}" )
separate_arguments ( entries UNIX_COMMAND "${entries}" )
set ( "${resultVarPrefix}_${prefix}" "${entries}" PARENT_SCOPE )
endif ( )
endforeach ( )
set ( ${ resultVarPrefix } _public "${public_module_headers}" PARENT_SCOPE )
set ( ${ resultVarPrefix } _private "${private_module_headers}" PARENT_SCOPE )
2019-02-11 16:09:03 +00:00
set ( ${ resultVarPrefix } _injections "${injections}" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2018-12-07 12:48:36 +00:00
# Add Qt::target and Qt6::target as aliases for the target
function ( qt_internal_add_target_aliases target )
get_target_property ( type "${target}" TYPE )
if ( type STREQUAL EXECUTABLE )
add_executable ( "Qt::${target}" ALIAS "${target}" )
add_executable ( "Qt${PROJECT_VERSION_MAJOR}::${target}" ALIAS "${target}" )
else ( )
add_library ( "Qt::${target}" ALIAS "${target}" )
add_library ( "Qt${PROJECT_VERSION_MAJOR}::${target}" ALIAS "${target}" )
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
# This is the main entry function for creating a Qt module, that typically
# consists of a library, public header files, private header files and configurable
# features.
#
2018-12-07 12:30:51 +00:00
# A CMake target with the specified target parameter is created. If the current source
2018-10-24 13:20:27 +00:00
# directory has a configure.cmake file, then that is also processed for feature definition
# and testing. Any features defined as well as any features coming from dependencies to
# this module are imported into the scope of the calling feature.
2018-12-07 12:30:51 +00:00
#
# Target is without leading "Qt". So e.g. the "QtCore" module has the target "Core".
function ( add_qt_module target )
2018-12-07 13:04:42 +00:00
qt_internal_module_info ( module "${target}" )
# Process arguments:
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
qt_parse_all_arguments ( arg "add_qt_module"
" N O _ M O D U L E _ H E A D E R S ; S T A T I C ; D I S A B L E _ T O O L S _ E X P O R T "
" C O N F I G _ M O D U L E _ N A M E "
2018-12-11 10:38:20 +00:00
" $ { _ _ d e f a u l t _ p r i v a t e _ a r g s } ; $ { _ _ d e f a u l t _ p u b l i c _ a r g s } " $ { A R G N } )
2018-10-24 13:20:27 +00:00
2018-12-07 13:04:42 +00:00
if ( NOT DEFINED arg_CONFIG_MODULE_NAME )
set ( arg_CONFIG_MODULE_NAME "${module_lower}" )
endif ( )
2018-10-24 13:20:27 +00:00
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
qt_internal_set_qt_known_modules ( "${QT_KNOWN_MODULES}" "${target}" )
2018-10-24 13:20:27 +00:00
### Define Targets:
2018-12-07 12:13:24 +00:00
if ( ${ arg_STATIC } )
2018-10-24 13:20:27 +00:00
add_library ( "${target}" STATIC )
elseif ( ${ QT_BUILD_SHARED_LIBS } )
add_library ( "${target}" SHARED )
else ( )
add_library ( "${target}" STATIC )
endif ( )
2018-12-07 12:48:36 +00:00
qt_internal_add_target_aliases ( "${target}" )
2018-10-24 13:20:27 +00:00
# Add _private target to link against the private headers:
set ( target_private "${target}Private" )
add_library ( "${target_private}" INTERFACE )
2018-12-07 12:48:36 +00:00
qt_internal_add_target_aliases ( "${target_private}" )
2018-10-24 13:20:27 +00:00
2018-12-11 10:38:20 +00:00
# Module headers:
2018-12-07 12:48:36 +00:00
if ( ${ arg_NO_MODULE_HEADERS } )
set_target_properties ( "${target}" PROPERTIES MODULE_HAS_HEADERS OFF )
else ( )
2018-12-07 13:04:42 +00:00
qt_ensure_sync_qt ( )
2018-10-24 13:20:27 +00:00
execute_process ( COMMAND "${HOST_PERL}" -w "${QT_SYNCQT}" -quiet -module "${module}" -version "${PROJECT_VERSION}" -outdir "${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}" )
set_target_properties ( "${target}" PROPERTIES MODULE_HAS_HEADERS ON )
2018-12-11 10:38:20 +00:00
### FIXME: Can we replace headers.pri?
qt_read_headers_pri ( "${target}" "module_headers" )
set_property ( TARGET "${target}" APPEND PROPERTY PUBLIC_HEADER "${module_headers_public}" )
set_property ( TARGET "${target}" APPEND PROPERTY PUBLIC_HEADER "${module_include_dir}/${module}Depends" )
set_property ( TARGET "${target}" APPEND PROPERTY PRIVATE_HEADER "${module_headers_private}" )
2019-02-11 16:09:03 +00:00
qt_install_injections ( "${module}" ${ module_headers_injections } )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-07 12:48:36 +00:00
set_target_properties ( "${target}" PROPERTIES
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / $ { I N S T A L L _ L I B D I R } "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { C M A K E _ B I N A R Y _ D I R } / $ { I N S T A L L _ B I N D I R } "
2019-02-12 10:20:22 +00:00
V E R S I O N $ { P R O J E C T _ V E R S I O N }
S O V E R S I O N $ { P R O J E C T _ V E R S I O N _ M A J O R }
2019-02-12 08:29:34 +00:00
O U T P U T _ N A M E " $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } " )
2018-10-24 13:20:27 +00:00
qt_internal_library_deprecation_level ( deprecation_define )
2019-03-06 12:51:38 +00:00
qt_autogen_tools ( "${target}"
D I S A B L E _ A U T O G E N _ T O O L S $ { a r g _ D I S A B L E _ A U T O G E N _ T O O L S }
)
2018-10-24 13:20:27 +00:00
extend_target ( "${target}"
2018-12-07 12:13:24 +00:00
S O U R C E S $ { a r g _ S O U R C E S }
2018-10-24 13:20:27 +00:00
P U B L I C _ I N C L U D E _ D I R E C T O R I E S
2018-12-07 13:04:42 +00:00
$ < B U I L D _ I N T E R F A C E : $ { m o d u l e _ i n c l u d e _ d i r } >
2018-10-24 13:20:27 +00:00
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e / $ { m o d u l e } >
2018-12-07 12:13:24 +00:00
$ { a r g _ P U B L I C _ I N C L U D E _ D I R E C T O R I E S }
2018-10-24 13:20:27 +00:00
I N C L U D E _ D I R E C T O R I E S
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
$ < B U I L D _ I N T E R F A C E : $ { P R O J E C T _ B I N A R Y _ D I R } / i n c l u d e >
2018-12-07 13:04:42 +00:00
" $ { m o d u l e _ i n c l u d e _ d i r } / $ { P R O J E C T _ V E R S I O N } "
" $ { m o d u l e _ i n c l u d e _ d i r } / $ { P R O J E C T _ V E R S I O N } / $ { m o d u l e } "
2018-12-07 12:13:24 +00:00
$ { a r g _ I N C L U D E _ D I R E C T O R I E S }
2018-10-24 13:20:27 +00:00
P U B L I C _ D E F I N E S
2018-12-07 12:13:24 +00:00
$ { a r g _ P U B L I C _ D E F I N E S }
2018-12-07 12:30:51 +00:00
Q T _ $ { m o d u l e _ u p p e r } _ L I B
2018-10-24 13:20:27 +00:00
D E F I N E S
2018-12-07 12:13:24 +00:00
$ { a r g _ D E F I N E S }
2018-10-24 13:20:27 +00:00
Q T _ N O _ C A S T _ T O _ A S C I I Q T _ A S C I I _ C A S T _ W A R N I N G S
Q T _ M O C _ C O M P A T #we don't need warnings from calling moc code in our generated code
Q T _ U S E _ Q S T R I N G B U I L D E R
Q T _ D E P R E C A T E D _ W A R N I N G S
Q T _ B U I L D I N G _ Q T
2018-12-07 12:30:51 +00:00
Q T _ B U I L D _ $ { m o d u l e _ u p p e r } _ L I B ### FIXME: use QT_BUILD_ADDON for Add-ons or remove if we don't have add-ons anymore
2018-10-24 13:20:27 +00:00
" $ { d e p r e c a t i o n _ d e f i n e } "
2018-12-11 10:38:20 +00:00
P U B L I C _ L I B R A R I E S $ { a r g _ P U B L I C _ L I B R A R I E S }
L I B R A R I E S $ { a r g _ L I B R A R I E S }
F E A T U R E _ D E P E N D E N C I E S $ { a r g _ F E A T U R E _ D E P E N D E N C I E S }
D B U S _ A D A P T O R _ S O U R C E S $ { a r g _ D B U S _ A D A P T O R _ S O U R C E S }
D B U S _ A D A P T O R _ F L A G S $ { a r g _ D B U S _ A D A P T O R _ F L A G S }
D B U S _ I N T E R F A C E _ S O U R C E S $ { a r g _ D B U S _ I N T E R F A C E _ S O U R C E S }
D B U S _ I N T E R F A C E _ F L A G S $ { a r g _ D B U S _ I N T E R F A C E _ F L A G S }
2019-01-29 11:07:24 +00:00
C O M P I L E _ O P T I O N S $ { a r g _ C O M P I L E _ O P T I O N S }
P U B L I C _ C O M P I L E _ O P T I O N S $ { a r g _ P U B L I C _ C O M P I L E _ O P T I O N S }
L I N K _ O P T I O N S $ { a r g _ L I N K _ O P T I O N S }
P U B L I C _ L I N K _ O P T I O N S $ { a r g _ P U B L I C _ L I N K _ O P T I O N S }
2019-01-30 15:43:11 +00:00
M O C _ O P T I O N S $ { a r g _ M O C _ O P T I O N S }
2018-10-24 13:20:27 +00:00
)
2018-12-11 10:38:20 +00:00
set ( configureFile "${CMAKE_CURRENT_SOURCE_DIR}/configure.cmake" )
if ( EXISTS "${configureFile}" )
qt_feature_module_begin (
L I B R A R Y " $ { t a r g e t } "
P U B L I C _ F I L E " q t $ { a r g _ C O N F I G _ M O D U L E _ N A M E } - c o n f i g . h "
P R I V A T E _ F I L E " q t $ { a r g _ C O N F I G _ M O D U L E _ N A M E } - c o n f i g _ p . h "
P U B L I C _ D E P E N D E N C I E S $ { a r g _ F E A T U R E _ 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 _ F E A T U R E _ D E P E N D E N C I E S }
)
include ( ${ configureFile } )
qt_feature_module_end ( "${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" )
2018-10-24 13:20:27 +00:00
endif ( )
if ( DEFINED module_headers_private )
qt_internal_add_linker_version_script ( "${target}" PRIVATE_HEADERS ${ module_headers_private } )
else ( )
qt_internal_add_linker_version_script ( "${target}" )
endif ( )
2019-02-12 08:29:34 +00:00
install ( TARGETS "${target}" "${target_private}" EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
2018-10-24 13:20:27 +00:00
L I B R A R Y D E S T I N A T I O N $ { I N S T A L L _ L I B D I R }
A R C H I V E D E S T I N A T I O N $ { I N S T A L L _ L I B D I R }
P U B L I C _ H E A D E R D E S T I N A T I O N $ { I N S T A L L _ I N C L U D E D I R } / $ { m o d u l e }
P R I V A T E _ H E A D E R D E S T I N A T I O N $ { I N S T A L L _ I N C L U D E D I R } / $ { m o d u l e } / $ { P R O J E C T _ V E R S I O N } / $ { m o d u l e } / p r i v a t e
)
2019-02-11 10:34:35 +00:00
set ( config_install_dir "${INSTALL_LIBDIR}/cmake/${INSTALL_CMAKE_NAMESPACE}${target}" )
2019-02-12 08:29:34 +00:00
install ( EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets" NAMESPACE ${ QT_CMAKE_EXPORT_NAMESPACE } :: DESTINATION ${ config_install_dir } )
2018-10-24 13:20:27 +00:00
2019-05-03 10:30:09 +00:00
qt_internal_export_modern_cmake_config_targets_file ( TARGETS "${target}" "${target_private}"
E X P O R T _ N A M E _ P R E F I X $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t }
C O N F I G _ I N S T A L L _ D I R " $ { c o n f i g _ i n s t a l l _ d i r } " )
2019-02-12 11:21:56 +00:00
set ( extra_cmake_files )
set ( extra_cmake_includes )
if ( EXISTS "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}Macros.cmake" )
list ( APPEND extra_cmake_files "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}Macros.cmake" )
list ( APPEND extra_cmake_includes "${INSTALL_CMAKE_NAMESPACE}${target}Macros.cmake" )
endif ( )
if ( EXISTS "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake.in" )
configure_file ( "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake.in"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g E x t r a s . c m a k e "
@ O N L Y )
list ( APPEND extra_cmake_files "${CMAKE_CURRENT_BINARY_DIR}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake" )
list ( APPEND extra_cmake_includes "${INSTALL_CMAKE_NAMESPACE}${target}ConfigExtras.cmake" )
endif ( )
2018-10-24 13:20:27 +00:00
### fixme: cmake is missing a built-in variable for this. We want to apply it only to modules and plugins
# that belong to Qt.
2019-02-27 12:49:04 +00:00
qt_internal_add_link_flags_no_undefined ( "${target}" )
2018-10-24 13:20:27 +00:00
# When a public module depends on private, also make its private depend on the other's private
2018-12-07 12:13:24 +00:00
set ( qt_libs_private "" )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
foreach ( it ${ QT_KNOWN_MODULES } )
2018-12-07 12:13:24 +00:00
list ( FIND arg_LIBRARIES "Qt::${it}Private" pos )
if ( pos GREATER -1 )
list ( APPEND qt_libs_private "Qt::${it}Private" )
2018-10-24 13:20:27 +00:00
endif ( )
endforeach ( )
2018-12-07 12:13:24 +00:00
target_link_libraries ( "${target_private}" INTERFACE "${target}" "${qt_libs_private}" )
2018-10-24 13:20:27 +00:00
target_include_directories ( "${target_private}" INTERFACE
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } >
2018-12-07 13:04:42 +00:00
$ < B U I L D _ I N T E R F A C E : $ { m o d u l e _ i n c l u d e _ d i r } / $ { P R O J E C T _ V E R S I O N } >
$ < B U I L D _ I N T E R F A C E : $ { m o d u l e _ i n c l u d e _ d i r } / $ { P R O J E C T _ V E R S I O N } / $ { m o d u l e } >
2018-10-24 13:20:27 +00:00
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e / $ { m o d u l e } / $ { P R O J E C T _ V E R S I O N } >
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e / $ { m o d u l e } / $ { P R O J E C T _ V E R S I O N } / $ { m o d u l e } >
)
2019-02-12 19:17:57 +00:00
2019-05-03 09:38:41 +00:00
get_target_property ( target_deps "${target}" _qt_target_deps )
if ( NOT target_deps )
set ( target_deps "" )
endif ( )
# TODO: should this also be in extend_target ? From the looks of it I would say that
# it is not necessary but I'm not sure
2019-02-12 19:17:57 +00:00
foreach ( lib IN LISTS arg_PUBLIC_LIBRARIES qt_libs_private )
if ( "${lib}" MATCHES "^Qt::(.*)" )
set ( lib "${CMAKE_MATCH_1}" )
if ( lib STREQUAL Platform OR lib STREQUAL GlobalConfig )
list ( APPEND target_deps "Qt5\;${PROJECT_VERSION}" )
elseif ( "${lib}" MATCHES "(.*)Private" )
list ( APPEND target_deps "${INSTALL_CMAKE_NAMESPACE}${CMAKE_MATCH_1}\;${PROJECT_VERSION}" )
else ( )
list ( APPEND target_deps "${INSTALL_CMAKE_NAMESPACE}${lib}\;${PROJECT_VERSION}" )
endif ( )
endif ( )
endforeach ( )
2019-05-03 09:38:41 +00:00
set_target_properties ( "${target}" PROPERTIES _qt_target_deps "${target_deps}" )
2019-02-11 11:12:07 +00:00
2019-02-12 19:17:57 +00:00
configure_package_config_file (
" $ { Q T _ C M A K E _ D I R } / Q t M o d u l e C o n f i g . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g . c m a k e "
I N S T A L L _ D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
)
write_basic_package_version_file (
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g V e r s i o n . c m a k e
V E R S I O N $ { P R O J E C T _ V E R S I O N }
C O M P A T I B I L I T Y A n y N e w e r V e r s i o n
)
install ( FILES
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g . c m a k e "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g V e r s i o n . c m a k e "
$ { e x t r a _ c m a k e _ f i l e s }
D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
C O M P O N E N T D e v e l
)
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
if ( NOT ${ arg_DISABLE_TOOLS_EXPORT } )
qt_export_tools ( ${ target } )
endif ( )
endfunction ( )
function ( qt_export_tools module_name )
# If no tools were defined belonging to this module, don't create a config and targets file.
# Guards against the case when doing a cross-build and the function is called manually and not
# by add_qt_module.
if ( NOT "${module_name}" IN_LIST QT_KNOWN_MODULES_WITH_TOOLS )
return ( )
endif ( )
# The tools target name. For example: CoreTools
set ( target "${module_name}Tools" )
set ( config_install_dir "${INSTALL_LIBDIR}/cmake/${INSTALL_CMAKE_NAMESPACE}${target}" )
# Add the extra cmake statements to make the tool targets global, so it doesn't matter where
# find_package is called.
# Also assemble a list of tool targets to expose in the config file for informational purposes.
set ( extra_cmake_statements "" )
set ( tool_targets "" )
foreach ( tool_name ${ QT_KNOWN_MODULE_${module_name } _TOOLS} )
set ( extra_cmake_statements " ${ extra_cmake_statements }
get_property ( is_global TARGET ${ INSTALL_CMAKE_NAMESPACE } :: ${ tool_name } PROPERTY IMPORTED_GLOBAL )
if ( NOT is_global )
set_property ( TARGET ${ INSTALL_CMAKE_NAMESPACE } :: ${ tool_name } PROPERTY IMPORTED_GLOBAL TRUE )
endif ( )
" )
list ( APPEND tool_targets "${QT_CMAKE_EXPORT_NAMESPACE}::${tool_name}" )
endforeach ( )
string ( APPEND extra_cmake_statements
" set ( ${ QT_CMAKE_EXPORT_NAMESPACE } ${ module_name } Tools_TARGETS \"${tool_targets}\")")
configure_package_config_file (
" $ { Q T _ C M A K E _ D I R } / Q t M o d u l e T o o l s C o n f i g . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g . c m a k e "
I N S T A L L _ D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
)
write_basic_package_version_file (
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g V e r s i o n . c m a k e "
V E R S I O N $ { P R O J E C T _ V E R S I O N }
C O M P A T I B I L I T Y A n y N e w e r V e r s i o n
)
install ( FILES
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g . c m a k e "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } C o n f i g V e r s i o n . c m a k e "
D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
C O M P O N E N T D e v e l
)
install ( EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
N A M E S P A C E " $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : "
D E S T I N A T I O N " $ { I N S T A L L _ L I B D I R } / c m a k e / $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t } " )
2019-05-03 10:30:09 +00:00
qt_internal_export_modern_cmake_config_targets_file ( TARGETS ${ QT_KNOWN_MODULE_${module_name } _TOOLS}
E X P O R T _ N A M E _ P R E F I X $ { I N S T A L L _ C M A K E _ N A M E S P A C E } $ { t a r g e t }
C O N F I G _ I N S T A L L _ D I R $ { c o n f i g _ i n s t a l l _ d i r } )
2018-10-24 13:20:27 +00:00
endfunction ( )
2019-03-26 12:32:34 +00:00
function ( qt_internal_check_directory_or_type name dir type default result_var )
if ( "x${dir}" STREQUAL x )
if ( "x${type}" STREQUAL x )
message ( FATAL_ERROR "add_qt_plugin called without setting either TYPE or ${name}." )
endif ( )
set ( ${ result_var } "${default}" PARENT_SCOPE )
else ( )
set ( ${ result_var } "${dir}" PARENT_SCOPE )
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
# This is the main entry point for defining Qt plugins.
2018-12-11 10:38:20 +00:00
# A CMake target is created with the given target. The TYPE parameter is needed to place the
2018-10-24 13:20:27 +00:00
# plugin into the correct plugins/ sub-directory.
2018-12-11 10:38:20 +00:00
function ( add_qt_plugin target )
qt_internal_module_info ( module "${target}" )
2018-10-24 13:20:27 +00:00
2019-03-26 12:32:34 +00:00
qt_parse_all_arguments ( arg "add_qt_plugin" "STATIC"
" T Y P E ; O U T P U T _ D I R E C T O R Y ; I N S T A L L _ D I R E C T O R Y ; A R C H I V E _ I N S T A L L _ D I R E C T O R Y "
" $ { _ _ d e f a u l t _ p r i v a t e _ a r g s } ; $ { _ _ d e f a u l t _ p u b l i c _ a r g s } " $ { A R G N } )
qt_internal_check_directory_or_type ( OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}" "${arg_TYPE}"
" $ { C M A K E _ B I N A R Y _ D I R } / $ { I N S T A L L _ P L U G I N S D I R } / $ { a r g _ T Y P E } " o u t p u t _ d i r e c t o r y )
qt_internal_check_directory_or_type ( INSTALL_DIRECTORY "${arg_INSTALL_DIRECTORY}" "${arg_TYPE}"
" $ { I N S T A L L _ P L U G I N S D I R } / $ { a r g _ T Y P E } " i n s t a l l _ d i r e c t o r y )
qt_internal_check_directory_or_type ( ARCHIVE_INSTALL_DIRECTORY
" $ { a r g _ A R C H I V E _ I N S T A L L _ D I R E C T O R Y } " " $ { a r g _ T Y P E } "
" $ { I N S T A L L _ L I B D I R } / $ { a r g _ T Y P E } " a r c h i v e _ i n s t a l l _ d i r e c t o r y )
2018-10-24 13:20:27 +00:00
2019-03-26 12:32:34 +00:00
if ( arg_STATIC )
add_library ( "${target}" STATIC )
else ( )
add_library ( "${target}" )
endif ( )
2018-12-11 10:38:20 +00:00
qt_internal_add_target_aliases ( "${target}" )
2018-10-24 13:20:27 +00:00
2018-12-11 10:38:20 +00:00
set_target_properties ( "${target}" PROPERTIES
2019-03-26 12:32:34 +00:00
L I B R A R Y _ O U T P U T _ D I R E C T O R Y " $ { o u t p u t _ d i r e c t o r y } "
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { o u t p u t _ d i r e c t o r y } "
A R C H I V E _ O U T P U T _ D I R E C T O R Y " $ { o u t p u t _ d i r e c t o r y } " )
2018-10-24 13:20:27 +00:00
qt_internal_library_deprecation_level ( deprecation_define )
2019-03-06 12:51:38 +00:00
qt_autogen_tools ( "${target}"
D I S A B L E _ A U T O G E N _ T O O L S $ { a r g _ D I S A B L E _ A U T O G E N _ T O O L S }
)
2019-03-26 12:39:43 +00:00
set ( static_plugin_define "" )
if ( arg_STATIC OR NOT QT_BUILD_SHARED_LIBS )
set ( static_plugin_define "QT_STATICPLUGIN" )
endif ( )
2018-12-11 10:38:20 +00:00
extend_target ( "${target}"
2018-12-07 12:13:24 +00:00
S O U R C E S $ { a r g _ S O U R C E S }
2018-10-24 13:20:27 +00:00
I N C L U D E _ D I R E C T O R I E S
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
2019-04-25 13:54:29 +00:00
# For the syncqt headers
$ < B U I L D _ I N T E R F A C E : $ { P R O J E C T _ B I N A R Y _ D I R } / i n c l u d e >
2018-12-07 12:13:24 +00:00
$ { a r g _ I N C L U D E _ D I R E C T O R I E S }
P U B L I C _ I N C L U D E _ D I R E C T O R I E S $ { a r g _ P U B L I C _ I N C L U D E _ D I R E C T O R I E S }
L I B R A R I E S $ { a r g _ L I B R A R I E S }
P U B L I C _ L I B R A R I E S $ { a r g _ P U B L I C _ L I B R A R I E S }
2018-10-24 13:20:27 +00:00
D E F I N E S
2018-12-07 12:13:24 +00:00
$ { a r g _ D E F I N E S }
2018-10-24 13:20:27 +00:00
Q T _ N O _ C A S T _ T O _ A S C I I Q T _ A S C I I _ C A S T _ W A R N I N G S
Q T _ M O C _ C O M P A T #we don't need warnings from calling moc code in our generated code
Q T _ U S E _ Q S T R I N G B U I L D E R
Q T _ D E P R E C A T E D _ W A R N I N G S
Q T _ B U I L D I N G _ Q T
2018-12-11 10:38:20 +00:00
Q T _ B U I L D _ $ { m o d u l e _ u p p e r } _ L I B ### FIXME: use QT_BUILD_ADDON for Add-ons or remove if we don't have add-ons anymore
2018-10-24 13:20:27 +00:00
" $ { d e p r e c a t i o n _ d e f i n e } "
2019-03-26 12:39:43 +00:00
" $ { s t a t i c _ p l u g i n _ d e f i n e } "
2019-03-11 11:34:52 +00:00
Q T _ P L U G I N
2018-10-24 13:20:27 +00:00
P U B L I C _ D E F I N E S
2018-12-11 10:38:20 +00:00
Q T _ $ { m o d u l e _ u p p e r } _ L I B
2018-12-07 12:13:24 +00:00
$ { a r g _ P U B L I C _ D E F I N E S }
2018-12-11 10:38:20 +00:00
F E A T U R E _ D E P E N D E N C I E S $ { a r g _ F E A T U R E _ D E P E N D E N C I E S }
2018-12-07 12:13:24 +00:00
D B U S _ A D A P T O R _ S O U R C E S " $ { a r g _ D B U S _ A D A P T O R _ S O U R C E S } "
D B U S _ A D A P T O R _ F L A G S " $ { a r g _ D B U S _ A D A P T O R _ F L A G S } "
D B U S _ I N T E R F A C E _ S O U R C E S " $ { a r g _ D B U S _ I N T E R F A C E _ S O U R C E S } "
D B U S _ I N T E R F A C E _ F L A G S " $ { a r g _ D B U S _ I N T E R F A C E _ F L A G S } "
2019-01-29 11:07:24 +00:00
C O M P I L E _ O P T I O N S $ { a r g _ C O M P I L E _ O P T I O N S }
P U B L I C _ C O M P I L E _ O P T I O N S $ { a r g _ P U B L I C _ C O M P I L E _ O P T I O N S }
L I N K _ O P T I O N S $ { a r g _ L I N K _ O P T I O N S }
P U B L I C _ L I N K _ O P T I O N S $ { a r g _ P U B L I C _ L I N K _ O P T I O N S }
2019-01-30 15:43:11 +00:00
M O C _ O P T I O N S $ { a r g _ M O C _ O P T I O N S }
2018-10-24 13:20:27 +00:00
)
2018-12-11 10:38:20 +00:00
install ( TARGETS "${target}" EXPORT "${target}Targets"
2019-03-26 12:32:34 +00:00
L I B R A R Y D E S T I N A T I O N " $ { i n s t a l l _ d i r e c t o r y } "
A R C H I V E D E S T I N A T I O N " $ { a r c h i v e _ i n s t a l l _ d i r e c t o r y } " )
2019-02-12 09:02:15 +00:00
install ( EXPORT "${target}Targets" NAMESPACE ${ QT_CMAKE_EXPORT_NAMESPACE } :: DESTINATION ${ INSTALL_LIBDIR } /cmake )
2018-10-24 13:20:27 +00:00
### fixme: cmake is missing a built-in variable for this. We want to apply it only to modules and plugins
# that belong to Qt.
2019-02-27 12:49:04 +00:00
qt_internal_add_link_flags_no_undefined ( "${target}" )
2018-10-24 13:20:27 +00:00
2018-12-11 10:38:20 +00:00
qt_internal_add_linker_version_script ( ${ target } )
2018-10-24 13:20:27 +00:00
endfunction ( )
# This function creates a CMake target for a generic console or GUI binary.
# Please consider to use a more specific version target like the one created
# by add_qt_test or add_qt_tool below.
function ( add_qt_executable name )
2019-04-29 14:32:21 +00:00
qt_parse_all_arguments ( arg "add_qt_executable" "GUI;BOOTSTRAP;NO_QT;NO_INSTALL" "OUTPUT_DIRECTORY;INSTALL_DIRECTORY" "EXE_FLAGS;${__default_private_args}" ${ ARGN } )
2018-10-24 13:20:27 +00:00
2018-12-07 12:13:24 +00:00
if ( "x${arg_OUTPUT_DIRECTORY}" STREQUAL "x" )
set ( arg_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}" )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-18 17:49:04 +00:00
get_filename_component ( arg_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
A B S O L U T E B A S E _ D I R " $ { C M A K E _ B I N A R Y _ D I R } " )
2019-03-18 18:09:27 +00:00
if ( "x${arg_INSTALL_DIRECTORY}" STREQUAL "x" )
set ( arg_INSTALL_DIRECTORY "${INSTALL_BINDIR}" )
endif ( )
2018-12-07 12:13:24 +00:00
add_executable ( "${name}" ${ arg_EXE_FLAGS } )
2019-03-06 12:51:38 +00:00
qt_autogen_tools ( "${name}"
D I S A B L E _ A U T O G E N _ T O O L S $ { a r g _ D I S A B L E _ A U T O G E N _ T O O L S }
)
2019-03-20 11:09:12 +00:00
set ( extra_libraries "" )
2019-04-29 14:32:21 +00:00
if ( NOT arg_BOOTSTRAP AND NOT arg_NO_QT )
2019-03-20 11:09:12 +00:00
set ( extra_libraries "Qt::Core" )
endif ( )
2018-10-24 13:20:27 +00:00
extend_target ( "${name}"
2018-12-07 12:13:24 +00:00
S O U R C E S $ { a r g _ S O U R C E S }
2018-10-24 13:20:27 +00:00
I N C L U D E _ D I R E C T O R I E S
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
2018-12-07 12:13:24 +00:00
$ { a r g _ I N C L U D E _ D I R E C T O R I E S }
D E F I N E S $ { a r g _ D E F I N E S }
2019-03-20 11:09:12 +00:00
L I B R A R I E S $ { a r g _ L I B R A R I E S } $ { e x t r a _ l i b r a r i e s }
2018-12-07 12:13:24 +00:00
D B U S _ A D A P T O R _ S O U R C E S " $ { a r g _ D B U S _ A D A P T O R _ S O U R C E S } "
D B U S _ A D A P T O R _ F L A G S " $ { a r g _ D B U S _ A D A P T O R _ F L A G S } "
D B U S _ I N T E R F A C E _ S O U R C E S " $ { a r g _ D B U S _ I N T E R F A C E _ S O U R C E S } "
D B U S _ I N T E R F A C E _ F L A G S " $ { a r g _ D B U S _ I N T E R F A C E _ F L A G S } "
2019-01-29 11:07:24 +00:00
C O M P I L E _ O P T I O N S $ { a r g _ C O M P I L E _ O P T I O N S }
L I N K _ O P T I O N S $ { a r g _ L I N K _ O P T I O N S }
2019-01-30 15:43:11 +00:00
M O C _ O P T I O N S $ { a r g _ M O C _ O P T I O N S }
2018-10-24 13:20:27 +00:00
)
set_target_properties ( "${name}" PROPERTIES
2018-12-07 12:13:24 +00:00
R U N T I M E _ O U T P U T _ D I R E C T O R Y " $ { a r g _ O U T P U T _ D I R E C T O R Y } "
W I N 3 2 _ E X E C U T A B L E " $ { a r g _ G U I } "
M A C O S X _ B U N D L E " $ { a r g _ G U I } "
2018-10-24 13:20:27 +00:00
)
2019-03-18 18:09:27 +00:00
2019-04-16 10:49:16 +00:00
if ( WIN32 )
# Workaround for not having ported the winmain / qtmain static library
# which is always linked in by qmake.
set_target_properties ( "${name}" PROPERTIES WIN32_EXECUTABLE 0 )
endif ( )
2019-04-03 09:33:28 +00:00
if ( NOT arg_NO_INSTALL )
install ( TARGETS "${name}"
R U N T I M E D E S T I N A T I O N " $ { a r g _ I N S T A L L _ D I R E C T O R Y } "
B U N D L E D E S T I N A T I O N " $ { a r g _ I N S T A L L _ D I R E C T O R Y } " )
endif ( )
2018-10-24 13:20:27 +00:00
endfunction ( )
# This function creates a CMake test target with the specified name for use with CTest.
function ( add_qt_test name )
2018-12-07 12:13:24 +00:00
qt_parse_all_arguments ( arg "add_qt_test" "RUN_SERIAL" "" "${__default_private_args}" ${ ARGN } )
set ( path "${CMAKE_CURRENT_BINARY_DIR}" )
2018-10-24 13:20:27 +00:00
add_qt_executable ( "${name}"
2019-04-03 09:33:28 +00:00
N O _ I N S T A L L
2018-12-07 12:13:24 +00:00
O U T P U T _ D I R E C T O R Y " $ { p a t h } "
S O U R C E S " $ { a r g _ S O U R C E S } "
2018-10-24 13:20:27 +00:00
I N C L U D E _ D I R E C T O R I E S
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
2019-05-03 12:46:29 +00:00
$ < B U I L D _ I N T E R F A C E : $ { P R O J E C T _ B I N A R Y _ D I R } / i n c l u d e >
2018-12-07 12:13:24 +00:00
" $ { a r g _ I N C L U D E _ D I R E C T O R I E S } "
D E F I N E S " $ { a r g _ D E F I N E S } "
2019-02-12 09:02:15 +00:00
L I B R A R I E S $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : C o r e $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : T e s t $ { a r g _ L I B R A R I E S }
2019-01-29 11:07:24 +00:00
C O M P I L E _ O P T I O N S $ { a r g _ C O M P I L E _ O P T I O N S }
L I N K _ O P T I O N S $ { a r g _ L I N K _ O P T I O N S }
2019-01-30 15:43:11 +00:00
M O C _ O P T I O N S $ { a r g _ M O C _ O P T I O N S }
2019-03-06 12:51:38 +00:00
D I S A B L E _ A U T O G E N _ T O O L S $ { a r g _ D I S A B L E _ A U T O G E N _ T O O L S }
2018-10-24 13:20:27 +00:00
)
2019-04-05 15:23:16 +00:00
add_test ( NAME "${name}" COMMAND "${name}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" )
2018-10-24 13:20:27 +00:00
2018-12-07 12:13:24 +00:00
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}" )
2018-10-24 13:20:27 +00:00
set_property ( TEST "${name}" APPEND PROPERTY ENVIRONMENT "QT_PLUGIN_PATH=${PROJECT_BINARY_DIR}/${INSTALL_PLUGINSDIR}" )
endfunction ( )
# This function creates an executable for use as helper program with tests. Some
# tests launch separate programs to test certainly input/output behavior.
function ( add_qt_test_helper name )
2019-04-05 09:17:24 +00:00
add_qt_executable ( "${name}" NO_INSTALL OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/.." ${ ARGN } )
2018-10-24 13:20:27 +00:00
endfunction ( )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
# Sets QT_WILL_BUILD_TOOLS if tools will be built.
function ( qt_check_if_tools_will_be_built )
set01 ( will_build_tools NOT CMAKE_CROSSCOMPILING AND NOT QT_FORCE_FIND_TOOLS )
set ( QT_WILL_BUILD_TOOLS ${ will_build_tools } CACHE INTERNAL "Are tools going to be built" FORCE )
endfunction ( )
2018-10-24 13:20:27 +00:00
# This function is used to define a "Qt tool", such as moc, uic or rcc.
# The BOOTSTRAP option allows building it as standalone program, otherwise
# it will be linked against QtCore.
function ( add_qt_tool name )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
qt_parse_all_arguments ( arg "add_qt_tool" "BOOTSTRAP;NO_QT;NO_INSTALL" "TOOLS_TARGET"
" $ { _ _ d e f a u l t _ p r i v a t e _ a r g s } " $ { A R G N } )
# Handle case when a tool does not belong to a module and it can't be built either (like
# during a cross-compile).
if ( NOT arg_TOOLS_TARGET AND NOT QT_WILL_BUILD_TOOLS )
message ( FATAL_ERROR "The tool \" ${ name } \" has not been assigned to a module via "
" TOOLS_TARGET ( so it can't be found ) a n d i t c a n ' t b e b u i l t "
" ( Q T _ W I L L _ B U I L D _ T O O L S i s $ { Q T _ W I L L _ B U I L D _ T O O L S } ) . " )
endif ( )
set ( full_name "${QT_CMAKE_EXPORT_NAMESPACE}::${name}" )
if ( TARGET ${ full_name } )
get_property ( path TARGET ${ full_name } PROPERTY LOCATION )
message ( STATUS "Tool '${full_name}' was found at ${path}." )
2019-02-11 14:50:17 +00:00
return ( )
endif ( )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
if ( arg_TOOLS_TARGET AND NOT QT_WILL_BUILD_TOOLS )
set ( tools_package_name "Qt5${arg_TOOLS_TARGET}Tools" )
message ( STATUS "Searching for tool '${full_name}' in package ${tools_package_name}." )
# Only search in path provided by QT_HOST_PATH. We need to do it with CMAKE_PREFIX_PATH
# instead of PATHS option, because any find_dependency call inside a Tools package would
# not get the proper prefix when using PATHS.
set ( BACKUP_CMAKE_PREFIX_PATH ${ CMAKE_PREFIX_PATH } )
set ( CMAKE_PREFIX_PATH "${QT_HOST_PATH}" )
2019-05-03 10:07:37 +00:00
# Search both with sysroots prepended as well as in the host system. When cross compiling
# the mode_package might be set to ONLY only, and the Qt5 tools packages are actually
# in the host system.
set ( BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ${ CMAKE_FIND_ROOT_PATH_MODE_PACKAGE } )
set ( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "BOTH" )
set ( BACKUP_CMAKE_SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}" )
set ( CMAKE_SIZEOF_VOID_P "" )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
find_package (
$ { t o o l s _ p a c k a g e _ n a m e }
$ { P R O J E C T _ V E R S I O N }
N O _ P A C K A G E _ R O O T _ P A T H
N O _ C M A K E _ E N V I R O N M E N T _ P A T H
N O _ S Y S T E M _ E N V I R O N M E N T _ P A T H
N O _ C M A K E _ P A C K A G E _ R E G I S T R Y
N O _ C M A K E _ S Y S T E M _ P A T H
N O _ C M A K E _ S Y S T E M _ P A C K A G E _ R E G I S T R Y )
2019-05-03 10:07:37 +00:00
set ( CMAKE_SIZEOF_VOID_P "${BACKUP_CMAKE_SIZEOF_VOID_P}" )
set ( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE "${BACKUP_CMAKE_FIND_ROOT_PATH_MODE_PACKAGE}" )
set ( CMAKE_PREFIX_PATH "${BACKUP_CMAKE_PREFIX_PATH}" )
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
if ( ${ ${tools_package_name } _FOUND} AND TARGET ${ full_name } )
get_property ( path TARGET ${ full_name } PROPERTY LOCATION )
message ( STATUS "${full_name} was found at ${path} using package ${tools_package_name}." )
return ( )
endif ( )
endif ( )
if ( NOT QT_WILL_BUILD_TOOLS )
message ( FATAL_ERROR "The tool \" ${ full_name } \" was not found in the "
" $ { t o o l s _ p a c k a g e _ n a m e } p a c k a g e . "
" P a c k a g e f o u n d : $ { $ { t o o l s _ p a c k a g e _ n a m e } _ F O U N D } " )
else ( )
message ( STATUS "Tool '${full_name}' will be built from source." )
endif ( )
2018-10-24 13:20:27 +00:00
2019-03-06 12:51:38 +00:00
set ( disable_autogen_tools "${arg_DISABLE_AUTOGEN_TOOLS}" )
2019-04-29 11:14:22 +00:00
if ( arg_NO_QT )
# FIXME: Remove NO_QT again once qmake can use a "normal" Qt!
if ( arg_BOOTSTRAP )
message ( FATAL_ERROR "Tool can not be NO_QT and BOOTSTRAP at the same time!" )
endif ( )
set ( corelib "" )
2018-10-24 13:20:27 +00:00
else ( )
2019-04-29 11:14:22 +00:00
if ( arg_BOOTSTRAP )
set ( corelib ${ QT_CMAKE_EXPORT_NAMESPACE } ::Bootstrap )
list ( APPEND disable_autogen_tools "uic" "moc" "rcc" )
else ( )
set ( corelib ${ QT_CMAKE_EXPORT_NAMESPACE } ::Core )
endif ( )
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-20 11:09:12 +00:00
set ( bootstrap "" )
if ( arg_BOOTSTRAP )
set ( bootstrap BOOTSTRAP )
endif ( )
2019-04-29 14:32:21 +00:00
set ( no_qt "" )
if ( arg_NO_QT )
set ( no_qt NO_QT )
endif ( )
2019-04-03 09:33:28 +00:00
set ( no_install "" )
if ( arg_NO_INSTALL )
set ( no_install NO_INSTALL )
endif ( )
2018-10-24 13:20:27 +00:00
add_qt_executable ( "${name}" OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}"
2019-03-20 11:09:12 +00:00
$ { b o o t s t r a p }
2019-04-29 14:32:21 +00:00
$ { n o _ q t }
2019-04-03 09:33:28 +00:00
$ { n o _ i n s t a l l }
2018-12-12 09:55:20 +00:00
S O U R C E S $ { a r g _ S O U R C E S }
2018-10-24 13:20:27 +00:00
I N C L U D E _ D I R E C T O R I E S
2018-12-07 12:13:24 +00:00
$ { a r g _ I N C L U D E _ D I R E C T O R I E S }
D E F I N E S $ { a r g _ D E F I N E S }
L I B R A R I E S $ { c o r e l i b } $ { a r g _ L I B R A R I E S }
2019-01-29 11:07:24 +00:00
C O M P I L E _ O P T I O N S $ { a r g _ C O M P I L E _ O P T I O N S }
L I N K _ O P T I O N S $ { a r g _ L I N K _ O P T I O N S }
2019-01-30 15:43:11 +00:00
M O C _ O P T I O N S $ { a r g _ M O C _ O P T I O N S }
2019-03-06 12:51:38 +00:00
D I S A B L E _ A U T O G E N _ T O O L S $ { d i s a b l e _ a u t o g e n _ t o o l s }
2018-10-24 13:20:27 +00:00
)
2018-12-07 12:48:36 +00:00
qt_internal_add_target_aliases ( "${name}" )
2018-10-24 13:20:27 +00:00
Export tool config and target files for each relevant module
CMake will now generate config and target files for each module that
provides tools. As a result, namespaced global targets such as
Qt5::moc or Qt5::rcc can be made available.
Third party projects that require just these tools, and not the Qt
modules themselves, should specify CMAKE_PREFIX_PATH pointing to the
installed Qt location, and call find_package(Qt5CoreTools),
find_package(Qt5GuiTools), etc.
It is also possible to call
find_package(Qt5Tools REQUIRED Core Widgets) where the last option
is a list of modules whose tools should be imported.
Note that all the tools are in the Qt5::
namespace and not in the Qt5CoreTools:: or Qt5WidgetsTools::
namespace.
This commit also changes the behavior regarding when to build tools
while building Qt itself.
When cross compiling Qt (checked via CMAKE_CROSSCOMPILING) or when
-DQT_FORCE_FIND_TOOLS=TRUE is passed, tools added by add_qt_tool will
always be searched for and not built.
In this case the user has to specify the CMake variable QT_HOST_PATH
pointing to an installed host Qt location.
When not cross compiling, tools added by add_qt_tool are built from
source.
When building leaf modules (like qtsvg) that require some tool that was
built in qtbase (like moc), the module project should contain a
find_package(Qt5ToolsCore) call and specify an appropriate
CMAKE_PREFIX_PATH so that the tool package is found.
Note that because HOST_QT_TOOLS_DIRECTORY was replaced by QT_HOST_PATH,
the ensure syncqt code was changed to make it work properly with
both qtbase and qtsvg.
Here's a list of tools and their module associations:
qmake, moc, rcc, tracegen, qfloat16-tables, qlalr -> CoreTools
qvkgen -> GuiTools
uic -> WidgetTools
dbus related tools -> DBusTools
Task-number: QTBUG-74134
Change-Id: Ie67d1e2f8de46102b48eca008f0b50caf4fbe3ed
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-10 17:21:22 +00:00
if ( NOT arg_NO_INSTALL AND arg_TOOLS_TARGET )
# Assign a tool to an export set, and mark the module to which the tool belongs.
qt_internal_append_known_modules_with_tools ( "${arg_TOOLS_TARGET}" )
# Also append the tool to the module list.
qt_internal_append_known_module_tool ( "${arg_TOOLS_TARGET}" "${name}" )
install ( TARGETS "${name}"
E X P O R T " Q t $ { P R O J E C T _ V E R S I O N _ M A J O R } $ { a r g _ T O O L S _ T A R G E T } T o o l s T a r g e t s "
D E S T I N A T I O N $ { I N S T A L L _ T A R G E T S _ D E F A U L T _ A R G S } )
2019-04-03 09:33:28 +00:00
endif ( )
2018-10-24 13:20:27 +00:00
endfunction ( )
function ( qt_create_tracepoints name tracePointsFile )
#### TODO
string ( TOLOWER "${name}" name )
file ( GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qt${name}_tracepoints_p.h" CONTENT
" #include <private/qtrace_p.h>")
endfunction ( )
function ( add_qt_resource target resourceName )
2019-03-07 09:05:10 +00:00
qt_parse_all_arguments ( rcc "add_qt_resource" "" "PREFIX;LANG;BASE" "FILES" ${ ARGN } )
2018-10-24 13:20:27 +00:00
2019-03-07 09:05:10 +00:00
# Generate .qrc file:
# <RCC><qresource ...>
set ( qrcContents "<RCC>\n <qresource" )
if ( rcc_PREFIX )
string ( APPEND qrcContents " prefix=\" ${ rcc_PREFIX } \"")
2018-10-24 13:20:27 +00:00
endif ( )
2019-03-07 09:05:10 +00:00
if ( rcc_LANG )
string ( APPEND qrcContents " lang=\" ${ rcc_LANG } \"")
endif ( )
string ( APPEND qrcContents ">\n" )
2018-10-24 13:20:27 +00:00
foreach ( file ${ rcc_FILES } )
2019-03-07 09:05:10 +00:00
if ( rcc_BASE )
set ( based_file "${rcc_BASE}/${file}" )
else ( )
set ( based_file "${file}" )
endif ( )
get_property ( alias SOURCE ${ based_file } PROPERTY alias )
2018-10-24 13:20:27 +00:00
if ( NOT alias )
set ( alias "${file}" )
endif ( )
### FIXME: escape file paths to be XML conform
2019-03-07 09:05:10 +00:00
# <file ...>...</file>
string ( APPEND qrcContents " <file alias=\" ${ alias } \">")
string ( APPEND qrcContents "${CMAKE_CURRENT_SOURCE_DIR}/${based_file}</file>\n" )
2018-10-24 13:20:27 +00:00
endforeach ( )
2019-03-07 09:05:10 +00:00
# </qresource></RCC>
2018-10-24 13:20:27 +00:00
string ( APPEND qrcContents " </qresource>\n</RCC>\n" )
2019-03-07 09:05:10 +00:00
2018-10-24 13:20:27 +00:00
set ( generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/${resourceName}.qrc" )
file ( GENERATE OUTPUT "${generatedResourceFile}" CONTENT "${qrcContents}" )
2019-03-07 09:05:10 +00:00
# Process .qrc file:
2018-10-24 13:20:27 +00:00
set ( generatedSourceCode "${CMAKE_CURRENT_BINARY_DIR}/qrc_${resourceName}.cpp" )
add_custom_command ( OUTPUT "${generatedSourceCode}"
2019-02-12 09:02:15 +00:00
C O M M A N D " $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : r c c "
2018-10-24 13:20:27 +00:00
A R G S - - n a m e " $ { r e s o u r c e N a m e } "
- - o u t p u t " $ { g e n e r a t e d S o u r c e C o d e } " " $ { g e n e r a t e d R e s o u r c e F i l e } "
D E P E N D S $ { f i l e s }
C O M M E N T " R C C $ { r e s o u r c e N a m e } "
V E R B A T I M )
target_sources ( ${ target } PRIVATE "${generatedSourceCode}" )
endfunction ( )
2019-03-11 14:09:33 +00:00
# Handle files that need special SIMD-related flags.
# This creates an object library and makes target link
# to it (privately).
function ( add_qt_simd_part target )
qt_parse_all_arguments ( arg "add_qt_simd_part" "" ""
" N A M E ; S I M D ; $ { _ _ d e f a u l t _ p r i v a t e _ a r g s } ; C O M P I L E _ F L A G S " $ { A R G N } )
if ( "x${arg_SIMD}" STREQUAL x )
message ( FATAL_ERROR "add_qt_simd_part needs a SIMD type to be set." )
endif ( )
set ( condition "QT_FEATURE_${arg_SIMD}" )
if ( "${arg_SIMD}" STREQUAL arch_haswell )
set ( condition "TEST_subarch_avx2 AND TEST_subarch_bmi AND TEST_subarch_bmi2 AND TEST_subarch_f16c AND TEST_subarch_fma AND TEST_subarch_lzcnt AND TEST_subarch_popcnt" )
elseif ( "${arg_SIMD}" STREQUAL avx512common )
set ( condition "TEST_subarch_avx512cd" )
elseif ( "${arg_SIMD}" STREQUAL avx512core )
set ( condition "TEST_subarch_avx512cd AND TEST_subarch_avx512bw AND TEST_subarch_avx512dq AND TEST_subarch_avx512vl" )
endif ( )
set ( name "${arg_NAME}" )
if ( "x${name}" STREQUAL x )
set ( name "${target}_simd_${arg_SIMD}" )
endif ( )
qt_evaluate_config_expression ( result ${ condition } )
if ( ${ result } )
if ( QT_CMAKE_DEBUG_EXTEND_TARGET )
message ( "add_qt_simd_part(${target} SIMD ${arg_SIMD} ...): Evaluated" )
endif ( )
string ( TOUPPER "QT_CFLAGS_${arg_SIMD}" simd_flags )
add_library ( "${name}" OBJECT )
target_sources ( "${name}" PRIVATE ${ arg_SOURCES } )
target_include_directories ( "${name}" PRIVATE
$ { a r g _ I N C L U D E _ D I R E C T O R I E S }
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , I N C L U D E _ D I R E C T O R I E S > )
target_compile_options ( "${name}" PRIVATE
$ { $ { s i m d _ f l a g s } }
$ { a r g _ C O M P I L E _ F L A G S }
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , C O M P I L E _ O P T I O N S > )
target_compile_definitions ( "${name}" PRIVATE
$ < T A R G E T _ P R O P E R T Y : $ { t a r g e t } , C O M P I L E _ D E F I N I T I O N S > )
target_link_libraries ( "${target}" PRIVATE "${name}" )
2019-02-11 11:12:07 +00:00
if ( NOT BUILD_SHARED_LIBS )
install (
T A R G E T S $ { n a m e }
E X P O R T " $ { I N S T A L L _ C M A K E _ N A M E S P A C E } T a r g e t s "
)
endif ( )
2019-03-11 14:09:33 +00:00
else ( )
if ( QT_CMAKE_DEBUG_EXTEND_TARGET )
message ( "add_qt_simd_part(${target} SIMD ${arg_SIMD} ...): Skipped" )
endif ( )
endif ( )
endfunction ( )
2018-10-24 13:20:27 +00:00
# From Qt5CoreMacros
# Function used to create the names of output files preserving relative dirs
2018-11-08 21:29:27 +00:00
function ( qt_make_output_file infile prefix suffix source_dir binary_dir result )
get_filename_component ( outfilename "${infile}" NAME_WE )
set ( base_dir "${source_dir}" )
string ( FIND "${infile}" "${binary_dir}/" in_binary )
if ( in_binary EQUAL 0 )
set ( base_dir "${binary_dir}" )
2018-10-24 13:20:27 +00:00
endif ( )
2018-11-08 21:29:27 +00:00
get_filename_component ( abs_infile "${infile}" ABSOLUTE BASE_DIR "${base_dir}" )
file ( RELATIVE_PATH rel_infile "${base_dir}" "${abs_infile}" )
string ( REPLACE "../" "__/" mapped_infile "${rel_infile}" )
get_filename_component ( abs_mapped_infile "${mapped_infile}" ABSOLUTE BASE_DIR "${binary_dir}" )
get_filename_component ( outpath "${abs_mapped_infile}" PATH )
2018-10-24 13:20:27 +00:00
file ( MAKE_DIRECTORY "${outpath}" )
2018-12-07 12:13:24 +00:00
set ( "${result}" "${outpath}/${prefix}${outfilename}${suffix}" PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2018-11-08 21:29:27 +00:00
2018-12-12 09:55:20 +00:00
# Complete manual moc invocation with full control.
# Use AUTOMOC whenever possible.
function ( qt_manual_moc result )
cmake_parse_arguments ( arg "" "" "FLAGS" ${ ARGN } )
set ( moc_files )
foreach ( infile ${ arg_UNPARSED_ARGUMENTS } )
qt_make_output_file ( "${infile}" "moc_" ".cpp"
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } " " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } " o u t f i l e )
list ( APPEND moc_files "${outfile}" )
2018-10-24 13:20:27 +00:00
2018-12-12 09:55:20 +00:00
set ( moc_parameters_file "${outfile}_parameters$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>" )
set ( moc_parameters ${ arg_FLAGS } -o "${outfile}" "${infile}" )
string ( REPLACE ";" "\n" moc_parameters "${moc_parameters}" )
2018-10-24 13:20:27 +00:00
2018-12-12 09:55:20 +00:00
file ( GENERATE OUTPUT "${moc_parameters_file}" CONTENT "${moc_parameters}\n" )
2018-10-24 13:20:27 +00:00
2018-12-12 09:55:20 +00:00
add_custom_command ( OUTPUT "${outfile}"
2019-02-12 09:02:15 +00:00
C O M M A N D $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : m o c " @ $ { m o c _ p a r a m e t e r s _ f i l e } "
D E P E N D S " $ { i n f i l e } " $ { m o c _ d e p e n d s } $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : m o c
2018-12-12 09:55:20 +00:00
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } " V E R B A T I M )
2018-10-24 13:20:27 +00:00
endforeach ( )
2018-12-12 09:55:20 +00:00
set ( "${result}" ${ moc_files } PARENT_SCOPE )
2018-10-24 13:20:27 +00:00
endfunction ( )
2018-10-29 15:53:51 +00:00
# helper to set up a qdbusxml2cpp rule
function ( qt_create_qdbusxml2cpp_command target infile )
2019-01-30 13:06:48 +00:00
qt_parse_all_arguments ( arg "qt_create_qdbusxml2cpp_command" "ADAPTOR;INTERFACE" "BASENAME" "FLAGS" ${ ARGN } )
2018-12-07 12:13:24 +00:00
if ( ( arg_ADAPTOR AND arg_INTERFACE ) OR ( NOT arg_ADAPTOR AND NOT arg_INTERFACE ) )
2018-10-29 15:53:51 +00:00
message ( FATAL_ERROR "qt_create_dbusxml2cpp_command needs either ADAPTOR or INTERFACE." )
endif ( )
2018-12-07 12:13:24 +00:00
set ( option "-a" )
set ( type "adaptor" )
if ( arg_INTERFACE )
set ( option "-p" )
set ( type "interface" )
2018-10-29 15:53:51 +00:00
endif ( )
2019-01-30 13:06:48 +00:00
if ( "${arg_BASENAME}" STREQUAL "" )
2019-03-18 18:10:28 +00:00
get_filename_component ( file_dir "${infile}" DIRECTORY )
get_filename_component ( file_name "${infile}" NAME_WLE )
get_filename_component ( file_ext "${infile}" LAST_EXT )
if ( "${file_ext}" STREQUAL ".xml" )
else ( )
message ( FATAL_ERROR "DBUS ${type} input file is not xml." )
endif ( )
# use last part of io.qt.something.xml!
get_filename_component ( file_ext "${file_name}" LAST_EXT )
if ( "x${file_ext}" STREQUAL "x" )
else ( )
string ( SUBSTRING "${file_ext}" 1 -1 file_name ) # cut of leading '.'
endif ( )
2019-01-30 13:06:48 +00:00
string ( TOLOWER "${file_name}" file_name )
set ( file_name "${file_name}_${type}" )
else ( )
set ( file_name ${ arg_BASENAME } )
endif ( )
2019-04-16 10:53:24 +00:00
# Use absolute file path for the source file and set the current working directory to the
# current binary directory, because setting an absolute path for the header:source combo option
# does not work. Splitting on ":" breaks inside the dbus tool when running on Windows
# due to ":" being contained in the drive path (e.g C:\foo.h:C:\foo.cpp).
get_filename_component ( absolute_in_file_path "${infile}" ABSOLUTE )
2018-10-29 15:53:51 +00:00
2019-04-16 10:53:24 +00:00
set ( header_file "${file_name}.h" )
set ( source_file "${file_name}.cpp" )
2018-10-29 15:53:51 +00:00
add_custom_command ( OUTPUT "${header_file}" "${source_file}"
2019-04-16 10:53:24 +00:00
C O M M A N D $ { Q T _ C M A K E _ E X P O R T _ N A M E S P A C E } : : q d b u s x m l 2 c p p $ { a r g _ F L A G S } " $ { o p t i o n } "
" $ { h e a d e r _ f i l e } : $ { s o u r c e _ f i l e } " " $ { a b s o l u t e _ i n _ f i l e _ p a t h } "
D E P E N D S " $ { a b s o l u t e _ i n _ f i l e _ p a t h } "
W O R K I N G _ D I R E C T O R Y " $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
2018-10-29 15:53:51 +00:00
V E R B A T I M )
2018-12-12 09:55:20 +00:00
target_sources ( "${target}" PRIVATE "${header_file}" "${source_file}" )
2018-10-29 15:53:51 +00:00
endfunction ( )
2018-12-07 13:04:42 +00:00
function ( qt_generate_forwarding_headers target )
2018-12-07 12:13:24 +00:00
qt_parse_all_arguments ( arg "qt_generate_forwarding_headers"
2018-10-24 13:20:27 +00:00
" P R I V A T E " " S O U R C E ; D E S T I N A T I O N " " C L A S S E S " $ { A R G N } )
2018-12-07 13:04:42 +00:00
qt_internal_module_info ( module "${target}" )
2018-10-24 13:20:27 +00:00
2018-12-07 12:13:24 +00:00
if ( NOT arg_DESTINATION )
get_filename_component ( arg_DESTINATION "${arg_SOURCE}" NAME )
2018-10-24 13:20:27 +00:00
endif ( )
2018-12-07 12:13:24 +00:00
if ( arg_PRIVATE )
2018-12-07 13:04:42 +00:00
set ( main_fwd "${module_include_dir}/${PROJECT_VERSION}/${module}/private/${arg_DESTINATION}" )
2018-10-24 13:20:27 +00:00
else ( )
2018-12-07 13:04:42 +00:00
set ( main_fwd "${module_include_dir}/${arg_DESTINATION}" )
2018-10-24 13:20:27 +00:00
endif ( )
get_filename_component ( main_fwd_dir "${main_fwd}" DIRECTORY )
2018-12-07 12:13:24 +00:00
file ( RELATIVE_PATH relpath "${main_fwd_dir}" "${CMAKE_CURRENT_BINARY_DIR}/${arg_SOURCE}" )
2018-10-24 13:20:27 +00:00
set ( main_contents "#include \" ${ relpath } \"")
file ( GENERATE OUTPUT "${main_fwd}" CONTENT "${main_contents}" )
2018-12-07 12:13:24 +00:00
foreach ( class_fwd ${ arg_CLASSES } )
2018-10-24 13:20:27 +00:00
set ( class_fwd_contents "#include \" ${ fwd_hdr } \"")
message ( "Generating forwarding header: ${class_fwd} -> ${relpath}." )
2018-12-07 13:04:42 +00:00
file ( GENERATE OUTPUT "${module_include_dir}/${class_fwd}" CONTENT "${class_fwd_contents}" )
2018-10-24 13:20:27 +00:00
endforeach ( )
endfunction ( )
function ( add_qt_docs qdocFile )
# TODO
endfunction ( )
Write find_dependency() calls in Qt Module config files
This change introduces a new function called qt_find_package()
which can take an extra option called PROVIDED_TARGETS, which
associates targets with the package that defines those targets.
This is done by setting the INTERFACE_QT_PACKAGE_NAME and
INTERFACE_QT_PACKAGE_VERSION properties on the imported targets.
This information allows us to generate appropriate find_dependency()
calls in a module's Config file for third party libraries.
For example when an application links against QtCore, it should also
link against zlib and atomic libraries. In order to do that, the
library locations first have to be found by CMake. This is achieved by
embedding find_dependency(ZLIB) and find_dependency(Atomic) in
Qt5CoreDependencies.cmake which is included by Qt5CoreConfig.cmake.
The latter is picked up when an application project contains
find_package(Qt5Core), and thus all linking dependencies are resolved.
The information 'which package provides which targets' is contained
in the python json2cmake conversion script. The generated output of
the script contains qt_find_package() calls that represent that
information.
The Qt5CoreDependencies.cmake file and which which dependencies it
contains is generated at the QtPostProcess stop.
Note that for non-static Qt builds, we only need to propagate public
3rd party libraries. For static builds, we need all third party
libraries.
In order for the INTERFACE_QT_PACKAGE_NAME property to be read in any
scope, the targets on which the property is set, have to be GLOBAL.
Also for applications and other modules to find all required third
party libraries, we have to install all our custom Find modules, and
make sure they define INTERFACE IMPORTED libraries, and not just
IMPORTED libraries.
Change-Id: I694d6e32d05b96d5e241df0156fc79d0029426aa
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-24 15:14:25 +00:00
macro ( qt_find_package )
# Get the target names we expect to be provided by the package.
cmake_parse_arguments ( arg "" "" "PROVIDED_TARGETS;COMPONENTS" ${ ARGN } )
# Get the version if specified.
set ( package_version "" )
if ( ${ ARGC } GREATER_EQUAL 2 )
if ( ${ ARGV1 } MATCHES "^[0-9\.]+$" )
set ( package_version "${ARGV1}" )
endif ( )
endif ( )
if ( arg_COMPONENTS )
# Re-append components to forward them.
list ( APPEND arg_UNPARSED_ARGUMENTS "COMPONENTS;${arg_COMPONENTS}" )
endif ( )
# Call original function without our custom arguments.
find_package ( ${ arg_UNPARSED_ARGUMENTS } )
if ( ${ ARGV0 } _FOUND AND arg_PROVIDED_TARGETS )
# If package was found, associate each target with its package name. This will be used
# later when creating Config files for Qt libraries, to generate correct find_dependency()
# calls. Also make the provided targets global, so that the properties can be read in
# all scopes.
foreach ( qt_find_package_target_name ${ arg_PROVIDED_TARGETS } )
if ( TARGET ${ qt_find_package_target_name } )
set_target_properties ( ${ qt_find_package_target_name }
P R O P E R T I E S I N T E R F A C E _ Q T _ P A C K A G E _ N A M E $ { A R G V 0 } )
if ( package_version )
set_target_properties ( ${ qt_find_package_target_name }
P R O P E R T I E S I N T E R F A C E _ Q T _ P A C K A G E _ V E R S I O N $ { A R G V 1 } )
endif ( )
if ( arg_COMPONENTS )
set_target_properties ( ${ qt_find_package_target_name }
P R O P E R T I E S
I N T E R F A C E _ Q T _ P A C K A G E _ C O M P O N E N T S $ { a r g _ C O M P O N E N T S } )
endif ( )
get_property ( is_global TARGET ${ qt_find_package_target_name } PROPERTY
I M P O R T E D _ G L O B A L )
if ( NOT is_global )
set_property ( TARGET ${ qt_find_package_target_name } PROPERTY
I M P O R T E D _ G L O B A L T R U E )
endif ( )
else ( )
2019-05-03 07:31:19 +00:00
message ( AUTHOR_WARNING
Write find_dependency() calls in Qt Module config files
This change introduces a new function called qt_find_package()
which can take an extra option called PROVIDED_TARGETS, which
associates targets with the package that defines those targets.
This is done by setting the INTERFACE_QT_PACKAGE_NAME and
INTERFACE_QT_PACKAGE_VERSION properties on the imported targets.
This information allows us to generate appropriate find_dependency()
calls in a module's Config file for third party libraries.
For example when an application links against QtCore, it should also
link against zlib and atomic libraries. In order to do that, the
library locations first have to be found by CMake. This is achieved by
embedding find_dependency(ZLIB) and find_dependency(Atomic) in
Qt5CoreDependencies.cmake which is included by Qt5CoreConfig.cmake.
The latter is picked up when an application project contains
find_package(Qt5Core), and thus all linking dependencies are resolved.
The information 'which package provides which targets' is contained
in the python json2cmake conversion script. The generated output of
the script contains qt_find_package() calls that represent that
information.
The Qt5CoreDependencies.cmake file and which which dependencies it
contains is generated at the QtPostProcess stop.
Note that for non-static Qt builds, we only need to propagate public
3rd party libraries. For static builds, we need all third party
libraries.
In order for the INTERFACE_QT_PACKAGE_NAME property to be read in any
scope, the targets on which the property is set, have to be GLOBAL.
Also for applications and other modules to find all required third
party libraries, we have to install all our custom Find modules, and
make sure they define INTERFACE IMPORTED libraries, and not just
IMPORTED libraries.
Change-Id: I694d6e32d05b96d5e241df0156fc79d0029426aa
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2019-04-24 15:14:25 +00:00
" E r r o r w h i l e t r y i n g t o m a r k t a r g e t ' $ { q t _ f i n d _ p a c k a g e _ t a r g e t _ n a m e } ' a s p a r t "
" o f t h e $ { A R G V 0 } p a c k a g e . P r o v i d e d t a r g e t n a m e d o e s n o t e x i s t . " )
endif ( )
endforeach ( )
endif ( )
endmacro ( )
2019-02-11 11:12:07 +00:00
# Creates a simple export set for the various Find* dependencies
# which are needed when creating a static build of Qt.
# This introduces a custom target property: INTERFACE_QT_EXPORTED_LIBRARY
# This target property indicates that Qt modules / plugins using this 3rd party library
# must add it to their list of dependencies when creating their own ${qtmodule}Config.cmake
function ( qt_install_static_target_export target )
if ( BUILD_SHARED_LIBS )
return ( )
endif ( )
qt_parse_all_arguments ( arg "qt_install_3rdparty_config_files" "" "EXPORT" "" ${ ARGN } )
# TODO mark EXPORT as required
set ( config_install_dir "${INSTALL_LIBDIR}/cmake/${arg_EXPORT}" )
set_target_properties ( ${ target }
P R O P E R T I E S
I N T E R F A C E _ Q T _ E X P O R T E D _ L I B R A R Y 1 )
install (
T A R G E T S $ { t a r g e t }
E X P O R T $ { a r g _ E X P O R T } T a r g e t s
L I B R A R Y D E S T I N A T I O N $ { I N S T A L L _ L I B D I R }
A R C H I V E D E S T I N A T I O N $ { I N S T A L L _ L I B D I R } )
install (
E X P O R T $ { a r g _ E X P O R T } T a r g e t s
D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
)
export ( EXPORT ${ arg_EXPORT } Targets )
endfunction ( )
# Create a set of ${target}Config.cmake and ${target}Version.cmake for a
# third-party library so that it can be found by client code linking statically.
function ( qt_install_3rdparty_config_files target )
if ( BUILD_SHARED_LIBS )
return ( )
endif ( )
qt_parse_all_arguments ( arg "qt_install_3rdparty_config_files" "" "EXPORT" "PACKAGES;ADDITIONAL_FILES" ${ ARGN } )
# TODO mark EXPORT as required
set ( 3RDPARTY_ADDITIONAL_SETUP_CODE )
foreach ( package ${ arg_PACKAGES } )
list ( APPEND 3RDPARTY_ADDITIONAL_SETUP_CODE "find_package(${package})\n" )
endforeach ( )
set ( config_install_dir "${INSTALL_LIBDIR}/cmake/${arg_EXPORT}" )
configure_package_config_file (
" $ { P R O J E C T _ S O U R C E _ D I R } / c m a k e / 3 r d p a r t y C o n f i g . c m a k e . i n "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { t a r g e t } C o n f i g . c m a k e "
I N S T A L L _ D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
)
write_basic_package_version_file (
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { t a r g e t } C o n f i g V e r s i o n . c m a k e "
V E R S I O N $ { P R O J E C T _ V E R S I O N }
C O M P A T I B I L I T Y A n y N e w e r V e r s i o n
)
install ( FILES
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { t a r g e t } C o n f i g . c m a k e "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { t a r g e t } C o n f i g V e r s i o n . c m a k e "
$ { a r g _ A D D I T I O N A L _ F I L E S }
D E S T I N A T I O N " $ { c o n f i g _ i n s t a l l _ d i r } "
C O M P O N E N T D e v e l
)
endfunction ( )
# Call this function in 3rdparty find modules that ought to be installed alongside
# Qt modules and must be found when linking statically.
function ( qt_install_3rdparty_library target )
qt_install_static_target_export ( ${ target } EXPORT ${ target } )
qt_install_3rdparty_config_files ( ${ target } EXPORT ${ target } ${ ARGN } )
endfunction ( )