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
# macro used to create the names of output files preserving relative dirs
2019-09-19 06:45:21 +00:00
macro ( qt6_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 ( )
2019-09-19 06:45:21 +00:00
macro ( qt6_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
2019-09-19 06:45:21 +00:00
function ( qt6_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
2019-08-23 09:39:30 +00:00
qt6_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 ( )
2019-08-23 09:39:30 +00:00
qt6_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
2019-08-23 09:39:30 +00:00
qt6_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 )
2019-08-23 09:39:30 +00:00
qt6_make_output_file ( ${ it } moc_ cpp outfile )
qt6_create_moc_command ( ${ it } ${ outfile } "${moc_flags}" "${moc_options}" "${moc_target}" "${moc_depends}" )
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.
2019-08-23 09:39:30 +00:00
qt6_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 )
2018-05-18 10:19:38 +00:00
set_source_files_properties ( ${ infile } PROPERTIES SKIP_AUTORCC ON )
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 } )
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 ( )
2020-01-22 12:47:08 +00:00
set ( _Qt6_COMPONENT_PATH "${CMAKE_CURRENT_LIST_DIR}/.." )
2018-06-14 12:50:39 +00:00
2019-06-11 13:46:31 +00:00
function ( add_qt_gui_executable target )
2019-06-12 08:21:40 +00:00
if ( ANDROID )
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 )
2019-08-30 09:34:23 +00:00
qt_android_apply_arch_suffix ( "${target}" )
2019-06-12 08:21:40 +00:00
else ( )
add_executable ( "${target}" WIN32 MACOSX_BUNDLE ${ ARGN } )
endif ( )
2019-09-19 12:35:00 +00:00
target_link_libraries ( "${target}" PRIVATE Qt::Core )
if ( TARGET Qt::Gui )
target_link_libraries ( "${target}" PRIVATE Qt::Gui )
endif ( )
2019-06-11 13:46:31 +00:00
2020-02-21 15:32:13 +00:00
if ( WIN32 )
2020-03-05 11:23:26 +00:00
qt6_generate_win32_rc_file ( ${ target } )
2020-02-21 15:32:13 +00:00
endif ( )
2019-06-12 08:21:40 +00:00
if ( ANDROID )
qt_android_generate_deployment_settings ( "${target}" )
2019-10-22 14:19:13 +00:00
qt_android_add_apk_target ( "${target}" )
2019-06-12 08:21:40 +00:00
endif ( )
2019-06-11 13:46:31 +00:00
endfunction ( )
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 ( )
# 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 } )
set_target_properties ( ${ target } PROPERTIES QT_DEFAULT_PLUGINS 0 )
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.
_qt_get_plugin_name_with_version ( "${_arg}" qt_plugin_with_version )
if ( TARGET "${_arg}" OR TARGET "${qt_plugin_with_version}" )
2019-09-23 14:57:06 +00:00
set_property ( TARGET "${target}" APPEND PROPERTY "QT_PLUGINS_${_current_type}" "${_arg}" )
else ( )
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 ( )
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
2020-01-27 13:56:40 +00:00
2020-02-03 15:52:18 +00:00
# Generate Qt metatypes.json for a target. By default we check whether AUTOMOC
# has been enabled and we extract the information from that target. Should you
# not wish to use automoc you need to pass in all the generated json files via the
# 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,
# defaults to a ${CMAKE_INSTALL_PREFIX}/lib/metatypes directory.
# 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.
2019-11-26 09:10:55 +00:00
function ( qt6_generate_meta_types_json_file target )
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 )
set ( arg_INSTALL_DIR "lib/metatypes" )
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 )
function ( qt_generate_meta_types_json_file )
qt6_generate_meta_types_json_file ( ${ ARGV } )
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.
function ( qt6_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 ( )
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-02-21 15:32:13 +00:00
2020-05-04 19:55:40 +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.
2020-05-11 12:51:33 +00:00
add_library ( ${ target } _ ${ cfg } _rc OBJECT "${output}" )
2020-05-04 19:55:40 +00:00
target_link_libraries ( ${ target } PRIVATE "$<$<CONFIG:${cfg}>:${target}_${cfg}_rc>" )
endwhile ( )
endif ( )
2020-02-21 15:32:13 +00:00
endfunction ( )
2020-04-17 12:36:09 +00:00
2020-10-01 08:58:02 +00:00
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_generate_win32_rc_file )
qt6_generate_win32_rc_file ( ${ ARGV } )
endfunction ( )
endif ( )
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 )
set ( resource_target "${target}_resources_${resourceName}" )
add_library ( "${resource_target}" OBJECT "${generated_source_code}" )
2020-06-16 08:39:01 +00:00
set_property ( TARGET ${ resource_target } APPEND PROPERTY QT_RESOURCE_NAME ${ resourceName } )
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
# as well.
target_link_libraries ( ${ 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 } > > " )
set ( ${ output_generated_target } "${resource_target}" PARENT_SCOPE )
else ( )
set ( ${ output_generated_target } "" PARENT_SCOPE )
target_sources ( ${ target } PRIVATE ${ generated_source_code } )
endif ( )
endfunction ( )
#
# 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
cmake_parse_arguments ( rcc "" "PREFIX;LANG;BASE;OUTPUT_TARGETS" "FILES;OPTIONS" ${ ARGN } )
string ( REPLACE "/" "_" resourceName ${ resourceName } )
string ( REPLACE "." "_" resourceName ${ resourceName } )
set ( output_targets "" )
# Apply base to all files
if ( rcc_BASE )
foreach ( file IN LISTS rcc_FILES )
set ( resource_file "${rcc_BASE}/${file}" )
__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 QT_RESOURCE_ALIAS ${ file } )
endif ( )
file ( TO_CMAKE_PATH ${ resource_file } resource_file )
list ( APPEND resource_files ${ resource_file } )
endforeach ( )
else ( )
set ( resource_files ${ rcc_FILES } )
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 )
qt6_quick_compiler_process_resources ( ${ target } ${ resourceName }
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 } )
set ( generatedResourceFile "${CMAKE_CURRENT_BINARY_DIR}/.rcc/generated_${newResourceName}.qrc" )
set ( generatedSourceCode "${CMAKE_CURRENT_BINARY_DIR}/.rcc/qrc_${newResourceName}.cpp" )
# 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 ( )
endforeach ( )
# </qresource></RCC>
string ( APPEND qrcContents " </qresource>\n</RCC>\n" )
file ( GENERATE OUTPUT "${generatedResourceFile}" CONTENT "${qrcContents}" )
set ( rccArgs --name "${newResourceName}"
- - 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 } " )
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 ( )
# Process .qrc file:
add_custom_command ( OUTPUT "${generatedSourceCode}"
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 A r g s }
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 )
get_target_property ( type "${target}" TYPE )
# 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 } "${generatedSourceCode}" output_target )
list ( APPEND output_targets ${ output_target } )
else ( )
target_sources ( ${ target } PRIVATE "${generatedSourceCode}" )
endif ( )
if ( rcc_OUTPUT_TARGETS )
set ( ${ rcc_OUTPUT_TARGETS } "${output_targets}" PARENT_SCOPE )
endif ( )
endfunction ( )
2020-04-21 11:28:57 +00:00
function ( qt6_add_plugin target )
cmake_parse_arguments ( arg
" S T A T I C "
2020-09-23 11:36:07 +00:00
" O U T P U T _ N A M E ; C L A S S _ N A M E ; T Y P E "
2020-04-21 11:28:57 +00:00
" "
$ { A R G N }
)
if ( arg_STATIC )
add_library ( ${ target } STATIC )
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 ( )
2020-05-29 10:08:01 +00:00
if ( WIN32 )
# CMake sets for Windows-GNU platforms the suffix "lib"
set_property ( TARGET "${target}" PROPERTY PREFIX "" )
endif ( )
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 )
qt_android_apply_arch_suffix ( "${target}" )
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.
set ( plugin_class_name "" )
if ( NOT arg_CLASS_NAME )
set ( plugin_class_name "${target}" )
else ( )
set ( plugin_class_name "${arg_CLASS_NAME}" )
endif ( )
set_target_properties ( ${ target } PROPERTIES QT_PLUGIN_CLASS_NAME "${plugin_class_name}" )
2020-04-21 11:28:57 +00:00
set ( static_plugin_define "" )
if ( arg_STATIC )
set ( static_plugin_define "QT_STATICPLUGIN" )
endif ( )
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
$ { s t a t i c _ p l u g i n _ d e f i n e }
)
endfunction ( )
if ( NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS )
function ( qt_add_plugin )
if ( NOT DEFINED QT_DISABLE_QT_ADD_PLUGIN_COMPATIBILITY
O R N O T Q T _ D I S A B L E _ Q T _ A D D _ P L U G I N _ C O M P A T I B I L I T Y )
qt_internal_add_plugin ( ${ ARGV } )
else ( )
qt6_add_plugin ( ${ ARGV } )
endif ( )
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-01 08:58:02 +00:00
function ( qt6_disable_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 )
function ( qt_disable_utf8_sources )
qt6_disable_utf8_sources ( ${ ARGV } )
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 ( )