@@ -957,4 +957,114 @@ function(set_once_var variable)
957957 set (CPPAN_ONCE_VARIABLES ${CPPAN_ONCE_VARIABLES} ${variable} CACHE STRING "" FORCE )
958958endfunction ()
959959
960+ ########################################
961+ # FUNCTION cppan_QT5_MAKE_OUTPUT_FILE
962+ ########################################
963+
964+ # macro used to create the names of output files preserving relative dirs
965+ macro (cppan_QT5_MAKE_OUTPUT_FILE infile prefix ext outfile )
966+ string (LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
967+ string (LENGTH ${infile} _infileLength)
968+ set (_checkinfile ${CMAKE_CURRENT_SOURCE_DIR} )
969+ if (_infileLength GREATER _binlength)
970+ string (SUBSTRING "${infile} " 0 ${_binlength} _checkinfile)
971+ if (_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR} " )
972+ file (RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile} )
973+ else ()
974+ file (RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile} )
975+ endif ()
976+ else ()
977+ file (RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile} )
978+ endif ()
979+ if (WIN32 AND rel MATCHES "^([a-zA-Z]):(.*)$" ) # absolute path
980+ set (rel "${CMAKE_MATCH_1} _${CMAKE_MATCH_2} " )
981+ endif ()
982+ set (_outfile "${CMAKE_CURRENT_BINARY_DIR} /${rel} " )
983+ string (REPLACE ".." "__" _outfile ${_outfile} )
984+ get_filename_component (outpath ${_outfile} PATH )
985+ get_filename_component (_outfile ${_outfile} NAME_WE )
986+ file (MAKE_DIRECTORY ${outpath} )
987+ set (${outfile} ${outpath} /${prefix}${_outfile} .${ext} )
988+ endmacro ()
989+
990+ ########################################
991+ # FUNCTION cppan_QT5_CREATE_MOC_COMMAND
992+ ########################################
993+
994+ # helper macro to set up a moc rule
995+ function (cppan_QT5_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target moc_depends )
996+ # Pass the parameters in a file. Set the working directory to
997+ # be that containing the parameters file and reference it by
998+ # just the file name. This is necessary because the moc tool on
999+ # MinGW builds does not seem to handle spaces in the path to the
1000+ # file given with the @ syntax.
1001+ get_filename_component (_moc_outfile_name "${outfile} " NAME )
1002+ get_filename_component (_moc_outfile_dir "${outfile} " PATH )
1003+ if (_moc_outfile_dir)
1004+ set (_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir} )
1005+ endif ()
1006+ set (_moc_parameters_file ${outfile} _parameters)
1007+ set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile} " "${infile} " )
1008+ string (REPLACE ";" "\n " _moc_parameters "${_moc_parameters} " )
1009+
1010+ if (moc_target)
1011+ set (_moc_parameters_file ${_moc_parameters_file} $<$<BOOL :$<CONFIGURATION >>:_ $<CONFIGURATION >>)
1012+ set (targetincludes "$<TARGET_PROPERTY :${moc_target} ,INCLUDE_DIRECTORIES >" )
1013+ set (targetdefines "$<TARGET_PROPERTY :${moc_target} ,COMPILE_DEFINITIONS >" )
1014+
1015+ set (targetincludes "$<$<BOOL :${targetincludes} >:-I $<JOIN :${targetincludes} ,\n -I >\n >" )
1016+ set (targetdefines "$<$<BOOL :${targetdefines} >:-D $<JOIN :${targetdefines} ,\n -D >\n >" )
1017+
1018+ file (GENERATE
1019+ OUTPUT ${_moc_parameters_file}
1020+ CONTENT "${targetdefines}${targetincludes}${_moc_parameters} \n "
1021+ )
1022+
1023+ set (targetincludes)
1024+ set (targetdefines)
1025+ else ()
1026+ file (WRITE ${_moc_parameters_file} "${_moc_parameters} \n " )
1027+ endif ()
1028+
1029+ set (_moc_extra_parameters_file @${_moc_parameters_file} )
1030+ file (APPEND ${BDIR} /moc.list "\" ${_moc_working_dir} \" \" ${Qt5Core_MOC_EXECUTABLE} \" \" ${_moc_extra_parameters_file} \"\n " )
1031+ set_source_files_properties (${infile} PROPERTIES SKIP_AUTOMOC ON )
1032+ set_source_files_properties (${outfile} PROPERTIES SKIP_AUTOMOC ON )
1033+ set_source_files_properties (${outfile} PROPERTIES SKIP_AUTOUIC ON )
1034+ endfunction ()
1035+
1036+ ########################################
1037+ # FUNCTION cppan_QT5_WRAP_CPP
1038+ ########################################
1039+
1040+ function (cppan_QT5_WRAP_CPP outfiles )
1041+ # get include dirs
1042+ qt5_get_moc_flags (moc_flags )
1043+
1044+ set (options)
1045+ set (oneValueArgs TARGET)
1046+ set (multiValueArgs OPTIONS DEPENDS)
1047+
1048+ cmake_parse_arguments (_WRAP_CPP "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
1049+
1050+ set (moc_files ${_WRAP_CPP_UNPARSED_ARGUMENTS} )
1051+ set (moc_options ${_WRAP_CPP_OPTIONS} )
1052+ set (moc_target ${_WRAP_CPP_TARGET} )
1053+ set (moc_depends ${_WRAP_CPP_DEPENDS} )
1054+
1055+ if (moc_target AND CMAKE_VERSION VERSION_LESS 2.8.12)
1056+ message (FATAL_ERROR "The TARGET parameter to qt5_wrap_cpp is only available when using CMake 2.8.12 or later." )
1057+ endif ()
1058+ foreach (it ${moc_files} )
1059+ get_filename_component (it ${it} ABSOLUTE )
1060+ cppan_qt5_make_output_file (${it} moc_ cpp outfile )
1061+ cppan_qt5_create_moc_command (${it} ${outfile} "${moc_flags} " "${moc_options} " "${moc_target} " "${moc_depends} " )
1062+ list (APPEND ${outfiles} ${outfile} )
1063+ endforeach ()
1064+ add_custom_command (OUTPUT ${outfiles}
1065+ COMMAND ${CPPAN_COMMAND} internal -parallel-moc ${BDIR} /moc.list
1066+ DEPENDS ${moc_files} ${moc_depends} )
1067+ set (${outfiles} ${${outfiles} } PARENT_SCOPE )
1068+ endfunction ()
1069+
9601070################################################################################
0 commit comments