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 )
get_filename_component ( _outfile ${ _outfile } NAME_WE )
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-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
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 }
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 }
2017-09-29 21:53:29 +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 } $ { 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-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 } )
2019-09-19 06:45:21 +00:00
qt6_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 }
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 } " V E R B A T I M )
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-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 }
2018-05-18 10:19:38 +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 } " V E R B A T I M )
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 }
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 }
V E R B A T I M )
list ( APPEND ${ outfiles } ${ outfile } )
endforeach ( )
set ( ${ outfiles } ${ ${outfiles } } PARENT_SCOPE )
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-01-22 12:47:08 +00:00
macro ( qt6_use_modules _target _link_type )
2019-11-08 16:24:30 +00:00
if ( CMAKE_WARN_DEPRECATED )
set ( messageType WARNING )
endif ( )
if ( CMAKE_ERROR_DEPRECATED )
set ( messageType FATAL_ERROR )
endif ( )
if ( messageType )
2020-01-22 12:47:08 +00:00
message ( ${ messageType } "The qt6_use_modules macro is obsolete. Use target_link_libraries with IMPORTED targets instead." )
2019-11-08 16:24:30 +00:00
endif ( )
2018-06-14 12:50:39 +00:00
2019-11-08 16:24:30 +00:00
if ( NOT TARGET ${ _target } )
2020-01-22 12:47:08 +00:00
message ( FATAL_ERROR "The first argument to qt6_use_modules must be an existing target." )
2019-11-08 16:24:30 +00:00
endif ( )
if ( "${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE" )
2020-01-22 12:47:08 +00:00
set ( _qt6_modules ${ ARGN } )
set ( _qt6_link_type ${ _link_type } )
2019-11-08 16:24:30 +00:00
else ( )
2020-01-22 12:47:08 +00:00
set ( _qt6_modules ${ _link_type } ${ ARGN } )
2019-11-08 16:24:30 +00:00
endif ( )
2018-06-14 12:50:39 +00:00
2020-01-22 12:47:08 +00:00
if ( "${_qt6_modules}" STREQUAL "" )
message ( FATAL_ERROR "qt6_use_modules requires at least one Qt module to use." )
2019-11-08 16:24:30 +00:00
endif ( )
2018-06-14 12:50:39 +00:00
2020-01-22 12:47:08 +00:00
foreach ( _module ${ _qt6_modules } )
if ( NOT Qt6 ${ _module } _FOUND )
find_package ( Qt6 ${ _module } PATHS "${_Qt6_COMPONENT_PATH}" NO_DEFAULT_PATH )
if ( NOT Qt6 ${ _module } _FOUND )
2019-11-08 16:24:30 +00:00
message ( FATAL_ERROR "Cannot use \" ${ _module } \" module which has not yet been found. " )
2018-06-14 12:50:39 +00:00
endif ( )
2019-11-08 16:24:30 +00:00
endif ( )
2020-01-22 12:47:08 +00:00
target_link_libraries ( ${ _target } ${ _qt6_link_type } ${ Qt6${_module } _LIBRARIES} )
set_property ( TARGET ${ _target } APPEND PROPERTY INCLUDE_DIRECTORIES ${ Qt6${_module } _INCLUDE_DIRS} )
set_property ( TARGET ${ _target } APPEND PROPERTY COMPILE_DEFINITIONS ${ Qt6${_module } _COMPILE_DEFINITIONS} )
2019-11-08 16:24:30 +00:00
set_property ( TARGET ${ _target } APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG )
set_property ( TARGET ${ _target } APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO QT_NO_DEBUG )
set_property ( TARGET ${ _target } APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL QT_NO_DEBUG )
2020-01-22 12:47:08 +00:00
if ( Qt6_POSITION_INDEPENDENT_CODE
AND ( NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
O R C M A K E _ C X X _ C O M P I L E R _ V E R S I O N V E R S I O N _ L E S S 5 . 0 ) )
set_property ( TARGET ${ _target } PROPERTY POSITION_INDEPENDENT_CODE ${ Qt6_POSITION_INDEPENDENT_CODE } )
2019-11-08 16:24:30 +00:00
endif ( )
endforeach ( )
endmacro ( )
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 )
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
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 ( )
2019-06-07 07:13:31 +00:00
macro ( _qt_import_plugin target plugin )
get_target_property ( plugin_class_name "${plugin}" QT_PLUGIN_CLASS_NAME )
if ( plugin_class_name )
set_property ( TARGET "${target}" APPEND PROPERTY QT_PLUGINS "${plugin}" )
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.
function ( qt_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 ( )
if ( TARGET "${_arg}" )
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
function ( qt6_import_plugins TARGET_NAME )
2018-10-17 20:03:28 +00:00
set ( _doing "" )
foreach ( _arg ${ ARGN } )
if ( _arg STREQUAL "INCLUDE" )
set ( _doing "INCLUDE" )
elseif ( _arg STREQUAL "EXCLUDE" )
set ( _doing "EXCLUDE" )
elseif ( _arg STREQUAL "INCLUDE_BY_TYPE" )
set ( _doing "INCLUDE_BY_TYPE" )
elseif ( _arg STREQUAL "EXCLUDE_BY_TYPE" )
set ( _doing "EXCLUDE_BY_TYPE" )
else ( )
if ( _doing STREQUAL "INCLUDE" )
set_property ( TARGET ${ TARGET_NAME } APPEND PROPERTY QT_PLUGINS "${_arg}" )
elseif ( _doing STREQUAL "EXCLUDE" )
set_property ( TARGET ${ TARGET_NAME } APPEND PROPERTY QT_NO_PLUGINS "${_arg}" )
elseif ( _doing STREQUAL "INCLUDE_BY_TYPE" )
string ( REGEX REPLACE "[-/]" "_" _plugin_type "${_arg}" )
set ( _doing "INCLUDE_BY_TYPE_PLUGINS" )
elseif ( _doing STREQUAL "INCLUDE_BY_TYPE_PLUGINS" )
set_property ( TARGET ${ TARGET_NAME } APPEND PROPERTY "QT_PLUGINS_${_plugin_type}" "${_arg}" )
elseif ( _doing STREQUAL "EXCLUDE_BY_TYPE" )
string ( REGEX REPLACE "[-/]" "_" _plugin_type "${_arg}" )
set_property ( TARGET ${ TARGET_NAME } PROPERTY "QT_PLUGINS_${_plugin_type}" - )
set ( _doing "" )
else ( )
message ( FATAL_ERROR "Unexpected extra argument: \" ${ _arg } \"")
endif ( )
endif ( )
endforeach ( )
endfunction ( )
2019-11-26 09:10:55 +00:00
function ( qt6_generate_meta_types_json_file target )
get_target_property ( target_type ${ target } TYPE )
if ( target_type STREQUAL "INTERFACE_LIBRARY" OR CMAKE_VERSION VERSION_LESS "3.16.0" )
# interface libraries not supported or cmake version is not high enough
message ( WARNING "Meta types generation requires CMake >= 3.16" )
return ( )
endif ( )
get_target_property ( existing_meta_types_file ${ target } QT_MODULE_META_TYPES_FILE )
if ( existing_meta_types_file )
return ( )
endif ( )
get_target_property ( target_binary_dir ${ target } BINARY_DIR )
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 ( 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 " )
set ( type_list_file "${target_binary_dir}/meta_types/json_file_list.txt" )
add_custom_target ( ${ target } _automoc_json_extraction
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 } "
- - 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 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 "
)
add_dependencies ( ${ target } _automoc_json_extraction ${ target } _autogen )
if ( CMAKE_BUILD_TYPE )
string ( TOLOWER ${ target } _ ${ CMAKE_BUILD_TYPE } target_lowercase )
else ( )
message ( FATAL_ERROR "add_custom_command's OUTPUT parameter does not support generator expressions, so we can't generate this file for multi-config generators" )
endif ( )
set ( metatypes_file "${target_binary_dir}/meta_types/qt6${target_lowercase}_metatypes.json" )
add_custom_command ( OUTPUT ${ metatypes_file }
D E P E N D 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 } : : m o c
- o $ { m e t a t y p e s _ f i l e }
- - c o l l e c t - j s o n " @ $ { t y p e _ l i s t _ f i l e } "
C O M M E N T " R u 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 "
)
target_sources ( ${ target } PRIVATE ${ metatypes_file } )
set_source_files_properties ( ${ metatypes_file } PROPERTIES HEADER_FILE_ONLY TRUE )
set_target_properties ( ${ target } PROPERTIES
Q T _ M O D U L E _ M E T A _ T Y P E S _ F I L E $ { m e t a t y p e s _ f i l e }
)
endfunction ( )