2011-11-01 13:59:23 +00:00
#=============================================================================
# Copyright 2005-2011 Kitware, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Kitware, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
2015-02-13 11:15:33 +00:00
# from this software without specific prior written permission.
2011-11-01 13:59:23 +00:00
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
######################################
#
# Macros for building Qt files
#
######################################
2011-12-05 01:06:21 +00:00
include ( CMakeParseArguments )
2011-11-01 13:59:23 +00:00
2020-10-30 15:46:40 +00:00
set ( __qt_core_macros_module_base_dir "${CMAKE_CURRENT_LIST_DIR}" )
2011-11-01 13:59:23 +00:00
# macro used to create the names of output files preserving relative dirs
2020-10-14 11:20:55 +00:00
macro ( _qt_internal_make_output_file infile prefix ext outfile )
2011-12-19 21:17:02 +00:00
string ( LENGTH ${ CMAKE_CURRENT_BINARY_DIR } _binlength )
string ( LENGTH ${ infile } _infileLength )
set ( _checkinfile ${ CMAKE_CURRENT_SOURCE_DIR } )
if ( _infileLength GREATER _binlength )
string ( SUBSTRING "${infile}" 0 ${ _binlength } _checkinfile )
if ( _checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}" )
file ( RELATIVE_PATH rel ${ CMAKE_CURRENT_BINARY_DIR } ${ infile } )
else ( )
file ( RELATIVE_PATH rel ${ CMAKE_CURRENT_SOURCE_DIR } ${ infile } )
endif ( )
else ( )
file ( RELATIVE_PATH rel ${ CMAKE_CURRENT_SOURCE_DIR } ${ infile } )
endif ( )
2015-12-21 16:56:55 +00:00
if ( WIN32 AND rel MATCHES "^([a-zA-Z]):(.*)$" ) # absolute path
set ( rel "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}" )
2011-12-19 21:17:02 +00:00
endif ( )
set ( _outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}" )
string ( REPLACE ".." "__" _outfile ${ _outfile } )
get_filename_component ( outpath ${ _outfile } PATH )
2020-02-13 08:14:09 +00:00
if ( CMAKE_VERSION VERSION_LESS "3.14" )
get_filename_component ( _outfile_ext ${ _outfile } EXT )
get_filename_component ( _outfile_ext ${ _outfile_ext } NAME_WE )
get_filename_component ( _outfile ${ _outfile } NAME_WE )
string ( APPEND _outfile ${ _outfile_ext } )
else ( )
get_filename_component ( _outfile ${ _outfile } NAME_WLE )
endif ( )
2011-12-19 21:17:02 +00:00
file ( MAKE_DIRECTORY ${ outpath } )
set ( ${ outfile } ${ outpath } / ${ prefix } ${ _outfile } . ${ ext } )
endmacro ( )
2020-10-14 11:20:55 +00:00
macro ( _qt_internal_get_moc_flags _moc_flags )
2011-12-19 21:17:02 +00:00
set ( ${ _moc_flags } )
get_directory_property ( _inc_DIRS INCLUDE_DIRECTORIES )
2012-10-02 10:04:00 +00:00
if ( CMAKE_INCLUDE_CURRENT_DIR )
list ( APPEND _inc_DIRS ${ CMAKE_CURRENT_SOURCE_DIR } ${ CMAKE_CURRENT_BINARY_DIR } )
endif ( )
2011-12-19 21:17:02 +00:00
foreach ( _current ${ _inc_DIRS } )
if ( "${_current}" MATCHES "\\.framework/?$" )
string ( REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}" )
set ( ${ _moc_flags } ${ ${_moc_flags } } "-F${framework_path}" )
else ( )
set ( ${ _moc_flags } ${ ${_moc_flags } } "-I${_current}" )
endif ( )
endforeach ( )
get_directory_property ( _defines COMPILE_DEFINITIONS )
foreach ( _current ${ _defines } )
set ( ${ _moc_flags } ${ ${_moc_flags } } "-D${_current}" )
endforeach ( )
2012-02-23 00:05:46 +00:00
if ( WIN32 )
2011-12-19 21:17:02 +00:00
set ( ${ _moc_flags } ${ ${_moc_flags } } -DWIN32 )
endif ( )
2016-04-14 00:25:37 +00:00
if ( MSVC )
2017-02-01 19:05:35 +00:00
set ( ${ _moc_flags } ${ ${_moc_flags } } --compiler-flavor=msvc )
2016-04-14 00:25:37 +00:00
endif ( )
2011-12-19 21:17:02 +00:00
endmacro ( )
2011-11-01 13:59:23 +00:00
# helper macro to set up a moc rule
2020-10-14 11:20:55 +00:00
function ( _qt_internal_create_moc_command infile outfile moc_flags moc_options moc_target moc_depends )
2013-06-19 15:56:04 +00:00
# Pass the parameters in a file. Set the working directory to
# be that containing the parameters file and reference it by
# just the file name. This is necessary because the moc tool on
# MinGW builds does not seem to handle spaces in the path to the
# file given with the @ syntax.
get_filename_component ( _moc_outfile_name "${outfile}" NAME )
get_filename_component ( _moc_outfile_dir "${outfile}" PATH )
if ( _moc_outfile_dir )
set ( _moc_working_dir WORKING_DIRECTORY ${ _moc_outfile_dir } )
endif ( )
set ( _moc_parameters_file ${ outfile } _parameters )
set ( _moc_parameters ${ moc_flags } ${ moc_options } -o "${outfile}" "${infile}" )
string ( REPLACE ";" "\n" _moc_parameters "${_moc_parameters}" )
if ( moc_target )
2013-12-13 14:17:03 +00:00
set ( _moc_parameters_file ${ _moc_parameters_file } $< $<BOOL:$<CONFIGURATION > >:_ $< CONFIGURATION > > )
2013-06-19 15:56:04 +00:00
set ( targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>" )
set ( targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>" )
set ( targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},\n-I>\n>" )
set ( targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},\n-D>\n>" )
file ( GENERATE
O U T P U T $ { _ m o c _ p a r a m e t e r s _ f i l e }
C O N T E N T " $ { t a r g e t d e f i n e s } $ { t a r g e t i n c l u d e s } $ { _ m o c _ p a r a m e t e r s } \ n "
)
set ( targetincludes )
set ( targetdefines )
2011-12-19 21:17:02 +00:00
else ( )
2013-06-19 15:56:04 +00:00
file ( WRITE ${ _moc_parameters_file } "${_moc_parameters}\n" )
2011-12-19 21:17:02 +00:00
endif ( )
2013-06-19 15:56:04 +00:00
set ( _moc_extra_parameters_file @ ${ _moc_parameters_file } )
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 _ e x t r a _ p a r a m e t e r s _ f i l e }
2015-01-19 06:18:39 +00:00
D E P E N D S $ { i n f i l e } $ { m o c _ d e p e n d s }
2013-06-19 15:56:04 +00:00
$ { _ m o c _ w o r k i n g _ d i r }
V E R B A T I M )
2017-09-29 20:17:10 +00:00
set_source_files_properties ( ${ infile } PROPERTIES SKIP_AUTOMOC ON )
set_source_files_properties ( ${ outfile } PROPERTIES SKIP_AUTOMOC ON )
set_source_files_properties ( ${ outfile } PROPERTIES SKIP_AUTOUIC ON )
2015-12-21 16:56:55 +00:00
endfunction ( )
2011-12-19 21:17:02 +00:00
2019-09-19 06:45:21 +00:00
function ( qt6_generate_moc infile outfile )
2011-12-19 21:17:02 +00:00
# get include dirs and flags
2020-10-14 11:20:55 +00:00
_qt_internal_get_moc_flags ( moc_flags )
2011-12-19 21:17:02 +00:00
get_filename_component ( abs_infile ${ infile } ABSOLUTE )
set ( _outfile "${outfile}" )
if ( NOT IS_ABSOLUTE "${outfile}" )
set ( _outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}" )
endif ( )
2013-06-19 15:56:04 +00:00
if ( "x${ARGV2}" STREQUAL "xTARGET" )
set ( moc_target ${ ARGV3 } )
endif ( )
2020-10-14 11:20:55 +00:00
_qt_internal_create_moc_command ( ${ abs_infile } ${ _outfile } "${moc_flags}" "" "${moc_target}" "" )
2011-12-19 21:30:50 +00:00
endfunction ( )
2011-12-19 21:17:02 +00:00
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_generate_moc )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_generate_moc ( ${ ARGV } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_generate_moc ( ${ ARGV } )
endif ( )
endfunction ( )
endif ( )
2011-12-19 21:17:02 +00:00
2019-08-23 09:39:30 +00:00
# qt6_wrap_cpp(outfiles inputfile ... )
2011-12-19 21:17:02 +00:00
2019-09-19 06:45:21 +00:00
function ( qt6_wrap_cpp outfiles )
2011-12-19 21:17:02 +00:00
# get include dirs
2020-10-14 11:20:55 +00:00
_qt_internal_get_moc_flags ( moc_flags )
2011-12-19 21:17:02 +00:00
set ( options )
2013-06-19 15:56:04 +00:00
set ( oneValueArgs TARGET )
2015-01-19 06:18:39 +00:00
set ( multiValueArgs OPTIONS DEPENDS )
2011-12-19 21:17:02 +00:00
cmake_parse_arguments ( _WRAP_CPP "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
set ( moc_files ${ _WRAP_CPP_UNPARSED_ARGUMENTS } )
set ( moc_options ${ _WRAP_CPP_OPTIONS } )
2013-06-19 15:56:04 +00:00
set ( moc_target ${ _WRAP_CPP_TARGET } )
2015-01-19 06:18:39 +00:00
set ( moc_depends ${ _WRAP_CPP_DEPENDS } )
2013-06-19 15:56:04 +00:00
2011-12-19 21:17:02 +00:00
foreach ( it ${ moc_files } )
get_filename_component ( it ${ it } ABSOLUTE )
2020-10-14 11:20:55 +00:00
_qt_internal_make_output_file ( ${ it } moc_ cpp outfile )
_qt_internal_create_moc_command (
$ { i t } $ { o u t f i l e } " $ { m o c _ f l a g s } " " $ { m o c _ o p t i o n s } " " $ { m o c _ t a r g e t } " " $ { m o c _ d e p e n d s } " )
2011-12-19 21:27:48 +00:00
list ( APPEND ${ outfiles } ${ outfile } )
2011-12-19 21:17:02 +00:00
endforeach ( )
2011-12-19 21:30:50 +00:00
set ( ${ outfiles } ${ ${outfiles } } PARENT_SCOPE )
endfunction ( )
2011-12-19 21:17:02 +00:00
2019-12-05 12:52:33 +00:00
# This will override the CMake upstream command, because that one is for Qt 3.
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_wrap_cpp outfiles )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_wrap_cpp ( "${outfiles}" ${ ARGN } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_wrap_cpp ( "${outfiles}" ${ ARGN } )
endif ( )
set ( "${outfiles}" "${${outfiles}}" PARENT_SCOPE )
endfunction ( )
endif ( )
2011-12-19 21:17:02 +00:00
2014-11-13 10:01:31 +00:00
2019-08-23 09:39:30 +00:00
# _qt6_parse_qrc_file(infile _out_depends _rc_depends)
2014-11-13 10:01:31 +00:00
# internal
2019-09-19 06:45:21 +00:00
function ( _qt6_parse_qrc_file infile _out_depends _rc_depends )
2014-11-13 10:01:31 +00:00
get_filename_component ( rc_path ${ infile } PATH )
if ( EXISTS "${infile}" )
# parse file for dependencies
# all files are absolute paths or relative to the location of the qrc file
file ( READ "${infile}" RC_FILE_CONTENTS )
string ( REGEX MATCHALL "<file[^<]+" RC_FILES "${RC_FILE_CONTENTS}" )
foreach ( RC_FILE ${ RC_FILES } )
string ( REGEX REPLACE "^<file[^>]*>" "" RC_FILE "${RC_FILE}" )
if ( NOT IS_ABSOLUTE "${RC_FILE}" )
set ( RC_FILE "${rc_path}/${RC_FILE}" )
endif ( )
set ( RC_DEPENDS ${ RC_DEPENDS } "${RC_FILE}" )
endforeach ( )
# Since this cmake macro is doing the dependency scanning for these files,
# let's make a configured file and add it as a dependency so cmake is run
# again when dependencies need to be recomputed.
2020-10-14 11:20:55 +00:00
_qt_internal_make_output_file ( "${infile}" "" "qrc.depends" out_depends )
2014-11-13 10:01:31 +00:00
configure_file ( "${infile}" "${out_depends}" COPYONLY )
else ( )
# The .qrc file does not exist (yet). Let's add a dependency and hope
# that it will be generated later
set ( out_depends )
endif ( )
set ( ${ _out_depends } ${ out_depends } PARENT_SCOPE )
set ( ${ _rc_depends } ${ RC_DEPENDS } PARENT_SCOPE )
endfunction ( )
2019-08-23 09:39:30 +00:00
# qt6_add_binary_resources(target inputfiles ... )
2014-11-13 10:01:31 +00:00
2019-09-19 06:45:21 +00:00
function ( qt6_add_binary_resources target )
2014-11-13 10:01:31 +00:00
set ( options )
set ( oneValueArgs DESTINATION )
set ( multiValueArgs OPTIONS )
cmake_parse_arguments ( _RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
set ( rcc_files ${ _RCC_UNPARSED_ARGUMENTS } )
set ( rcc_options ${ _RCC_OPTIONS } )
set ( rcc_destination ${ _RCC_DESTINATION } )
if ( NOT rcc_destination )
set ( rcc_destination ${ CMAKE_CURRENT_BINARY_DIR } / ${ target } .rcc )
endif ( )
foreach ( it ${ rcc_files } )
get_filename_component ( infile ${ it } ABSOLUTE )
2019-09-19 06:45:21 +00:00
_qt6_parse_qrc_file ( ${ infile } _out_depends _rc_depends )
2017-09-29 20:17:10 +00:00
set_source_files_properties ( ${ infile } PROPERTIES SKIP_AUTORCC ON )
2014-11-13 10:01:31 +00:00
set ( infiles ${ infiles } ${ infile } )
set ( out_depends ${ out_depends } ${ _out_depends } )
set ( rc_depends ${ rc_depends } ${ _rc_depends } )
endforeach ( )
add_custom_command ( OUTPUT ${ rcc_destination }
2020-01-31 13:44:52 +00:00
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 } : : r c c
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
2014-11-13 10:01:31 +00:00
A R G S $ { r c c _ o p t i o n s } - - b i n a r y - - n a m e $ { t a r g e t } - - o u t p u t $ { r c c _ d e s t i n a t i o n } $ { i n f i l e s }
2020-01-31 13:44:52 +00:00
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 } : : r c c
$ { r c _ d e p e n d s }
$ { o u t _ d e p e n d s }
$ { i n f i l e s }
V E R B A T I M )
2014-11-13 10:01:31 +00:00
add_custom_target ( ${ target } ALL DEPENDS ${ rcc_destination } )
endfunction ( )
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_binary_resources )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_add_binary_resources ( ${ ARGV } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_add_binary_resources ( ${ ARGV } )
endif ( )
endfunction ( )
endif ( )
2014-11-13 10:01:31 +00:00
2019-08-23 09:39:30 +00:00
# qt6_add_resources(target resourcename ...
2019-08-19 14:19:08 +00:00
# or
2019-08-23 09:39:30 +00:00
# qt6_add_resources(outfiles inputfile ... )
2011-12-19 21:17:02 +00:00
2019-09-19 06:45:21 +00:00
function ( qt6_add_resources outfiles )
2019-08-19 14:19:08 +00:00
if ( TARGET ${ outfiles } )
2019-09-16 07:49:40 +00:00
cmake_parse_arguments ( arg "" "OUTPUT_TARGETS" "" ${ ARGN } )
2020-10-01 08:58:02 +00:00
_qt_internal_process_resource ( ${ ARGV } )
2019-09-16 07:49:40 +00:00
if ( arg_OUTPUT_TARGETS )
set ( ${ arg_OUTPUT_TARGETS } ${ ${arg_OUTPUT_TARGETS } } PARENT_SCOPE )
endif ( )
2019-08-19 14:19:08 +00:00
else ( )
set ( options )
set ( oneValueArgs )
set ( multiValueArgs OPTIONS )
2011-12-19 21:17:02 +00:00
2019-08-19 14:19:08 +00:00
cmake_parse_arguments ( _RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
2011-12-19 21:17:02 +00:00
2019-08-19 14:19:08 +00:00
set ( rcc_files ${ _RCC_UNPARSED_ARGUMENTS } )
set ( rcc_options ${ _RCC_OPTIONS } )
2011-12-19 21:17:02 +00:00
2019-08-19 14:19:08 +00:00
if ( "${rcc_options}" MATCHES "-binary" )
2019-08-23 09:39:30 +00:00
message ( WARNING "Use qt6_add_binary_resources for binary option" )
2019-08-19 14:19:08 +00:00
endif ( )
2011-12-19 21:17:02 +00:00
2019-08-19 14:19:08 +00:00
foreach ( it ${ rcc_files } )
get_filename_component ( outfilename ${ it } NAME_WE )
get_filename_component ( infile ${ it } ABSOLUTE )
set ( outfile ${ CMAKE_CURRENT_BINARY_DIR } /qrc_ ${ outfilename } .cpp )
2019-09-19 06:45:21 +00:00
_qt6_parse_qrc_file ( ${ infile } _out_depends _rc_depends )
2019-08-19 14:19:08 +00:00
set_source_files_properties ( ${ infile } PROPERTIES SKIP_AUTORCC ON )
add_custom_command ( OUTPUT ${ outfile }
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
A R G S $ { r c c _ o p t i o n s } - - n a m e $ { o u t f i l e n a m e } - - o u t p u t $ { o u t f i l e } $ { i n f i l e }
M A I N _ D E P E N D E N C Y $ { i n f i l e }
2020-01-31 13:44:52 +00:00
D E P E N D S $ { _ r c _ d e p e n d s } " $ { _ o u 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 } : : r c c
V E R B A T I M )
2019-08-19 14:19:08 +00:00
set_source_files_properties ( ${ outfile } PROPERTIES SKIP_AUTOMOC ON )
set_source_files_properties ( ${ outfile } PROPERTIES SKIP_AUTOUIC ON )
list ( APPEND ${ outfiles } ${ outfile } )
endforeach ( )
set ( ${ outfiles } ${ ${outfiles } } PARENT_SCOPE )
2014-11-13 10:01:31 +00:00
endif ( )
2011-12-19 21:30:50 +00:00
endfunction ( )
2012-05-05 21:40:19 +00:00
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_resources outfiles )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_add_resources ( "${outfiles}" ${ ARGN } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_add_resources ( "${outfiles}" ${ ARGN } )
endif ( )
if ( NOT TARGET ${ outfiles } )
set ( "${outfiles}" "${${outfiles}}" PARENT_SCOPE )
endif ( )
endfunction ( )
endif ( )
2019-08-23 09:39:30 +00:00
# qt6_add_big_resources(outfiles inputfile ... )
2018-05-18 10:19:38 +00:00
2019-09-19 06:45:21 +00:00
function ( qt6_add_big_resources outfiles )
2019-05-20 09:37:27 +00:00
if ( CMAKE_VERSION VERSION_LESS 3.9 )
2019-08-23 09:39:30 +00:00
message ( FATAL_ERROR, "qt6_add_big_resources requires CMake 3.9 or newer" )
2019-05-20 09:37:27 +00:00
endif ( )
2018-05-18 10:19:38 +00:00
set ( options )
set ( oneValueArgs )
set ( multiValueArgs OPTIONS )
cmake_parse_arguments ( _RCC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
set ( rcc_files ${ _RCC_UNPARSED_ARGUMENTS } )
set ( rcc_options ${ _RCC_OPTIONS } )
if ( "${rcc_options}" MATCHES "-binary" )
2019-08-23 09:39:30 +00:00
message ( WARNING "Use qt6_add_binary_resources for binary option" )
2018-05-18 10:19:38 +00:00
endif ( )
foreach ( it ${ rcc_files } )
get_filename_component ( outfilename ${ it } NAME_WE )
get_filename_component ( infile ${ it } ABSOLUTE )
set ( tmpoutfile ${ CMAKE_CURRENT_BINARY_DIR } /qrc_ ${ outfilename } tmp.cpp )
set ( outfile ${ CMAKE_CURRENT_BINARY_DIR } /qrc_ ${ outfilename } .o )
2019-09-19 06:45:21 +00:00
_qt6_parse_qrc_file ( ${ infile } _out_depends _rc_depends )
2021-05-20 11:22:28 +00:00
set_source_files_properties ( ${ infile } PROPERTIES SKIP_AUTOGEN ON )
2018-05-18 10:19:38 +00:00
add_custom_command ( OUTPUT ${ tmpoutfile }
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 $ { r c c _ o p t i o n s } - - n a m e $ { o u t f i l e n a m e } - - p a s s 1 - - o u t p u t $ { t m p o u t f i l e } $ { i n f i l e }
2020-01-31 13:44:52 +00:00
D E P E N D S $ { i n f i l e } $ { _ r c _ d e p e n d s } " $ { o u 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 } : : r c c
V E R B A T I M )
2018-05-18 10:19:38 +00:00
add_custom_target ( big_resources_ ${ outfilename } ALL DEPENDS ${ tmpoutfile } )
add_library ( rcc_object_ ${ outfilename } OBJECT ${ tmpoutfile } )
2021-01-18 10:49:52 +00:00
target_compile_definitions ( rcc_object_ ${ outfilename } PUBLIC "$<TARGET_PROPERTY:Qt6::Core,INTERFACE_COMPILE_DEFINITIONS>" )
2019-03-18 10:29:16 +00:00
set_target_properties ( rcc_object_ ${ outfilename } PROPERTIES AUTOMOC OFF )
set_target_properties ( rcc_object_ ${ outfilename } PROPERTIES AUTOUIC OFF )
2018-05-18 10:19:38 +00:00
add_dependencies ( rcc_object_ ${ outfilename } big_resources_ ${ outfilename } )
2019-05-20 09:37:27 +00:00
# The modification of TARGET_OBJECTS needs the following change in cmake
# https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f
2018-05-18 10:19:38 +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 } : : r c c
2018-05-18 10:19:38 +00:00
A R G S $ { r c c _ o p t i o n s } - - n a m e $ { o u t f i l e n a m e } - - p a s s 2 - - t e m p $ < T A R G E T _ O B J E C T S : r c c _ o b j e c t _ $ { o u t f i l e n a m e } > - - o u t p u t $ { o u t f i l e } $ { i n f i l e }
2020-07-06 17:31:28 +00:00
D E P E N D S r c c _ o b j e c t _ $ { o u t f i l e n a m e } $ < T A R G E T _ O B J E C T S : r c c _ o b j e c t _ $ { o u t f i l e n a m e } > $ { 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-05-18 10:19:38 +00:00
V E R B A T I M )
list ( APPEND ${ outfiles } ${ outfile } )
endforeach ( )
set ( ${ outfiles } ${ ${outfiles } } PARENT_SCOPE )
endfunction ( )
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_big_resources outfiles )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_add_big_resources ( ${ outfiles } ${ ARGN } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_add_big_resources ( ${ outfiles } ${ ARGN } )
endif ( )
set ( "${outfiles}" "${${outfiles}}" PARENT_SCOPE )
endfunction ( )
endif ( )
2021-03-23 04:48:56 +00:00
function ( _qt_internal_apply_win_prefix_and_suffix target )
if ( WIN32 )
# Table of prefix / suffixes for MSVC libraries as qmake expects them to be created.
# static - Qt6EdidSupport.lib (platform support libraries / or static QtCore, etc)
# shared - Qt6Core.dll
# shared import library - Qt6Core.lib
# module aka Qt plugin - qwindows.dll
# module import library - qwindows.lib
#
# The CMake defaults are fine for us.
# Table of prefix / suffixes for MinGW libraries as qmake expects them to be created.
# static - libQt6EdidSupport.a (platform support libraries / or static QtCore, etc)
# shared - Qt6Core.dll
# shared import library - libQt6Core.a
# module aka Qt plugin - qwindows.dll
# module import library - libqwindows.a
#
# CMake for Windows-GNU platforms defaults the prefix to "lib".
# CMake for Windows-GNU platforms defaults the import suffix to ".dll.a".
# These CMake defaults are not ok for us.
# This should cover both MINGW with GCC and CLANG.
if ( NOT MSVC )
set_property ( TARGET "${target}" PROPERTY IMPORT_SUFFIX ".a" )
get_target_property ( target_type ${ target } TYPE )
if ( target_type STREQUAL "STATIC_LIBRARY" )
set_property ( TARGET "${target}" PROPERTY PREFIX "lib" )
else ( )
set_property ( TARGET "${target}" PROPERTY PREFIX "" )
set_property ( TARGET "${target}" PROPERTY IMPORT_PREFIX "lib" )
endif ( )
endif ( )
endif ( )
endfunction ( )
2020-01-22 12:47:08 +00:00
set ( _Qt6_COMPONENT_PATH "${CMAKE_CURRENT_LIST_DIR}/.." )
2018-06-14 12:50:39 +00:00
2020-10-14 11:20:55 +00:00
# This function is currently in Technical Preview.
# It's signature and behavior might change.
#
# Wrapper function that adds an executable with some Qt specific behavior.
2020-12-08 11:00:22 +00:00
# Some scenarios require steps to be deferred to the end of the current
# directory scope so that the caller has an opportunity to modify certain
# target properties.
2020-10-15 15:58:15 +00:00
function ( qt6_add_executable target )
2020-12-08 11:00:22 +00:00
cmake_parse_arguments ( PARSE_ARGV 1 arg "MANUAL_FINALIZATION" "" "" )
_qt_internal_create_executable ( "${target}" ${ arg_UNPARSED_ARGUMENTS } )
if ( arg_MANUAL_FINALIZATION )
2021-05-18 17:42:55 +00:00
# Caller says they will call qt6_finalize_target() themselves later
2020-12-08 11:00:22 +00:00
return ( )
endif ( )
# Defer the finalization if we can. When the caller's project requires
# CMake 3.19 or later, this makes the calls to this function concise while
# still allowing target property modification before finalization.
if ( CMAKE_VERSION VERSION_GREATER_EQUAL 3.19 )
# Need to wrap in an EVAL CODE or else ${target} won't be evaluated
# due to special behavior of cmake_language() argument handling
2021-05-18 17:42:55 +00:00
cmake_language ( EVAL CODE "cmake_language(DEFER CALL qt6_finalize_target ${target})" )
2020-12-08 11:00:22 +00:00
else ( )
2021-04-28 14:27:19 +00:00
set_target_properties ( "${target}" PROPERTIES _qt_is_immediately_finalized TRUE )
2021-05-18 17:42:55 +00:00
qt6_finalize_target ( "${target}" )
2020-12-08 11:00:22 +00:00
endif ( )
endfunction ( )
function ( _qt_internal_create_executable target )
2019-06-12 08:21:40 +00:00
if ( ANDROID )
2020-11-30 16:16:41 +00:00
list ( REMOVE_ITEM ARGN "WIN32" "MACOSX_BUNDLE" )
2019-06-12 08:21:40 +00:00
add_library ( "${target}" MODULE ${ ARGN } )
2019-06-26 14:19:13 +00:00
# On our qmake builds we do don't compile the executables with
# visibility=hidden. Not having this flag set will cause the
# executable to have main() hidden and can then no longer be loaded
# through dlopen()
set_property ( TARGET "${target}" PROPERTY C_VISIBILITY_PRESET default )
set_property ( TARGET "${target}" PROPERTY CXX_VISIBILITY_PRESET default )
2020-06-24 16:19:15 +00:00
set_property ( TARGET "${target}" PROPERTY OBJC_VISIBILITY_PRESET default )
set_property ( TARGET "${target}" PROPERTY OBJCXX_VISIBILITY_PRESET default )
2020-10-26 12:47:49 +00:00
qt6_android_apply_arch_suffix ( "${target}" )
2019-06-12 08:21:40 +00:00
else ( )
2020-10-26 12:42:58 +00:00
add_executable ( "${target}" ${ ARGN } )
2019-06-12 08:21:40 +00:00
endif ( )
2020-12-08 11:00:22 +00:00
2020-12-16 01:06:07 +00:00
target_link_libraries ( "${target}" PRIVATE Qt6::Core )
2020-12-08 11:00:22 +00:00
endfunction ( )
2020-02-21 15:32:13 +00:00
2021-05-18 17:42:55 +00:00
function ( _qt_internal_finalize_executable target )
2021-04-28 14:27:19 +00:00
get_target_property ( is_finalized "${target}" _qt_executable_is_finalized )
if ( is_finalized )
message ( AUTHOR_WARNING
2021-05-18 17:42:55 +00:00
" T r i e d t o c a l l q t 6 _ f i n a l i z e _ t a r g e t t w i c e o n e x e c u t a b l e : ' $ { t a r g e t } ' . \
2021-04-28 14:27:19 +00:00
D i d y o u f o r g e t t o s p e c i f y M A N U A L _ F I N A L I Z A T I O N t o q t 6 _ a d d _ e x e c u t a b l e ? " )
return ( )
endif ( )
2021-02-15 07:59:08 +00:00
# We can't evaluate generator expressions at configure time, so we can't
# ask for any transitive properties or even the full library dependency
2021-05-04 07:09:47 +00:00
# chain.
# We can still look at the immediate dependencies
# (and recursively their dependencies) and query
2021-02-15 07:59:08 +00:00
# any that are not expressed as generator expressions. For any we can
# identify as a CMake target known to the current scope, we can check if
# that target has a finalizer to be called. This is expected to cover the
# vast majority of use cases, since projects will typically link directly
# to Qt::* targets. For the cases where this isn't so, the project will be
# responsible for calling any relevant functions themselves instead of
# relying on these automatic finalization calls.
set ( finalizers )
2021-05-04 07:09:47 +00:00
__qt_internal_collect_all_target_dependencies ( "${target}" dep_targets )
if ( dep_targets )
foreach ( dep IN LISTS dep_targets )
2021-02-15 07:59:08 +00:00
get_target_property ( dep_finalizers ${ dep }
I N T E R F A C E _ Q T _ E X E C U T A B L E _ F I N A L I Z E R S
)
if ( dep_finalizers )
list ( APPEND finalizers ${ dep_finalizers } )
endif ( )
endforeach ( )
list ( REMOVE_DUPLICATES finalizers )
endif ( )
2021-05-04 07:09:47 +00:00
2021-02-15 07:59:08 +00:00
if ( finalizers )
if ( CMAKE_VERSION VERSION_LESS 3.18 )
# cmake_language() not available
message ( WARNING
" S k i p p i n g m o d u l e - s p e c i f i c f i n a l i z e r s f o r t a r g e t $ { t a r g e t } "
" ( r e q u i r e s C M a k e 3 . 1 8 o r l a t e r ) "
)
else ( )
foreach ( finalizer_func IN LISTS finalizers )
cmake_language ( CALL ${ finalizer_func } ${ target } )
endforeach ( )
endif ( )
endif ( )
2019-06-12 08:21:40 +00:00
if ( ANDROID )
2020-12-16 01:06:07 +00:00
qt6_android_generate_deployment_settings ( "${target}" )
qt6_android_add_apk_target ( "${target}" )
2019-06-12 08:21:40 +00:00
endif ( )
2020-09-03 08:29:41 +00:00
if ( EMSCRIPTEN )
qt_wasm_add_target_helpers ( "${target}" )
endif ( )
2021-04-14 16:16:44 +00:00
if ( IOS )
qt6_finalize_ios_app ( "${target}" )
endif ( )
2021-04-28 14:27:19 +00:00
# For finalizer mode of plugin importing to work safely, we need to know the list of Qt
# dependencies the target has, but those might be added later than the qt_add_executable call.
# Most of our examples are like that. Only enable finalizer mode when we are sure that the user
# manually finalized the executable, or it was automatically done via a deferred call.
# A project can still do it manually by calling qt_import_plugins() explicitly.
get_target_property ( is_immediately_finalized "${target}" _qt_is_immediately_finalized )
if ( NOT is_immediately_finalized )
__qt_internal_apply_plugin_imports_finalizer_mode ( "${target}" )
endif ( )
set_target_properties ( ${ target } PROPERTIES _qt_executable_is_finalized TRUE )
2021-04-14 16:16:44 +00:00
endfunction ( )
2021-05-18 17:42:55 +00:00
function ( qt6_finalize_target target )
if ( NOT TARGET "${target}" )
message ( FATAL_ERROR "No target '${target}' found in current scope." )
endif ( )
get_target_property ( target_type ${ target } TYPE )
if ( target_type STREQUAL "EXECUTABLE" )
_qt_internal_finalize_executable ( ${ ARGV } )
endif ( )
endfunction ( )
2021-04-14 16:16:44 +00:00
function ( _qt_internal_find_ios_development_team_id out_var )
get_property ( team_id GLOBAL PROPERTY _qt_internal_ios_development_team_id )
get_property ( team_id_computed GLOBAL PROPERTY _qt_internal_ios_development_team_id_computed )
if ( team_id_computed )
# Just in case if the value is non-empty but still booly FALSE.
if ( NOT team_id )
set ( team_id "" )
endif ( )
set ( "${out_var}" "${team_id}" PARENT_SCOPE )
return ( )
endif ( )
set_property ( GLOBAL PROPERTY _qt_internal_ios_development_team_id_computed "TRUE" )
set ( home_dir "$ENV{HOME}" )
set ( xcode_preferences_path "${home_dir}/Library/Preferences/com.apple.dt.Xcode.plist" )
# Extract the first account name (email) from the user's Xcode preferences
message ( DEBUG "Trying to extract an Xcode development team id from '${xcode_preferences_path}'" )
execute_process ( COMMAND "/usr/libexec/PlistBuddy"
- x - c " p r i n t I D E P r o v i s i o n i n g T e a m s " " $ { x c o d e _ p r e f e r e n c e s _ p a t h } "
O U T P U T _ V A R I A B L E t e a m s _ x m l
E R R O R _ V A R I A B L E p l i s t _ e r r o r )
if ( teams_xml AND NOT plist_error )
string ( REPLACE "\n" ";" teams_xml_lines "${teams_xml}" )
foreach ( xml_line ${ teams_xml_lines } )
if ( xml_line MATCHES "<key>(.+)</key>" )
set ( first_account "${CMAKE_MATCH_1}" )
string ( STRIP "${first_account}" first_account )
break ( )
endif ( )
endforeach ( )
endif ( )
if ( NOT first_account )
message ( DEBUG "Failed to extract an Xcode development team id." )
return ( )
endif ( )
# Extract the first team ID
execute_process ( COMMAND "/usr/libexec/PlistBuddy"
- c " p r i n t I D E P r o v i s i o n i n g T e a m s : $ { f i r s t _ a c c o u n t } : 0 : t e a m I D "
" $ { x c o d e _ p r e f e r e n c e s _ p a t h } "
O U T P U T _ V A R I A B L E t e a m _ i d
E R R O R _ V A R I A B L E t e a m _ i d _ e r r o r )
if ( team_id AND NOT team_id_error )
message ( DEBUG "Successfully extracted the first encountered Xcode development team id." )
string ( STRIP "${team_id}" team_id )
set_property ( GLOBAL PROPERTY _qt_internal_ios_development_team_id "${team_id}" )
set ( "${out_var}" "${team_id}" PARENT_SCOPE )
endif ( )
endfunction ( )
function ( _qt_internal_get_ios_bundle_identifier_prefix out_var )
get_property ( prefix GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix )
get_property ( prefix_computed GLOBAL PROPERTY
_ q t _ i n t e r n a l _ i o s _ b u n d l e _ i d e n t i f i e r _ p r e f i x _ c o m p u t e d )
if ( prefix_computed )
# Just in case if the value is non-empty but still booly FALSE.
if ( NOT prefix )
set ( prefix "" )
endif ( )
set ( "${out_var}" "${prefix}" PARENT_SCOPE )
return ( )
endif ( )
set_property ( GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix_computed "TRUE" )
set ( home_dir "$ENV{HOME}" )
set ( xcode_preferences_path "${home_dir}/Library/Preferences/com.apple.dt.Xcode.plist" )
message ( DEBUG "Trying to extract the default bundle identifier prefix from Xcode preferences." )
execute_process ( COMMAND "/usr/libexec/PlistBuddy"
- c " p r i n t I D E T e m p l a t e O p t i o n s : b u n d l e I d e n t i f i e r P r e f i x "
" $ { x c o d e _ p r e f e r e n c e s _ p a t h } "
O U T P U T _ V A R I A B L E p r e f i x
E R R O R _ V A R I A B L E p r e f i x _ e r r o r )
if ( prefix AND NOT prefix_error )
message ( DEBUG "Successfully extracted the default bundle indentifier prefix." )
string ( STRIP "${prefix}" prefix )
else ( )
message ( DEBUG "Failed to extract the default bundle indentifier prefix." )
endif ( )
if ( prefix )
set_property ( GLOBAL PROPERTY _qt_internal_ios_bundle_identifier_prefix "${prefix}" )
set ( "${out_var}" "${prefix}" PARENT_SCOPE )
endif ( )
endfunction ( )
function ( _qt_internal_get_default_ios_bundle_identifier out_var )
_qt_internal_get_ios_bundle_identifier_prefix ( prefix )
if ( NOT prefix )
set ( prefix "com.yourcompany" )
endif ( )
set ( "${out_var}" "${prefix}.\${PRODUCT_NAME:rfc1034identifier}" PARENT_SCOPE )
endfunction ( )
function ( qt6_finalize_ios_app target )
# If user hasn't provided a development team id, try to find the first one specified
# in the Xcode preferences.
if ( NOT CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM AND NOT QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID )
get_target_property ( existing_team_id "${target}" XCODE_ATTRIBUTE_DEVELOPMENT_TEAM )
if ( NOT existing_team_id )
_qt_internal_find_ios_development_team_id ( team_id )
set_target_properties ( "${target}"
P R O P E R T I E S X C O D E _ A T T R I B U T E _ D E V E L O P M E N T _ T E A M " $ { t e a m _ i d } " )
endif ( )
endif ( )
# If user hasn't provided a bundle identifier for the app, get a default identifier
# using the default bundle prefix from Xcode preferences and add it to the generated
# Info.plist file.
if ( NOT MACOSX_BUNDLE_GUI_IDENTIFIER AND NOT QT_NO_SET_XCODE_BUNDLE_IDENTIFIER )
get_target_property ( existing_id "${target}" MACOSX_BUNDLE_GUI_IDENTIFIER )
if ( NOT existing_id )
_qt_internal_get_default_ios_bundle_identifier ( bundle_id )
set_target_properties ( "${target}"
P R O P E R T I E S M A C O S X _ B U N D L E _ G U I _ I D E N T I F I E R " $ { b u n d l e _ i d } " )
endif ( )
endif ( )
# Reuse the same bundle identifier for the Xcode property.
if ( NOT CMAKE_XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER
A N D N O T Q T _ N O _ S E T _ X C O D E _ B U N D L E _ I D E N T I F I E R )
get_target_property ( existing_id "${target}" XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER )
if ( NOT existing_id )
set_target_properties ( "${target}"
P R O P E R T I E S X C O D E _ A T T R I B U T E _ P R O D U C T _ B U N D L E _ I D E N T I F I E R
" $ { b u n d l e _ i d } " )
endif ( )
endif ( )
2019-06-11 13:46:31 +00:00
endfunction ( )
2020-10-15 15:58:15 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_executable )
qt6_add_executable ( ${ ARGV } )
endfunction ( )
2021-05-18 17:42:55 +00:00
function ( qt_finalize_target )
qt6_finalize_target ( ${ ARGV } )
2020-12-08 11:00:22 +00:00
endfunction ( )
2020-10-15 15:58:15 +00:00
endif ( )
2020-10-19 14:34:46 +00:00
# Temporarily keep compatibility, until all repositories are migrated.
function ( add_qt_gui_executable )
message ( AUTHOR_WARNING "Please replace add_qt_gui_executable with qt_add_executable instead. The former will be removed shortly." )
qt6_add_executable ( ${ ARGV } )
endfunction ( )
2020-10-15 15:58:15 +00:00
2020-01-22 15:28:57 +00:00
function ( _qt_get_plugin_name_with_version target out_var )
string ( REGEX REPLACE "^Qt::(.+)" "Qt${QT_DEFAULT_MAJOR_VERSION}::\\1"
q t _ p l u g i n _ w i t h _ v e r s i o n " $ { t a r g e t } " )
if ( TARGET "${qt_plugin_with_version}" )
set ( "${out_var}" "${qt_plugin_with_version}" PARENT_SCOPE )
else ( )
set ( "${out_var}" "" PARENT_SCOPE )
endif ( )
endfunction ( )
2019-06-07 07:13:31 +00:00
macro ( _qt_import_plugin target plugin )
2020-01-22 15:28:57 +00:00
set ( _final_plugin_name "${plugin}" )
if ( NOT TARGET "${plugin}" )
_qt_get_plugin_name_with_version ( "${plugin}" _qt_plugin_with_version_name )
if ( TARGET "${_qt_plugin_with_version_name}" )
set ( _final_plugin_name "${_qt_plugin_with_version_name}" )
endif ( )
endif ( )
if ( NOT TARGET "${_final_plugin_name}" )
message (
" W a r n i n g : p l u g - i n $ { _ f i n a l _ p l u g i n _ n a m e } i s n o t k n o w n t o t h e c u r r e n t Q t i n s t a l l a t i o n . " )
else ( )
get_target_property ( _plugin_class_name "${_final_plugin_name}" QT_PLUGIN_CLASS_NAME )
if ( _plugin_class_name )
set_property ( TARGET "${target}" APPEND PROPERTY QT_PLUGINS "${plugin}" )
endif ( )
2019-06-07 07:13:31 +00:00
endif ( )
endmacro ( )
2020-11-30 18:28:00 +00:00
function ( _qt_internal_disable_static_default_plugins target )
set_target_properties ( ${ target } PROPERTIES QT_DEFAULT_PLUGINS 0 )
endfunction ( )
2019-06-07 07:13:31 +00:00
# This function is used to indicate which plug-ins are going to be
# used by a given target.
2019-09-23 14:57:06 +00:00
# This allows static linking to a correct set of plugins.
2019-06-07 07:13:31 +00:00
# Options :
2019-09-23 14:57:06 +00:00
# NO_DEFAULT: disable linking against any plug-in by default for that target, e.g. no platform plug-in.
# INCLUDE <list of additional plug-ins to be linked against>
# EXCLUDE <list of plug-ins to be removed from the default set>
# INCLUDE_BY_TYPE <type> <included plugins>
# EXCLUDE_BY_TYPE <type to be excluded>
#
# Example :
# qt_import_plugins(myapp
# INCLUDE Qt::QCocoaIntegrationPlugin
# EXCLUDE Qt::QMinimalIntegrationPlugin
# INCLUDE_BY_TYPE imageformats Qt::QGifPlugin Qt::QJpegPlugin
# EXCLUDE_BY_TYPE sqldrivers
# )
2019-06-07 07:13:31 +00:00
# TODO : support qml plug-ins.
2019-12-05 12:52:33 +00:00
function ( qt6_import_plugins target )
2019-09-23 14:57:06 +00:00
cmake_parse_arguments ( arg "NO_DEFAULT" "" "INCLUDE;EXCLUDE;INCLUDE_BY_TYPE;EXCLUDE_BY_TYPE" ${ ARGN } )
2019-06-07 07:13:31 +00:00
2019-09-23 14:57:06 +00:00
# Handle NO_DEFAULT
2019-06-07 07:13:31 +00:00
if ( ${ arg_NO_DEFAULT } )
2020-11-30 18:28:00 +00:00
_qt_internal_disable_static_default_plugins ( "${target}" )
2019-06-07 07:13:31 +00:00
endif ( )
2019-09-23 14:57:06 +00:00
# Handle INCLUDE
2019-06-07 07:13:31 +00:00
foreach ( plugin ${ arg_INCLUDE } )
_qt_import_plugin ( "${target}" "${plugin}" )
endforeach ( )
2019-09-23 14:57:06 +00:00
# Handle EXCLUDE
2019-06-07 07:13:31 +00:00
foreach ( plugin ${ arg_EXCLUDE } )
set_property ( TARGET "${target}" APPEND PROPERTY QT_NO_PLUGINS "${plugin}" )
endforeach ( )
2019-09-23 14:57:06 +00:00
# Handle INCLUDE_BY_TYPE
set ( _current_type "" )
foreach ( _arg ${ arg_INCLUDE_BY_TYPE } )
string ( REGEX REPLACE "[-/]" "_" _plugin_type "${_arg}" )
list ( FIND QT_ALL_PLUGIN_TYPES_FOUND_VIA_FIND_PACKAGE "${_plugin_type}" _has_plugin_type )
if ( ${ _has_plugin_type } GREATER_EQUAL 0 )
set ( _current_type "${_plugin_type}" )
else ( )
if ( "${_current_type}" STREQUAL "" )
message ( FATAL_ERROR "qt_import_plugins: invalid syntax for INCLUDE_BY_TYPE" )
endif ( )
2020-01-22 15:28:57 +00:00
# Check if passed plugin target name is a version-less one, and make a version-full
# one.
2021-05-06 14:38:53 +00:00
set_property ( TARGET "${target}" APPEND PROPERTY "QT_PLUGINS_${_current_type}" "${_arg}" )
2021-04-28 14:27:19 +00:00
set_property ( TARGET "${target}" APPEND PROPERTY "_qt_plugins_by_type" "${_arg}" )
2020-01-22 15:28:57 +00:00
_qt_get_plugin_name_with_version ( "${_arg}" qt_plugin_with_version )
2021-05-06 14:38:53 +00:00
# TODO: Do we really need this check? We didn't have it in Qt5, and plugin targets
# wrapped in genexes end up causing warnings, but we explicitly use GENEX_EVAL to
# support them.
if ( NOT TARGET "${_arg}" AND NOT TARGET "${qt_plugin_with_version}" )
2019-09-23 14:57:06 +00:00
message ( "Warning: plug-in ${_arg} is not known to the current Qt installation." )
endif ( )
endif ( )
endforeach ( )
# Handle EXCLUDE_BY_TYPE
foreach ( _arg ${ arg_EXCLUDE_BY_TYPE } )
string ( REGEX REPLACE "[-/]" "_" _plugin_type "${_arg}" )
set_property ( TARGET "${target}" PROPERTY "QT_PLUGINS_${_plugin_type}" "-" )
endforeach ( )
2021-04-28 14:27:19 +00:00
# If the project called qt_import_plugins, use this as an event to enable finalizer mode for
# plugin importing.
#
2021-05-18 17:42:55 +00:00
# This is done in addition to the code in qt_finalize_target, to ensure pre-existing
2021-04-28 14:27:19 +00:00
# projects that use qt_import_plugins activate finalizer mode even with an older CMake version
# that doesn't support deferred calls (and projects that don't explicitly call
2021-05-18 17:42:55 +00:00
# qt_finalize_target).
2021-04-28 14:27:19 +00:00
__qt_internal_apply_plugin_imports_finalizer_mode ( ${ target } )
2019-09-23 14:57:06 +00:00
endfunction ( )
2019-10-11 14:16:29 +00:00
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_import_plugins )
if ( QT_DEFAULT_MAJOR_VERSION EQUAL 5 )
qt5_import_plugins ( ${ ARGV } )
elseif ( QT_DEFAULT_MAJOR_VERSION EQUAL 6 )
qt6_import_plugins ( ${ ARGV } )
2018-10-17 20:03:28 +00:00
endif ( )
2019-12-05 12:52:33 +00:00
endfunction ( )
endif ( )
2019-11-26 09:10:55 +00:00
2021-04-28 14:27:19 +00:00
# This function allows enabling or disabling the finalizer mode of plugin importing in static Qt
# builds.
#
# When finalizer mode is enabled, all plugins initializer object libraries are directly linked to
# the given '${target}' (executable or shared library).
# This prevents cycles between Qt provided static libraries and reduces link time, due to the
# libraries not being repeated because they are not part of a cycle anymore.
#
# When finalizer mode is disabled, each plugin initializer is propagated via usage requirements
# of its associated module.
#
# Finalizer mode is enabled by default if:
# - the project calls qt_import_plugins explicitly or
2021-05-18 17:42:55 +00:00
# - the project calls qt_finalize_target explicitly or
2021-04-28 14:27:19 +00:00
# - the project uses qt_add_executable and a CMake version greater than or equal to 3.19
2021-05-18 17:42:55 +00:00
# (which will DEFER CALL qt_finalize_target)
2021-04-28 14:27:19 +00:00
function ( qt6_enable_import_plugins_finalizer_mode target enabled )
if ( enabled )
set ( enabled "TRUE" )
else ( )
set ( enabled "FALSE" )
endif ( )
set_property ( TARGET "${target}" PROPERTY _qt_static_plugins_use_finalizer_mode "${enabled}" )
endfunction ( )
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_enable_import_plugins_finalizer_mode )
qt6_enable_import_plugins_finalizer_mode ( ${ ARGV } )
endfunction ( )
endif ( )
2020-01-27 13:56:40 +00:00
2020-10-14 11:20:55 +00:00
# Extracts metatypes from a Qt target and generates a metatypes.json for it.
# By default we check whether AUTOMOC has been enabled and we extract the information from the
# target's AUTOMOC supporting files.
# Should you not wish to use automoc you need to pass in all the generated json files via the
2020-02-03 15:52:18 +00:00
# MANUAL_MOC_JSON_FILES parameter. The latter can be obtained by running moc with
# the --output-json parameter.
2020-01-27 13:56:40 +00:00
# Params:
2020-05-25 16:52:16 +00:00
# INSTALL_DIR: Location where to install the metatypes file. For public consumption,
2020-11-10 14:31:11 +00:00
# defaults to a ${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBDIR}/metatypes directory.
2020-05-25 16:52:16 +00:00
# Executable metatypes files are never installed.
# COPY_OVER_INSTALL: (Qt Internal) When present will install the file via a post build step
# copy rather than using install.
2020-10-14 11:20:55 +00:00
function ( qt6_extract_metatypes target )
2019-11-26 09:10:55 +00:00
2020-02-03 15:52:18 +00:00
get_target_property ( existing_meta_types_file ${ target } INTERFACE_QT_META_TYPES_BUILD_FILE )
if ( existing_meta_types_file )
return ( )
endif ( )
cmake_parse_arguments ( arg "COPY_OVER_INSTALL" "INSTALL_DIR" "MANUAL_MOC_JSON_FILES" ${ ARGN } )
2020-01-27 13:56:40 +00:00
2019-11-26 09:10:55 +00:00
get_target_property ( target_type ${ target } TYPE )
2020-02-03 15:52:18 +00:00
if ( target_type STREQUAL "INTERFACE_LIBRARY" )
message ( FATAL_ERROR "Meta types generation does not work on interface libraries" )
2019-11-26 09:10:55 +00:00
return ( )
endif ( )
2020-02-03 15:52:18 +00:00
if ( CMAKE_VERSION VERSION_LESS "3.16.0" )
message ( FATAL_ERROR "Meta types generation requires CMake >= 3.16" )
2019-11-26 09:10:55 +00:00
return ( )
endif ( )
2020-05-25 16:52:16 +00:00
# Whether the generated json file needs to be installed for prefix-builds, or copied for
# non-prefix builds. Regardless of the type of build, executable metatypes.json files should
# not be installed. Only library .json files should be installed.
set ( should_install "TRUE" )
if ( target_type STREQUAL "EXECUTABLE" )
set ( should_install "FALSE" )
endif ( )
# Automatically fill default install args when not specified.
if ( NOT arg_INSTALL_DIR )
2020-11-10 14:31:11 +00:00
# INSTALL_LIBDIR is not set when QtBuildInternals is not loaded (when not doing a Qt build).
if ( INSTALL_LIBDIR )
set ( arg_INSTALL_DIR "${INSTALL_LIBDIR}/metatypes" )
else ( )
set ( arg_INSTALL_DIR "lib/metatypes" )
endif ( )
2020-05-25 16:52:16 +00:00
endif ( )
2019-11-26 09:10:55 +00:00
get_target_property ( target_binary_dir ${ target } BINARY_DIR )
2020-02-03 15:52:18 +00:00
set ( type_list_file "${target_binary_dir}/meta_types/${target}_json_file_list.txt" )
set ( type_list_file_manual "${target_binary_dir}/meta_types/${target}_json_file_list_manual.txt" )
get_target_property ( uses_automoc ${ target } AUTOMOC )
set ( automoc_args )
set ( automoc_dependencies )
2020-05-25 16:52:16 +00:00
# Handle automoc generated data
2020-02-03 15:52:18 +00:00
if ( uses_automoc )
# Tell automoc to output json files)
set_property ( TARGET "${target}" APPEND PROPERTY
A U T O M O C _ M O C _ O P T I O N S " - - o u t p u t - j s o n "
)
2019-11-26 09:10:55 +00:00
2020-05-25 17:18:49 +00:00
if ( NOT CMAKE_CONFIGURATION_TYPES )
2020-02-03 15:52:18 +00:00
set ( cmake_autogen_cache_file
" $ { t a r g e t _ b i n a r y _ d i r } / C M a k e F i l e s / $ { t a r g e t } _ a u t o g e n . d i r / P a r s e C a c h e . t x t " )
set ( mutli_config_args
- - c m a k e - a u t o g e n - i n c l u d e - d i r - p a t h " $ { t a r g e t _ b i n a r y _ d i r } / $ { t a r g e t } _ a u t o g e n / i n c l u d e "
)
else ( )
set ( cmake_autogen_cache_file
" $ { t a r g e t _ b i n a r y _ d i r } / C M a k e F i l e s / $ { t a r g e t } _ a u t o g e n . d i r / P a r s e C a c h e _ $ < C O N F I G > . t x t " )
set ( mutli_config_args
- - c m a k e - a u t o g e n - i n c l u d e - d i r - p a t h " $ { t a r g e t _ b i n a r y _ d i r } / $ { t a r g e t } _ a u t o g e n / i n c l u d e _ $ < C O N F I G > "
" - - c m a k e - m u l t i - c o n f i g " )
endif ( )
set ( cmake_autogen_info_file
" $ { t a r g e t _ b i n a r y _ d i r } / C M a k e F i l e s / $ { t a r g e t } _ a u t o g e n . d i r / A u t o g e n I n f o . j s o n " )
2020-03-04 14:58:59 +00:00
set ( use_dep_files FALSE )
if ( CMAKE_VERSION VERSION_GREATER_EQUAL "3.17" ) # Requires automoc changes present only in 3.17
if ( CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" )
set ( use_dep_files TRUE )
endif ( )
endif ( )
if ( NOT use_dep_files )
add_custom_target ( ${ target } _automoc_json_extraction
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 } : : c m a k e _ a u t o m o c _ p a r s e r
B Y P R O D U C T S $ { t y p e _ l i s t _ f i l e }
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 } : : c m a k e _ a u t o m o c _ p a r s e r
- - c m a k e - a u t o g e n - c a c h e - f i l e " $ { c m a k e _ a u t o g e n _ c a c h e _ f i l e } "
- - c m a k e - a u t o g e n - i n f o - f i l e " $ { c m a k e _ a u t o g e n _ i n f o _ f i l e } "
- - o u t p u t - f i l e - p a t h " $ { t y p e _ l i s t _ f i l e } "
$ { m u t l i _ c o n f i g _ a r g s }
C O M M E N T " R u n n i n g A u t o m o c f i l e e x t r a c t i o n "
C O M M A N D _ E X P A N D _ L I S T S
)
add_dependencies ( ${ target } _automoc_json_extraction ${ target } _autogen )
else ( )
set ( cmake_autogen_timestamp_file
" $ { t a r g e t _ b i n a r y _ d i r } / $ { t a r g e t } _ a u t o g e n / t i m e s t a m p "
)
add_custom_command ( OUTPUT ${ type_list_file }
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 } : : c m a k e _ a u t o m o c _ p a r s e r
$ { c m a k e _ a u t o g e n _ t i m e s t a m p _ f i l e }
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 } : : c m a k e _ a u t o m o c _ p a r s e r
- - c m a k e - a u t o g e n - c a c h e - f i l e " $ { c m a k e _ a u t o g e n _ c a c h e _ f i l e } "
- - c m a k e - a u t o g e n - i n f o - f i l e " $ { c m a k e _ a u t o g e n _ i n f o _ f i l e } "
- - o u t p u t - f i l e - p a t h " $ { t y p e _ l i s t _ f i l e } "
$ { m u t l i _ c o n f i g _ a r g s }
C O M M E N T " R u n n i n g A u t o m o c f i l e e x t r a c t i o n "
C O M M A N D _ E X P A N D _ L I S T S
)
endif ( )
2020-02-03 15:52:18 +00:00
set ( automoc_args "@${type_list_file}" )
set ( automoc_dependencies "${type_list_file}" )
endif ( )
set ( manual_args )
set ( manual_dependencies )
if ( arg_MANUAL_MOC_JSON_FILES )
list ( REMOVE_DUPLICATES arg_MANUAL_MOC_JSON_FILES )
file ( GENERATE
O U T P U T $ { t y p e _ l i s t _ f i l e _ m a n u a l }
C O N T E N T " $ < J O I N : $ < G E N E X _ E V A L : $ { a r g _ M A N U A L _ M O C _ J S O N _ F I L E S } > , \ n > "
)
list ( APPEND manual_dependencies ${ arg_MANUAL_MOC_JSON_FILES } ${ type_list_file_manual } )
set ( manual_args "@${type_list_file_manual}" )
endif ( )
2019-11-26 09:10:55 +00:00
2020-02-03 15:52:18 +00:00
if ( NOT manual_args AND NOT automoc_args )
message ( FATAL_ERROR "Metatype generation requires either the use of AUTOMOC or a manual list of generated json files" )
endif ( )
2019-11-26 09:10:55 +00:00
if ( CMAKE_BUILD_TYPE )
string ( TOLOWER ${ target } _ ${ CMAKE_BUILD_TYPE } target_lowercase )
else ( )
2019-12-06 14:12:17 +00:00
string ( TOLOWER ${ target } target_lowercase )
2019-11-26 09:10:55 +00:00
endif ( )
2020-01-27 13:56:40 +00:00
set ( metatypes_file_name "qt6${target_lowercase}_metatypes.json" )
set ( metatypes_file "${target_binary_dir}/meta_types/${metatypes_file_name}" )
2020-02-07 13:12:27 +00:00
set ( metatypes_file_gen "${target_binary_dir}/meta_types/${metatypes_file_name}.gen" )
2020-01-27 13:56:40 +00:00
set ( metatypes_dep_file_name "qt6${target_lowercase}_metatypes_dep.txt" )
set ( metatypes_dep_file "${target_binary_dir}/meta_types/${metatypes_dep_file_name}" )
2020-02-07 13:12:27 +00:00
# Due to generated source file dependency rules being tied to the directory
# scope in which they are created it is not possible for other targets which
# are defined in a separate scope to see these rules. This leads to failures
# in locating the generated source files.
# To work around this we write a dummy file to disk to make sure targets
# which link against the current target do not produce the error. This dummy
# file is then replaced with the contents of the generated file during
# build.
if ( NOT EXISTS ${ metatypes_file } )
file ( MAKE_DIRECTORY "${target_binary_dir}/meta_types" )
file ( TOUCH ${ metatypes_file } )
endif ( )
2020-03-20 09:03:59 +00:00
# Need to make the path absolute during a Qt non-prefix build, otherwise files are written
# to the source dir because the paths are relative to the source dir when using file(TOUCH).
if ( arg_COPY_OVER_INSTALL AND NOT IS_ABSOLUTE "${arg_INSTALL_DIR}/${metatypes_file_name}" )
set ( arg_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${arg_INSTALL_DIR}" )
endif ( )
2020-05-25 16:52:16 +00:00
if ( should_install AND arg_COPY_OVER_INSTALL
A N D N O T E X I S T S $ { a r g _ I N S T A L L _ D I R } / $ { m e t a t y p e s _ f i l e _ n a m e } )
2020-02-12 09:30:48 +00:00
file ( MAKE_DIRECTORY "${arg_INSTALL_DIR}" )
file ( TOUCH "${arg_INSTALL_DIR}/${metatypes_file_name}" )
endif ( )
2020-02-07 13:12:27 +00:00
add_custom_command ( OUTPUT ${ metatypes_file_gen } ${ metatypes_file }
2020-02-03 15:52:18 +00:00
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 $ { a u t o m o c _ d e p e n d e n c i e s } $ { m a n u a l _ d e p e n d e n c i e s }
2019-11-26 09:10:55 +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
2020-02-07 13:12:27 +00:00
- o $ { m e t a t y p e s _ f i l e _ g e n }
2020-02-03 15:52:18 +00:00
- - c o l l e c t - j s o n $ { a u t o m o c _ a r g s } $ { m a n u a l _ a r g s }
2020-02-07 13:12:27 +00:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
$ { m e t a t y p e s _ f i l e _ g e n }
$ { m e t a t y p e s _ f i l e }
2020-10-12 06:51:57 +00:00
C O M M E N T " R u n n i n g a u t o m o c w i t h - - c o l l e c t - j s o n "
2019-11-26 09:10:55 +00:00
)
2020-02-07 13:12:27 +00:00
# We still need to add this file as a source of Core, otherwise the file
# rule above is not triggered. INTERFACE_SOURCES do not properly register
# as dependencies to build the current target.
target_sources ( ${ target } PRIVATE ${ metatypes_file_gen } )
set ( metatypes_file_genex_build )
set ( metatypes_file_genex_install )
if ( arg_COPY_OVER_INSTALL )
2020-05-25 16:52:16 +00:00
if ( should_install )
set ( metatypes_file_genex_build
" $ < B U I L D _ I N T E R F A C E : $ < $ < B O O L : $ < T A R G E T _ P R O P E R T Y : Q T _ C O N S U M E S _ M E T A T Y P E S > > : $ { a r g _ I N S T A L L _ D I R } / $ { m e t a t y p e s _ f i l e _ n a m e } > > "
)
endif ( )
2020-02-07 13:12:27 +00:00
else ( )
set ( metatypes_file_genex_build
" $ < B U I L D _ I N T E R F A C E : $ < $ < B O O L : $ < T A R G E T _ P R O P E R T Y : Q T _ C O N S U M E S _ M E T A T Y P E S > > : $ { m e t a t y p e s _ f i l e } > > "
)
2020-05-25 16:52:16 +00:00
if ( should_install )
set ( metatypes_file_genex_install
" $ < I N S T A L L _ I N T E R F A C E : $ < $ < B O O L : $ < T A R G E T _ P R O P E R T Y : Q T _ C O N S U M E S _ M E T A T Y P E S > > : $ < I N S T A L L _ P R E F I X > / $ { a r g _ I N S T A L L _ D I R } / $ { m e t a t y p e s _ f i l e _ n a m e } > > "
)
endif ( )
2020-02-07 13:12:27 +00:00
endif ( )
2019-11-26 09:10:55 +00:00
set_source_files_properties ( ${ metatypes_file } PROPERTIES HEADER_FILE_ONLY TRUE )
set_target_properties ( ${ target } PROPERTIES
2020-01-27 13:56:40 +00:00
I N T E R F A C E _ Q T _ M O D U L E _ H A S _ M E T A _ T Y P E S Y E S
I N T E R F A C E _ Q T _ M O D U L E _ M E T A _ T Y P E S _ F R O M _ B U I L D Y E S
2020-05-25 16:52:16 +00:00
I N T E R F A C E _ Q T _ M E T A _ T Y P E S _ B U I L D _ F I L E " $ { m e t a t y p e s _ f i l e } "
2020-02-07 13:12:27 +00:00
Q T _ M O D U L E _ M E T A _ T Y P E S _ F I L E _ G E N E X _ B U I L D " $ { m e t a t y p e s _ f i l e _ g e n e x _ b u i l d } "
Q T _ M O D U L E _ M E T A _ T Y P E S _ F I L E _ G E N E X _ I N S T A L L " $ { m e t a t y p e s _ f i l e _ g e n e x _ i n s t a l l } "
2020-01-27 13:56:40 +00:00
)
2020-02-07 13:12:27 +00:00
target_sources ( ${ target } INTERFACE ${ metatypes_file_genex_build } ${ metatypes_file_genex_install } )
2020-01-27 13:56:40 +00:00
2020-05-25 16:52:16 +00:00
# Installation is complicated, because there are multiple combinations.
# In non-prefix builds (signaled by arg_COPY_OVER_INSTALL == TRUE), Qt modules are /copied/
# into the qt_prefix/lib/metatypes.
# In prefix builds (signaled by arg_COPY_OVER_INSTALL == FALSE), Qt modules are /installed/
# into the qt_prefix/lib/metatypes.
# Currently only the internal qt_add_module sets arg_COPY_OVER_INSTALL.
#
# Tests and examples are executables, and thus will not have their meta types installed, but
# they will have them generated (if this function is called).
#
# Regular libraries and plugins (which are not part of the Qt build), will be /installed/
# into a lib/metatypes directory relative to their prefix, rather than the Qt prefix (only
# outside of a Qt build).
# We don't support non-prefix builds for libraries or plugins which are not part of the official
# Qt build. Aka everything non-prefix / COPY_OVER_INSTALL related are implementation details
# that users shouldn't use.
if ( should_install )
if ( arg_COPY_OVER_INSTALL )
set ( command_args
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
" $ { m e t a t y p e s _ f i l e } "
" $ { a r g _ I N S T A L L _ D I R } / $ { m e t a t y p e s _ f i l e _ n a m e } "
2020-02-03 15:52:18 +00:00
)
2020-05-25 16:52:16 +00:00
if ( target_type STREQUAL "OBJECT_LIBRARY" )
add_custom_target ( ${ target } _metatypes_copy
D E P E N D S " $ { m e t a t y p e s _ f i l e } "
$ { c o m m a n d _ a r g s }
)
add_dependencies ( ${ target } ${ target } _metatypes_copy )
else ( )
add_custom_command ( TARGET ${ target } POST_BUILD
$ { c o m m a n d _ a r g s }
)
endif ( )
2020-02-03 15:52:18 +00:00
else ( )
2020-05-25 16:52:16 +00:00
install ( FILES "${metatypes_file}" DESTINATION "${arg_INSTALL_DIR}" )
2020-02-03 15:52:18 +00:00
endif ( )
2020-01-27 13:56:40 +00:00
endif ( )
2019-11-26 09:10:55 +00:00
endfunction ( )
2019-12-05 12:52:33 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
2020-10-14 11:20:55 +00:00
function ( qt_extract_metatypes )
qt6_extract_metatypes ( ${ ARGV } )
2019-12-05 12:52:33 +00:00
endfunction ( )
endif ( )
2020-02-21 15:32:13 +00:00
# Generate Win32 RC files for a target. All entries in the RC file are generated
2020-05-04 19:55:40 +00:00
# from target properties:
2020-02-21 15:32:13 +00:00
#
# QT_TARGET_COMPANY_NAME: RC Company name
# QT_TARGET_DESCRIPTION: RC File Description
# QT_TARGET_VERSION: RC File and Product Version
# QT_TARGET_COPYRIGHT: RC LegalCopyright
# QT_TARGET_PRODUCT_NAME: RC ProductName
2020-05-11 15:04:21 +00:00
# QT_TARGET_COMMENTS: RC Comments
# QT_TARGET_ORIGINAL_FILENAME: RC Original FileName
# QT_TARGET_TRADEMARKS: RC LegalTrademarks
# QT_TARGET_INTERNALNAME: RC InternalName
2020-02-21 15:32:13 +00:00
# QT_TARGET_RC_ICONS: List of paths to icon files
#
2020-05-04 19:55:40 +00:00
# If you do not wish to auto-generate rc files, it's possible to provide your
2020-02-21 15:32:13 +00:00
# own RC file by setting the property QT_TARGET_WINDOWS_RC_FILE with a path to
# an existing rc file.
2020-10-14 11:20:55 +00:00
function ( _qt_internal_generate_win32_rc_file target )
2020-05-06 05:54:37 +00:00
set ( prohibited_target_types INTERFACE_LIBRARY STATIC_LIBRARY OBJECT_LIBRARY )
2020-02-21 15:32:13 +00:00
get_target_property ( target_type ${ target } TYPE )
2020-05-06 05:54:37 +00:00
if ( target_type IN_LIST prohibited_target_types )
2020-02-21 15:32:13 +00:00
return ( )
endif ( )
get_target_property ( target_binary_dir ${ target } BINARY_DIR )
get_target_property ( target_rc_file ${ target } QT_TARGET_WINDOWS_RC_FILE )
get_target_property ( target_version ${ target } QT_TARGET_VERSION )
if ( NOT target_rc_file AND NOT target_version )
return ( )
endif ( )
2020-05-04 19:55:40 +00:00
if ( target_rc_file )
# Use the provided RC file
target_sources ( ${ target } PRIVATE "${target_rc_file}" )
else ( )
2020-02-21 15:32:13 +00:00
# Generate RC File
2020-05-04 19:55:40 +00:00
set ( rc_file_output "${target_binary_dir}/" )
if ( QT_GENERATOR_IS_MULTI_CONFIG )
string ( APPEND rc_file_output "$<CONFIG>/" )
endif ( )
string ( APPEND rc_file_output "${target}_resource.rc" )
2020-02-21 15:32:13 +00:00
set ( target_rc_file "${rc_file_output}" )
set ( company_name "" )
get_target_property ( target_company_name ${ target } QT_TARGET_COMPANY_NAME )
if ( target_company_name )
set ( company_name "${target_company_name}" )
endif ( )
set ( file_description "" )
get_target_property ( target_description ${ target } QT_TARGET_DESCRIPTION )
if ( target_description )
set ( file_description "${target_description}" )
endif ( )
set ( legal_copyright "" )
get_target_property ( target_copyright ${ target } QT_TARGET_COPYRIGHT )
if ( target_copyright )
set ( legal_copyright "${target_copyright}" )
endif ( )
set ( product_name "" )
get_target_property ( target_product_name ${ target } QT_TARGET_PRODUCT_NAME )
if ( target_product_name )
set ( product_name "${target_product_name}" )
else ( )
set ( product_name "${target}" )
endif ( )
2020-05-11 15:04:21 +00:00
set ( comments "" )
get_target_property ( target_comments ${ target } QT_TARGET_COMMENTS )
if ( target_comments )
set ( comments "${target_comments}" )
endif ( )
set ( legal_trademarks "" )
get_target_property ( target_trademarks ${ target } QT_TARGET_TRADEMARKS )
if ( target_trademarks )
set ( legal_trademarks "${target_trademarks}" )
endif ( )
2020-02-21 15:32:13 +00:00
set ( product_version "" )
if ( target_version )
if ( target_version MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" )
# nothing to do
elseif ( target_version MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+" )
set ( target_version "${target_version}.0" )
elseif ( target_version MATCHES "[0-9]+\\.[0-9]+" )
set ( target_version "${target_version}.0.0" )
elseif ( target_version MATCHES "[0-9]+" )
set ( target_version "${target_version}.0.0.0" )
else ( )
2020-07-27 08:17:04 +00:00
message ( FATAL_ERROR "Invalid version format: '${target_version}'" )
2020-02-21 15:32:13 +00:00
endif ( )
set ( product_version "${target_version}" )
else ( )
set ( product_version "0.0.0.0" )
endif ( )
set ( file_version "${product_version}" )
string ( REPLACE "." "," version_comma ${ product_version } )
2020-05-11 15:04:21 +00:00
set ( original_file_name "$<TARGET_FILE_NAME:${target}>" )
get_target_property ( target_original_file_name ${ target } QT_TARGET_ORIGINAL_FILENAME )
if ( target_original_file_name )
set ( original_file_name "${target_original_file_name}" )
endif ( )
set ( internal_name "" )
get_target_property ( target_internal_name ${ target } QT_TARGET_INTERNALNAME )
if ( target_internal_name )
set ( internal_name "${target_internal_name}" )
endif ( )
2020-02-21 15:32:13 +00:00
set ( icons "" )
get_target_property ( target_icons ${ target } QT_TARGET_RC_ICONS )
if ( target_icons )
set ( index 1 )
foreach ( icon IN LISTS target_icons )
2020-05-11 13:49:28 +00:00
string ( APPEND icons "IDI_ICON${index} ICON \" ${ icon } \"\n")
2020-02-21 15:32:13 +00:00
math ( EXPR index "${index} +1" )
endforeach ( )
endif ( )
2020-05-12 02:25:35 +00:00
set ( target_file_type "VFT_DLL" )
if ( target_type STREQUAL "EXECUTABLE" )
set ( target_file_type "VFT_APP" )
endif ( )
2020-02-21 15:32:13 +00:00
set ( contents " #include <windows.h>
2020-05-06 05:56:45 +00:00
$ { i c o n s }
2020-02-21 15:32:13 +00:00
V S _ V E R S I O N _ I N F O V E R S I O N I N F O
F I L E V E R S I O N $ { v e r s i o n _ c o m m a }
P R O D U C T V E R S I O N $ { v e r s i o n _ c o m m a }
F I L E F L A G S M A S K 0 x 3 f L
#ifdef _DEBUG
F I L E F L A G S V S _ F F _ D E B U G
#else
F I L E F L A G S 0 x 0 L
#endif
2020-05-04 08:51:01 +00:00
F I L E O S V O S _ N T _ W I N D O W S 3 2
2020-05-12 02:25:35 +00:00
F I L E T Y P E $ { t a r g e t _ f i l e _ t y p e }
2020-05-04 08:51:01 +00:00
F I L E S U B T Y P E V F T 2 _ U N K N O W N
2020-02-21 15:32:13 +00:00
B E G I N
B L O C K \ " S t r i n g F i l e I n f o \ "
B E G I N
B L O C K \ " 0 4 0 9 0 4 b 0 \ "
B E G I N
V A L U E \ " C o m p a n y N a m e \ " , \ " $ { c o m p a n y _ n a m e } \ "
V A L U E \ " F i l e D e s c r i p t i o n \ " , \ " $ { f i l e _ d e s c r i p t i o n } \ "
V A L U E \ " F i l e V e r s i o n \ " , \ " $ { f i l e _ v e r s i o n } \ "
V A L U E \ " L e g a l C o p y r i g h t \ " , \ " $ { l e g a l _ c o p y r i g h t } \ "
V A L U E \ " O r i g i n a l F i l e n a m e \ " , \ " $ { o r i g i n a l _ f i l e _ n a m e } \ "
V A L U E \ " P r o d u c t N a m e \ " , \ " $ { p r o d u c t _ n a m e } \ "
V A L U E \ " P r o d u c t V e r s i o n \ " , \ " $ { p r o d u c t _ v e r s i o n } \ "
2020-05-11 15:04:21 +00:00
V A L U E \ " C o m m e n t s \ " , \ " $ { c o m m e n t s } \ "
V A L U E \ " L e g a l T r a d e m a r k s \ " , \ " $ { l e g a l _ t r a d e m a r k s } \ "
V A L U E \ " I n t e r n a l N a m e \ " , \ " $ { i n t e r n a l _ n a m e } \ "
2020-02-21 15:32:13 +00:00
E N D
E N D
B L O C K \ " V a r F i l e I n f o \ "
B E G I N
V A L U E \ " T r a n s l a t i o n \ " , 0 x 0 4 0 9 , 1 2 0 0
E N D
E N D
/ * E n d o f V e r s i o n i n f o * / \ n "
)
# We can't use the output of file generate as source so we work around
# this by generating the file under a different name and then copying
# the file in place using add custom command.
file ( GENERATE OUTPUT "${rc_file_output}.tmp"
C O N T E N T " $ { c o n t e n t s } "
)
2020-05-04 19:55:40 +00:00
if ( QT_GENERATOR_IS_MULTI_CONFIG )
set ( cfgs ${ CMAKE_CONFIGURATION_TYPES } )
set ( outputs "" )
foreach ( cfg ${ cfgs } )
string ( REPLACE "$<CONFIG>" "${cfg}" expanded_rc_file_output "${rc_file_output}" )
list ( APPEND outputs "${expanded_rc_file_output}" )
endforeach ( )
else ( )
set ( cfgs "${CMAKE_BUILD_TYPE}" )
set ( outputs "${rc_file_output}" )
endif ( )
2020-11-10 11:50:21 +00:00
# We would like to do the following:
# target_sources(${target} PRIVATE "$<$<CONFIG:${cfg}>:${output}>")
# However, https://gitlab.kitware.com/cmake/cmake/-/issues/20682 doesn't let us.
# Work-around by compiling the resources in an object lib and linking that.
add_library ( ${ target } _rc OBJECT "${output}" )
target_link_libraries ( ${ target } PRIVATE $< TARGET_OBJECTS:${target}_rc > )
2020-05-04 19:55:40 +00:00
while ( outputs )
list ( POP_FRONT cfgs cfg )
list ( POP_FRONT outputs output )
set ( input "${output}.tmp" )
add_custom_command ( OUTPUT "${output}"
D E P E N D S " $ { i n p u t } "
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t " $ { i n p u t } " " $ { o u t p u t } "
)
2020-11-10 11:50:21 +00:00
target_sources ( ${ target } _rc PRIVATE "$<$<CONFIG:${cfg}>:${output}>" )
2020-05-04 19:55:40 +00:00
endwhile ( )
endif ( )
2020-02-21 15:32:13 +00:00
endfunction ( )
2020-04-17 12:36:09 +00:00
function ( __qt_get_relative_resource_path_for_file output_alias file )
get_property ( alias SOURCE ${ file } PROPERTY QT_RESOURCE_ALIAS )
if ( NOT alias )
set ( alias "${file}" )
endif ( )
set ( ${ output_alias } ${ alias } PARENT_SCOPE )
endfunction ( )
function ( __qt_propagate_generated_resource target resource_name generated_source_code output_generated_target )
get_target_property ( type ${ target } TYPE )
if ( type STREQUAL STATIC_LIBRARY )
2020-11-26 16:13:49 +00:00
get_target_property ( resource_count ${ target } _qt_generated_resource_target_count )
if ( NOT resource_count )
set ( resource_count "0" )
endif ( )
math ( EXPR resource_count "${resource_count} + 1" )
set_target_properties ( ${ target } PROPERTIES _qt_generated_resource_target_count ${ resource_count } )
set ( resource_target "${target}_resources_${resource_count}" )
2020-04-17 12:36:09 +00:00
add_library ( "${resource_target}" OBJECT "${generated_source_code}" )
2021-03-29 14:46:19 +00:00
target_compile_definitions ( "${resource_target}" PRIVATE
" $ < T A R G E T _ P R O P E R T Y : $ { 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 , 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 > "
)
2021-04-23 14:23:36 +00:00
target_link_libraries ( ${ resource_target } PRIVATE ${ QT_CMAKE_EXPORT_NAMESPACE } ::Platform )
_qt_internal_copy_dependency_properties ( ${ resource_target } ${ target } PRIVATE_ONLY )
2021-03-29 13:28:16 +00:00
# Special handling is required for the Core library resources. The linking of the Core
# library to the resources adds a circular dependency. This leads to the wrong
# objects/library order in the linker command line, since the Core library target is resolved
# first.
if ( NOT target STREQUAL "Core" )
target_link_libraries ( ${ resource_target } INTERFACE ${ QT_CMAKE_EXPORT_NAMESPACE } ::Core )
endif ( )
2020-11-20 11:49:53 +00:00
set_property ( TARGET ${ resource_target } APPEND PROPERTY _qt_resource_name ${ resource_name } )
2020-04-17 12:36:09 +00:00
2020-11-25 16:54:53 +00:00
# Save the path to the generated source file, relative to the the current build dir.
# The path will be used in static library prl file generation to ensure qmake links
# against the installed resource object files.
# Example saved path:
# .rcc/qrc_qprintdialog.cpp
file ( RELATIVE_PATH generated_cpp_file_relative_path
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } "
" $ { g e n e r a t e d _ s o u r c e _ c o d e } " )
set_property ( TARGET ${ resource_target } APPEND PROPERTY
_ q t _ r e s o u r c e _ g e n e r a t e d _ c p p _ r e l a t i v e _ p a t h " $ { g e n e r a t e d _ c p p _ f i l e _ r e l a t i v e _ p a t h } " )
2020-04-17 12:36:09 +00:00
# Use TARGET_NAME genex to map to the correct prefixed target name when it is exported
# via qt_install(EXPORT), so that the consumers of the target can find the object library
2021-04-22 13:09:44 +00:00
# as well.
target_sources ( ${ target } INTERFACE
" $ < T A R G E T _ O B J E C T S : $ < T A R G E T _ N A M E : $ { r e s o u r c e _ t a r g e t } > > "
)
2021-03-29 13:28:16 +00:00
if ( NOT target STREQUAL "Core" )
2021-04-22 13:09:44 +00:00
# It's necessary to link the object library target, since we want to pass
# the object library dependencies to the 'target'. Interface linking doesn't
# add the objects of the resource library to the end-point linker line
# but propagates all the dependencies of the resource_target added before
# or AFTER the line below.
target_link_libraries ( ${ target } INTERFACE ${ resource_target } )
2021-03-29 13:28:16 +00:00
endif ( )
2020-04-17 12:36:09 +00:00
set ( ${ output_generated_target } "${resource_target}" PARENT_SCOPE )
else ( )
set ( ${ output_generated_target } "" PARENT_SCOPE )
target_sources ( ${ target } PRIVATE ${ generated_source_code } )
endif ( )
endfunction ( )
2020-11-05 16:05:44 +00:00
# Creates fake targets and adds resource files to IDE's tree
function ( _qt_internal_expose_source_file_to_ide target file )
set ( ide_target_extension "other_files" )
set ( qml_extensions ".qml" ".js" )
get_filename_component ( resource_extension "${file}" LAST_EXT )
if ( resource_extension IN_LIST qml_extensions )
set ( ide_target_extension "qml_files" )
endif ( )
set ( ide_target ${ target } _ ${ ide_target_extension } )
if ( NOT TARGET ${ ide_target } )
add_custom_target ( ${ ide_target } SOURCES "${file}" )
else ( )
set_property ( TARGET ${ ide_target } APPEND PROPERTY SOURCES "${file}" )
endif ( )
endfunction ( )
2020-04-17 12:36:09 +00:00
#
# Process resources via file path instead of QRC files. Behind the
# scnenes, it will generate a qrc file and apply post processing steps
# when applicable. (e.g.: QtQuickCompiler)
#
# The QRC Prefix is set via the PREFIX parameter.
#
# Alias settings for files need to be set via the QT_RESOURCE_ALIAS property
# via the set_soure_files_properties() command.
#
# When using this command with static libraries, one or more special targets
# will be generated. Should you wish to perform additional processing on these
# targets pass a value to the OUTPUT_TARGETS parameter.
#
2020-10-01 08:58:02 +00:00
function ( _qt_internal_process_resource target resourceName )
2020-04-17 12:36:09 +00:00
2020-11-10 14:18:49 +00:00
cmake_parse_arguments ( rcc "" "PREFIX;LANG;BASE;OUTPUT_TARGETS;DESTINATION" "FILES;OPTIONS" ${ ARGN } )
if ( "${rcc_OPTIONS}" MATCHES "-binary" )
set ( isBinary TRUE )
endif ( )
2020-04-17 12:36:09 +00:00
string ( REPLACE "/" "_" resourceName ${ resourceName } )
string ( REPLACE "." "_" resourceName ${ resourceName } )
set ( output_targets "" )
2021-05-14 13:31:30 +00:00
if ( NOT DEFINED QT_REPO_MODULE_VERSION OR QT_USE_FIXED_QT_ADD_RESOURCE_BASE )
# Use the fixed BASE argument instead of the slightly broken one from 6.0.
2020-04-17 12:36:09 +00:00
set ( resource_files ${ rcc_FILES } )
2021-05-14 13:31:30 +00:00
if ( NOT "${rcc_BASE}" STREQUAL "" )
get_filename_component ( abs_base "${rcc_BASE}" ABSOLUTE )
foreach ( file_path IN LISTS resource_files )
get_source_file_property ( alias "${file_path}" QT_RESOURCE_ALIAS )
if ( alias STREQUAL "NOTFOUND" )
get_filename_component ( abs_file "${file_path}" ABSOLUTE )
file ( RELATIVE_PATH rel_file "${abs_base}" "${abs_file}" )
set_property ( SOURCE "${file_path}" PROPERTY QT_RESOURCE_ALIAS "${rel_file}" )
endif ( )
endforeach ( )
endif ( )
else ( )
# TODO: Remove this else branch, once every Qt module defines
# QT_USE_FIXED_QT_ADD_RESOURCE_BASE.
# Apply base to all files
if ( rcc_BASE )
foreach ( file_path IN LISTS rcc_FILES )
set ( resource_file "${rcc_BASE}/${file_path}" )
__qt_get_relative_resource_path_for_file ( alias ${ resource_file } )
# Handle case where resources were generated from a directory
# different than the one where the main .pro file resides.
# Unless otherwise specified, we should use the original file path
# as alias.
if ( alias STREQUAL resource_file )
set_source_files_properties ( ${ resource_file } PROPERTIES
Q T _ R E S O U R C E _ A L I A S $ { f i l e _ p a t h } )
endif ( )
file ( TO_CMAKE_PATH ${ resource_file } resource_file )
list ( APPEND resource_files ${ resource_file } )
endforeach ( )
else ( )
set ( resource_files ${ rcc_FILES } )
endif ( )
2020-04-17 12:36:09 +00:00
endif ( )
if ( NOT rcc_PREFIX )
get_target_property ( rcc_PREFIX ${ target } QT_RESOURCE_PREFIX )
if ( NOT rcc_PREFIX )
2020-10-01 08:58:02 +00:00
message ( FATAL_ERROR "_qt_internal_process_resource() was called without a PREFIX and the target does not provide QT_RESOURCE_PREFIX. Please either add a PREFIX or make the target ${target} provide a default." )
2020-04-17 12:36:09 +00:00
endif ( )
endif ( )
# Apply quick compiler pass. This is only enabled when Qt6QmlMacros is
# parsed.
if ( QT6_ADD_RESOURCE_DECLARATIVE_EXTENSIONS )
2020-10-01 09:43:23 +00:00
_qt_internal_quick_compiler_process_resources ( ${ target } ${ resourceName }
2020-04-17 12:36:09 +00:00
F I L E S $ { r e s o u r c e _ f i l e s }
P R E F I X $ { r c c _ P R E F I X }
O U T P U T _ R E M A I N I N G _ R E S O U R C E S r e s o u r c e s
O U T P U T _ R E S O U R C E _ N A M E n e w 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 _ T A R G E T o u t p u t _ t a r g e t _ q u i c k
)
else ( )
set ( newResourceName ${ resourceName } )
set ( resources ${ resource_files } )
endif ( )
if ( NOT resources )
if ( rcc_OUTPUT_TARGETS )
set ( ${ rcc_OUTPUT_TARGETS } "${output_target_quick}" PARENT_SCOPE )
endif ( )
return ( )
endif ( )
list ( APPEND output_targets ${ output_target_quick } )
2020-11-23 16:54:34 +00:00
set ( generatedBaseName "${newResourceName}" )
2020-11-10 14:18:49 +00:00
set ( generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/${generatedBaseName}.qrc" )
2020-04-17 12:36:09 +00:00
# Generate .qrc file:
# <RCC><qresource ...>
set ( qrcContents "<RCC>\n <qresource" )
if ( rcc_PREFIX )
string ( APPEND qrcContents " prefix=\" ${ rcc_PREFIX } \"")
endif ( )
if ( rcc_LANG )
string ( APPEND qrcContents " lang=\" ${ rcc_LANG } \"")
endif ( )
string ( APPEND qrcContents ">\n" )
set ( resource_dependencies )
foreach ( file IN LISTS resources )
__qt_get_relative_resource_path_for_file ( file_resource_path ${ file } )
if ( NOT IS_ABSOLUTE ${ file } )
set ( file "${CMAKE_CURRENT_SOURCE_DIR}/${file}" )
endif ( )
### FIXME: escape file paths to be XML conform
# <file ...>...</file>
string ( APPEND qrcContents " <file alias=\" ${ file_resource_path } \">")
string ( APPEND qrcContents "${file}</file>\n" )
list ( APPEND files "${file}" )
get_source_file_property ( target_dependency ${ file } QT_RESOURCE_TARGET_DEPENDENCY )
if ( NOT target_dependency )
list ( APPEND resource_dependencies ${ file } )
else ( )
if ( NOT TARGET ${ target_dependency } )
message ( FATAL_ERROR "Target dependency on resource file ${file} is not a cmake target." )
endif ( )
list ( APPEND resource_dependencies ${ target_dependency } )
endif ( )
2020-11-05 16:05:44 +00:00
_qt_internal_expose_source_file_to_ide ( ${ target } "${file}" )
2020-04-17 12:36:09 +00:00
endforeach ( )
# </qresource></RCC>
string ( APPEND qrcContents " </qresource>\n</RCC>\n" )
2020-10-30 15:46:40 +00:00
set ( template_file "${__qt_core_macros_module_base_dir}/Qt6CoreConfigureFileTemplate.in" )
set ( qt_core_configure_file_contents "${qrcContents}" )
configure_file ( "${template_file}" "${generatedResourceFile}" )
2020-10-14 14:04:44 +00:00
2020-11-10 14:18:49 +00:00
set ( rccArgs --name "${newResourceName}" "${generatedResourceFile}" )
2020-04-17 12:36:09 +00:00
if ( rcc_OPTIONS )
list ( APPEND rccArgs ${ rcc_OPTIONS } )
endif ( )
# When cross-building, we use host tools to generate target code. If the host rcc was compiled
# with zstd support, it expects the target QtCore to be able to decompress zstd compressed
# content. This might be true with qmake where host tools are built as part of the
# cross-compiled Qt, but with CMake we build tools separate from the cross-compiled Qt.
# If the target does not support zstd (feature is disabled), tell rcc not to generate
# zstd related code.
if ( NOT QT_FEATURE_zstd )
list ( APPEND rccArgs "--no-zstd" )
endif ( )
2020-11-10 14:18:49 +00:00
set_property ( SOURCE "${generatedResourceFile}" PROPERTY SKIP_AUTOGEN ON )
# Set output file name for rcc command
if ( isBinary )
set ( generatedOutfile "${CMAKE_CURRENT_BINARY_DIR}/${generatedBaseName}.rcc" )
if ( rcc_DESTINATION )
# Add .rcc suffix if it's not specified by user
get_filename_component ( destinationRccExt "${rcc_DESTINATION}" LAST_EXT )
if ( "${destinationRccExt}" STREQUAL ".rcc" )
set ( generatedOutfile "${rcc_DESTINATION}" )
else ( )
set ( generatedOutfile "${rcc_DESTINATION}.rcc" )
endif ( )
endif ( )
else ( )
set ( generatedOutfile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${newResourceName}.cpp" )
endif ( )
list ( PREPEND rccArgs --output "${generatedOutfile}" )
2020-04-17 12:36:09 +00:00
# Process .qrc file:
2020-11-10 14:18:49 +00:00
add_custom_command ( OUTPUT "${generatedOutfile}"
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 " $ { r c c A r g s }
2020-04-17 12:36:09 +00:00
D E P E N D S
$ { r e s o u r c e _ d e p e n d e n c i e s }
$ { g e n e r a t e d R e s o u r c e 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 } : : r c c "
C O M M E N T " R C C $ { n e w R e s o u r c e N a m e } "
V E R B A T I M )
2020-11-10 14:18:49 +00:00
if ( isBinary )
# Add generated .rcc target to 'all' set
add_custom_target ( binary_resource_ ${ generatedBaseName } ALL DEPENDS "${generatedOutfile}" )
2020-04-17 12:36:09 +00:00
else ( )
2020-11-10 14:18:49 +00:00
set_property ( SOURCE "${generatedOutfile}" PROPERTY SKIP_AUTOGEN ON )
set_property ( TARGET ${ target } APPEND PROPERTY _qt_generated_qrc_files "${generatedResourceFile}" )
# Only do this if newResourceName is the same as resourceName, since
# the resource will be chainloaded by the qt quickcompiler
# qml cache loader
if ( newResourceName STREQUAL resourceName )
__qt_propagate_generated_resource ( ${ target } ${ resourceName } "${generatedOutfile}" output_target )
list ( APPEND output_targets ${ output_target } )
else ( )
target_sources ( ${ target } PRIVATE "${generatedOutfile}" )
endif ( )
if ( rcc_OUTPUT_TARGETS )
set ( ${ rcc_OUTPUT_TARGETS } "${output_targets}" PARENT_SCOPE )
endif ( )
2020-04-17 12:36:09 +00:00
endif ( )
endfunction ( )
2020-04-21 11:28:57 +00:00
2021-03-23 04:48:56 +00:00
macro ( _qt_internal_get_add_plugin_keywords option_args single_args multi_args )
set ( ${ option_args }
S T A T I C
2021-04-06 11:06:11 +00:00
S H A R E D
2021-03-23 04:48:56 +00:00
)
set ( ${ single_args }
T Y P E
C L A S S _ N A M E
O U T P U T _ N A M E
)
set ( ${ multi_args } )
endmacro ( )
2020-10-14 11:20:55 +00:00
# This function is currently in Technical Preview.
# It's signature and behavior might change.
2020-04-21 11:28:57 +00:00
function ( qt6_add_plugin target )
2021-03-23 04:48:56 +00:00
_qt_internal_get_add_plugin_keywords ( opt_args single_args multi_args )
# TODO: Transitional use only, replaced by CLASS_NAME. Remove this once
# all other repos have been updated to use CLASS_NAME.
list ( APPEND single_args CLASSNAME )
cmake_parse_arguments ( PARSE_ARGV 1 arg "${opt_args}" "${single_args}" "${multi_args}" )
# Handle the inconsistent CLASSNAME/CLASS_NAME keyword naming between commands
if ( arg_CLASSNAME )
if ( arg_CLASS_NAME AND NOT arg_CLASSNAME STREQUAL arg_CLASS_NAME )
message ( FATAL_ERROR
" B o t h C L A S S N A M E a n d C L A S S _ N A M E w e r e g i v e n a n d w e r e d i f f e r e n t . "
" O n l y o n e o f t h e t w o s h o u l d b e u s e d . "
)
endif ( )
set ( arg_CLASS_NAME "${arg_CLASSNAME}" )
unset ( arg_CLASSNAME )
endif ( )
2021-04-06 11:06:11 +00:00
if ( arg_STATIC AND arg_SHARED )
message ( FATAL_ERROR
" B o t h S T A T I C a n d S H A R E D o p t i o n s w e r e g i v e n . O n l y o n e o f t h e t w o s h o u l d b e u s e d . "
)
endif ( )
# If no explicit STATIC/SHARED option is set, default to the flavor of the Qt build.
if ( QT6_IS_SHARED_LIBS_BUILD )
set ( create_static_plugin FALSE )
else ( )
set ( create_static_plugin TRUE )
endif ( )
# Explicit option takes priority over the computed default.
if ( arg_STATIC )
set ( create_static_plugin TRUE )
elseif ( arg_SHARED )
set ( create_static_plugin FALSE )
endif ( )
if ( create_static_plugin )
2020-04-21 11:28:57 +00:00
add_library ( ${ target } STATIC )
2021-03-23 04:48:56 +00:00
target_compile_definitions ( ${ target } PRIVATE QT_STATICPLUGIN )
2020-04-21 11:28:57 +00:00
else ( )
add_library ( ${ target } MODULE )
if ( APPLE )
# CMake defaults to using .so extensions for loadable modules, aka plugins,
# but Qt plugins are actually suffixed with .dylib.
set_property ( TARGET "${target}" PROPERTY SUFFIX ".dylib" )
endif ( )
2021-03-23 04:48:56 +00:00
_qt_internal_apply_win_prefix_and_suffix ( ${ target } )
2020-04-21 11:28:57 +00:00
endif ( )
set ( output_name ${ target } )
if ( arg_OUTPUT_NAME )
set ( output_name ${ arg_OUTPUT_NAME } )
endif ( )
set_property ( TARGET "${target}" PROPERTY OUTPUT_NAME "${output_name}" )
if ( ANDROID )
2020-10-26 12:47:49 +00:00
qt6_android_apply_arch_suffix ( "${target}" )
2020-04-21 11:28:57 +00:00
set_target_properties ( ${ target }
P R O P E R T I E S
L I B R A R Y _ O U T P U T _ N A M E " p l u g i n s _ $ { a r g _ T Y P E } _ $ { o u t p u t _ n a m e } "
)
endif ( )
2020-04-28 12:07:29 +00:00
# Derive the class name from the target name if it's not explicitly specified.
2021-03-23 04:48:56 +00:00
# Don't set it for qml plugins though.
2020-04-28 12:07:29 +00:00
set ( plugin_class_name "" )
2021-03-23 04:48:56 +00:00
if ( NOT "${arg_TYPE}" STREQUAL "qml_plugin" )
if ( NOT arg_CLASS_NAME )
set ( plugin_class_name "${target}" )
else ( )
set ( plugin_class_name "${arg_CLASS_NAME}" )
endif ( )
2020-04-28 12:07:29 +00:00
endif ( )
set_target_properties ( ${ target } PROPERTIES QT_PLUGIN_CLASS_NAME "${plugin_class_name}" )
2020-04-21 11:28:57 +00:00
target_compile_definitions ( ${ target } PRIVATE
Q T _ P L U G I N
Q T _ D E P R E C A T E D _ W A R N I N G S
)
endfunction ( )
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_plugin )
2020-10-15 15:09:29 +00:00
qt6_add_plugin ( ${ ARGV } )
2020-04-21 11:28:57 +00:00
endfunction ( )
endif ( )
2020-05-12 12:57:23 +00:00
# By default Qt6 forces usage of utf8 sources for consumers of Qt.
# Users can opt out of utf8 sources by calling this function with the target name of their
# application or library.
2020-10-14 11:20:55 +00:00
function ( qt6_allow_non_utf8_sources target )
2020-05-12 12:57:23 +00:00
set_target_properties ( "${target}" PROPERTIES QT_NO_UTF8_SOURCE TRUE )
endfunction ( )
CMake: Don't use std=gnu++11 when building Qt internal targets
The logic is a bit involved in qmake.
The Qt internal qt_common.prf adds CONFIG += strict_c++ which applies
to qt modules, qt plugins, qml plugins, qt helper libs, winmain and
qt_apps, qt_tools, but NOT tests (which is important because the tests
on Windows MinGW fail to build without the GNU extensions).
Then default_post.prf checks for the strict_c++ value and either uses
the strict or non-strict C++ standard flags. default_post.prf is
loaded for all qmake projects, not just the Qt internal ones.
Now CMake doesn't provide a transitive based option to disable C++
GNU extensions with a mechanism similar to target_compile_features.
It only provides the CXX_EXTENSIONS property and it's associated
CMAKE_CXX_EXTENSIONS variable. We can't set the variable at a
directory scope, because that is too coarse grained.
So we rely on setting the property via a function in every relevant
qt_add_<target> function.
Now the naming of the function is weird.
We name the function as qt_internal_<...>, because it's not meant to be
used by Qt users.
We prepend an underscore to the name because we need to place it in
Qt6CoreMacros, so that the function can be called by
qt_add_qml_module which IS a public function.
That's because in Qt5 load(qml_plugin) was private API, but in Qt 6 +
CMake we decided to make qt_add_qml_module() as public API.
Change-Id: Id014626b087d590e25cb46843f93d0c67fc36e44
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-06-04 09:29:00 +00:00
2020-10-01 08:58:02 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
2020-10-14 11:20:55 +00:00
function ( qt_allow_non_utf8_sources )
qt6_allow_non_utf8_sources ( ${ ARGV } )
2020-10-01 08:58:02 +00:00
endfunction ( )
endif ( )
CMake: Don't use std=gnu++11 when building Qt internal targets
The logic is a bit involved in qmake.
The Qt internal qt_common.prf adds CONFIG += strict_c++ which applies
to qt modules, qt plugins, qml plugins, qt helper libs, winmain and
qt_apps, qt_tools, but NOT tests (which is important because the tests
on Windows MinGW fail to build without the GNU extensions).
Then default_post.prf checks for the strict_c++ value and either uses
the strict or non-strict C++ standard flags. default_post.prf is
loaded for all qmake projects, not just the Qt internal ones.
Now CMake doesn't provide a transitive based option to disable C++
GNU extensions with a mechanism similar to target_compile_features.
It only provides the CXX_EXTENSIONS property and it's associated
CMAKE_CXX_EXTENSIONS variable. We can't set the variable at a
directory scope, because that is too coarse grained.
So we rely on setting the property via a function in every relevant
qt_add_<target> function.
Now the naming of the function is weird.
We name the function as qt_internal_<...>, because it's not meant to be
used by Qt users.
We prepend an underscore to the name because we need to place it in
Qt6CoreMacros, so that the function can be called by
qt_add_qml_module which IS a public function.
That's because in Qt5 load(qml_plugin) was private API, but in Qt 6 +
CMake we decided to make qt_add_qml_module() as public API.
Change-Id: Id014626b087d590e25cb46843f93d0c67fc36e44
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-06-04 09:29:00 +00:00
function ( _qt_internal_apply_strict_cpp target )
# Disable C, Obj-C and C++ GNU extensions aka no "-std=gnu++11".
# Similar to mkspecs/features/default_post.prf's CONFIG += strict_cpp.
# Allow opt-out via variable.
if ( NOT QT_ENABLE_CXX_EXTENSIONS )
get_target_property ( target_type "${target}" TYPE )
if ( NOT target_type STREQUAL "INTERFACE_LIBRARY" )
set_target_properties ( "${target}" PROPERTIES
C X X _ E X T E N S I O N S O F F
C _ E X T E N S I O N S O F F
O B J C _ E X T E N S I O N S O F F
O B J C X X _ E X T E N S I O N S O F F )
endif ( )
endif ( )
endfunction ( )
2021-04-23 14:23:36 +00:00
2021-04-15 10:35:46 +00:00
# Wraps a tool command with a script that contains the necessary environment for the tool to run
# correctly.
# _qt_internal_wrap_tool_command(var <SET|APPEND> <command> [args...])
# Arguments:
# APPEND Selects the 'append' mode for the out_variable argument.
# SET Selects the 'set' mode for the out_variable argument.
function ( _qt_internal_wrap_tool_command out_variable action )
set ( append FALSE )
if ( action STREQUAL "APPEND" )
set ( append TRUE )
elseif ( NOT action STREQUAL "SET" )
message ( FATAL_ERROR "Invalid action specified ${action}. Supported actions: SET, APPEND" )
endif ( )
set ( cmd COMMAND ${ QT_TOOL_COMMAND_WRAPPER_PATH } ${ ARGN } )
if ( append )
list ( APPEND ${ out_variable } ${ cmd } )
else ( )
set ( ${ out_variable } ${ cmd } )
endif ( )
set ( ${ out_variable } "${${out_variable}}" PARENT_SCOPE )
endfunction ( )
2021-04-23 14:23:36 +00:00
# Copies properties of the dependency to the target.
# Arguments:
# PROPERTIES list of properties to copy. If not specified the following properties are copied
# by default: INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES COMPILE_DEFINITIONS
# COMPILE_OPTIONS COMPILE_FEATURES
# PRIVATE_ONLY copy only private properties (without INTERFACE analogues). Optional.
# INTERFACE_ONLY copy only interface properties (without non-prefixed analogues). Optional.
# Note: Not all properties have INTERFACE properties analogues.
# See https://cmake.org/cmake/help/latest/prop_tgt/EXPORT_PROPERTIES.html for details.
#
# PRIVATE_ONLY and INTERFACE_ONLY in the same call are not allowed. Omit these options to copy
# both sets.
function ( _qt_internal_copy_dependency_properties target dependency )
cmake_parse_arguments ( arg "INTERFACE_ONLY;PRIVATE_ONLY" "" "PROPERTIES" ${ ARGN } )
if ( arg_PRIVATE_ONLY AND arg_INTERFACE_ONLY )
message ( " Both PRIVATE_ONLY and INTERFACE_ONLY options are set.\
P l e a s e u s e _ q t _ i n t e r n a l _ c o p y _ d e p e n d e n c y _ p r o p e r t i e s w i t h o u t t h e s e o p t i o n s t o c o p y a s e t o f
p r o p e r t i e s o f b o t h t y p e s . "
)
endif ( )
if ( arg_PROPERTIES )
set ( common_props_to_set ${ arg_PROPERTIES } )
else ( )
set ( common_props_to_set
I N C L U D E _ D I R E C T O R I E S S Y S T E M _ I N C L U D E _ D I R E C T O R I E S
C O M P I L E _ D E F I N I T I O N S C O M P I L E _ O P T I O N S
C O M P I L E _ F E A T U R E S
)
endif ( )
set ( props_to_set "" )
if ( NOT arg_INTERFACE_ONLY )
set ( props_to_set ${ common_props_to_set } )
endif ( )
if ( NOT arg_PRIVATE_ONLY )
list ( TRANSFORM common_props_to_set PREPEND INTERFACE_
O U T P U T _ V A R I A B L E i n t e r f a c e _ p r o p e r t i e s )
list ( APPEND props_to_set ${ interface_properties } )
endif ( )
foreach ( prop ${ props_to_set } )
set_property ( TARGET
" $ { t a r g e t } " A P P E N D P R O P E R T Y
$ { p r o p } " $ < T A R G E T _ P R O P E R T Y : $ { d e p e n d e n c y } , $ { p r o p } > "
)
endforeach ( )
endfunction ( )