Merge topic 'qt4-macros-TARGET-arg'
9ce60ff
Qt4Macros: Allow specifying a TARGET in invokations of macros.
This commit is contained in:
commit
b418327d1b
|
@ -21,15 +21,20 @@
|
||||||
######################################
|
######################################
|
||||||
|
|
||||||
|
|
||||||
macro (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options)
|
macro (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options _qt4_target)
|
||||||
set(${_qt4_files})
|
set(${_qt4_files})
|
||||||
set(${_qt4_options})
|
set(${_qt4_options})
|
||||||
set(_QT4_DOING_OPTIONS FALSE)
|
set(_QT4_DOING_OPTIONS FALSE)
|
||||||
|
set(_QT4_DOING_TARGET FALSE)
|
||||||
foreach(_currentArg ${ARGN})
|
foreach(_currentArg ${ARGN})
|
||||||
if ("${_currentArg}" STREQUAL "OPTIONS")
|
if ("x${_currentArg}" STREQUAL "xOPTIONS")
|
||||||
set(_QT4_DOING_OPTIONS TRUE)
|
set(_QT4_DOING_OPTIONS TRUE)
|
||||||
|
elseif ("x${_currentArg}" STREQUAL "xTARGET")
|
||||||
|
set(_QT4_DOING_TARGET TRUE)
|
||||||
else ()
|
else ()
|
||||||
if(_QT4_DOING_OPTIONS)
|
if(_QT4_DOING_TARGET)
|
||||||
|
set(${_qt4_target} "${_currentArg}")
|
||||||
|
elseif(_QT4_DOING_OPTIONS)
|
||||||
list(APPEND ${_qt4_options} "${_currentArg}")
|
list(APPEND ${_qt4_options} "${_currentArg}")
|
||||||
else()
|
else()
|
||||||
list(APPEND ${_qt4_files} "${_currentArg}")
|
list(APPEND ${_qt4_files} "${_currentArg}")
|
||||||
|
@ -92,9 +97,8 @@ endmacro()
|
||||||
|
|
||||||
|
|
||||||
# helper macro to set up a moc rule
|
# helper macro to set up a moc rule
|
||||||
macro (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options)
|
macro (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
|
||||||
# For Windows, create a parameters file to work around command line length limit
|
# For Windows, create a parameters file to work around command line length limit
|
||||||
if (WIN32)
|
|
||||||
# Pass the parameters in a file. Set the working directory to
|
# Pass the parameters in a file. Set the working directory to
|
||||||
# be that containing the parameters file and reference it by
|
# be that containing the parameters file and reference it by
|
||||||
# just the file name. This is necessary because the moc tool on
|
# just the file name. This is necessary because the moc tool on
|
||||||
|
@ -108,18 +112,34 @@ macro (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options)
|
||||||
set (_moc_parameters_file ${outfile}_parameters)
|
set (_moc_parameters_file ${outfile}_parameters)
|
||||||
set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
|
set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
|
||||||
string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
|
string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
|
||||||
file (WRITE ${_moc_parameters_file} "${_moc_parameters}")
|
|
||||||
|
set(targetincludes)
|
||||||
|
set(targetdefines)
|
||||||
|
if(moc_target)
|
||||||
|
list(APPEND targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
|
||||||
|
list(APPEND 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
|
||||||
|
OUTPUT ${_moc_parameters_file}
|
||||||
|
CONTENT "${targetdefines}${targetincludes}${targetoptions}${_moc_parameters}\n"
|
||||||
|
CONDITION 1
|
||||||
|
)
|
||||||
|
|
||||||
|
set(targetincludes)
|
||||||
|
set(targetdefines)
|
||||||
|
else()
|
||||||
|
file(WRITE ${_moc_parameters_file} "${_moc_parameters}\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(_moc_extra_parameters_file @${_moc_parameters_file})
|
||||||
add_custom_command(OUTPUT ${outfile}
|
add_custom_command(OUTPUT ${outfile}
|
||||||
COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters
|
COMMAND ${QT_MOC_EXECUTABLE} ${_moc_extra_parameters_file}
|
||||||
DEPENDS ${infile}
|
DEPENDS ${infile}
|
||||||
${_moc_working_dir}
|
${_moc_working_dir}
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
else ()
|
|
||||||
add_custom_command(OUTPUT ${outfile}
|
|
||||||
COMMAND ${QT_MOC_EXECUTABLE}
|
|
||||||
ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile}
|
|
||||||
DEPENDS ${infile} VERBATIM)
|
|
||||||
endif ()
|
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +151,11 @@ macro (QT4_GENERATE_MOC infile outfile )
|
||||||
if(NOT IS_ABSOLUTE "${outfile}")
|
if(NOT IS_ABSOLUTE "${outfile}")
|
||||||
set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
|
set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
|
||||||
endif()
|
endif()
|
||||||
QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "")
|
|
||||||
|
if ("x${ARGV2}" STREQUAL "xTARGET")
|
||||||
|
set(moc_target ${ARGV3})
|
||||||
|
endif()
|
||||||
|
QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
|
||||||
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file
|
set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
|
@ -141,12 +165,12 @@ endmacro ()
|
||||||
macro (QT4_WRAP_CPP outfiles )
|
macro (QT4_WRAP_CPP outfiles )
|
||||||
# get include dirs
|
# get include dirs
|
||||||
QT4_GET_MOC_FLAGS(moc_flags)
|
QT4_GET_MOC_FLAGS(moc_flags)
|
||||||
QT4_EXTRACT_OPTIONS(moc_files moc_options ${ARGN})
|
QT4_EXTRACT_OPTIONS(moc_files moc_options moc_target ${ARGN})
|
||||||
|
|
||||||
foreach (it ${moc_files})
|
foreach (it ${moc_files})
|
||||||
get_filename_component(it ${it} ABSOLUTE)
|
get_filename_component(it ${it} ABSOLUTE)
|
||||||
QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
|
QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
|
||||||
QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}")
|
QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}")
|
||||||
set(${outfiles} ${${outfiles}} ${outfile})
|
set(${outfiles} ${${outfiles}} ${outfile})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
@ -156,7 +180,7 @@ endmacro ()
|
||||||
# QT4_WRAP_UI(outfiles inputfile ... )
|
# QT4_WRAP_UI(outfiles inputfile ... )
|
||||||
|
|
||||||
macro (QT4_WRAP_UI outfiles )
|
macro (QT4_WRAP_UI outfiles )
|
||||||
QT4_EXTRACT_OPTIONS(ui_files ui_options ${ARGN})
|
QT4_EXTRACT_OPTIONS(ui_files ui_options ui_target ${ARGN})
|
||||||
|
|
||||||
foreach (it ${ui_files})
|
foreach (it ${ui_files})
|
||||||
get_filename_component(outfile ${it} NAME_WE)
|
get_filename_component(outfile ${it} NAME_WE)
|
||||||
|
@ -175,7 +199,7 @@ endmacro ()
|
||||||
# QT4_ADD_RESOURCES(outfiles inputfile ... )
|
# QT4_ADD_RESOURCES(outfiles inputfile ... )
|
||||||
|
|
||||||
macro (QT4_ADD_RESOURCES outfiles )
|
macro (QT4_ADD_RESOURCES outfiles )
|
||||||
QT4_EXTRACT_OPTIONS(rcc_files rcc_options ${ARGN})
|
QT4_EXTRACT_OPTIONS(rcc_files rcc_options rcc_target ${ARGN})
|
||||||
|
|
||||||
foreach (it ${rcc_files})
|
foreach (it ${rcc_files})
|
||||||
get_filename_component(outfilename ${it} NAME_WE)
|
get_filename_component(outfilename ${it} NAME_WE)
|
||||||
|
@ -270,7 +294,7 @@ endmacro()
|
||||||
|
|
||||||
|
|
||||||
macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
|
macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
|
||||||
QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options ${ARGN})
|
QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options _qt4_dbus_target ${ARGN})
|
||||||
|
|
||||||
get_filename_component(_in_file ${_header} ABSOLUTE)
|
get_filename_component(_in_file ${_header} ABSOLUTE)
|
||||||
get_filename_component(_basename ${_header} NAME_WE)
|
get_filename_component(_basename ${_header} NAME_WE)
|
||||||
|
@ -366,7 +390,7 @@ macro(QT4_AUTOMOC)
|
||||||
set(_header ${_abs_PATH}/${_basename}.h)
|
set(_header ${_abs_PATH}/${_basename}.h)
|
||||||
endif()
|
endif()
|
||||||
set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
|
set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
|
||||||
QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "")
|
QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "" "")
|
||||||
MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
|
MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
endif()
|
endif()
|
||||||
|
@ -376,7 +400,7 @@ endmacro()
|
||||||
|
|
||||||
|
|
||||||
macro(QT4_CREATE_TRANSLATION _qm_files)
|
macro(QT4_CREATE_TRANSLATION _qm_files)
|
||||||
QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options ${ARGN})
|
QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options _lupdate_target ${ARGN})
|
||||||
set(_my_sources)
|
set(_my_sources)
|
||||||
set(_my_dirs)
|
set(_my_dirs)
|
||||||
set(_my_tsfiles)
|
set(_my_tsfiles)
|
||||||
|
|
|
@ -19,3 +19,20 @@ if (WIN32)
|
||||||
target_link_libraries(activeqtexe Qt4::QAxServer Qt4::QtGui)
|
target_link_libraries(activeqtexe Qt4::QAxServer Qt4::QtGui)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
qt4_generate_moc(main_gen_test.cpp
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc"
|
||||||
|
TARGET Qt4GenerateMacroTest
|
||||||
|
)
|
||||||
|
add_executable(Qt4GenerateMacroTest WIN32 main_gen_test.cpp "${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc")
|
||||||
|
set_property(TARGET Qt4GenerateMacroTest PROPERTY AUTOMOC OFF)
|
||||||
|
target_include_directories(Qt4GenerateMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
|
||||||
|
target_link_libraries(Qt4GenerateMacroTest Qt4::QtGui)
|
||||||
|
|
||||||
|
qt4_wrap_cpp(moc_file mywrapobject.h
|
||||||
|
TARGET Qt4WrapMacroTest
|
||||||
|
)
|
||||||
|
add_executable(Qt4WrapMacroTest WIN32 main_wrap_test.cpp ${moc_file})
|
||||||
|
set_property(TARGET Qt4WrapMacroTest PROPERTY AUTOMOC OFF)
|
||||||
|
target_include_directories(Qt4WrapMacroTest PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/interface")
|
||||||
|
target_link_libraries(Qt4WrapMacroTest Qt4::QtGui)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
#ifndef MYINTERFACE_H
|
||||||
|
#define MYINTERFACE_H
|
||||||
|
|
||||||
|
class MyInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_INTERFACE(MyInterface, "org.cmake.example.MyInterface")
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "myinterface.h"
|
||||||
|
|
||||||
|
class MyObject : public QObject, MyInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(MyInterface)
|
||||||
|
public:
|
||||||
|
explicit MyObject(QObject *parent = 0) : QObject(parent) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
MyObject mo;
|
||||||
|
mo.objectName();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "main_gen_test.moc"
|
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "mywrapobject.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
MyWrapObject mwo;
|
||||||
|
mwo.objectName();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
#ifndef MYWRAPOBJECT_H
|
||||||
|
#define MYWRAPOBJECT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "myinterface.h"
|
||||||
|
|
||||||
|
class MyWrapObject : public QObject, MyInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(MyInterface)
|
||||||
|
public:
|
||||||
|
explicit MyWrapObject(QObject *parent = 0) : QObject(parent) { }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue