summaryrefslogtreecommitdiffstats
path: root/Modules/Qt4Macros.cmake
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-02-26 22:27:22 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-06-03 08:07:02 (GMT)
commit9ce60ff509c4ff27fe861fc5b2080f50897a68c4 (patch)
tree36d4973eef51233452e1ebd822f395647868f25a /Modules/Qt4Macros.cmake
parenta4d8c64d10105fd4448ffde6a5d2fb74c1bb4f57 (diff)
downloadCMake-9ce60ff509c4ff27fe861fc5b2080f50897a68c4.zip
CMake-9ce60ff509c4ff27fe861fc5b2080f50897a68c4.tar.gz
CMake-9ce60ff509c4ff27fe861fc5b2080f50897a68c4.tar.bz2
Qt4Macros: Allow specifying a TARGET in invokations of macros.
That will allow things like this: find_package(Qt4) qt4_generate_moc(myfile.h moc_myfile.cpp TARGET foo) # Note, foo target doesn't # exist until below. add_library(foo ...) The qt4_generate_moc call would use the INCLUDE_DIRECTORIES from the foo target using generator expressions. Currently it reads the INCLUDE_DIRECTORIES directory property, meaning that include_directories() is required. Support for the TARGET is also added to qt4_wrap_cpp, but not qt4_automoc, as that is deprecated in favor of the AUTOMOC target property. The moc tool reports failure if the Q_INTERFACES macro is used with an argument which has not appeared with Q_DECLARE_INTERFACE, so that is the basis of the unit test. The command line arguments are now always written to a file, which is passed to moc as the @atfile. This was already the case on Windows, but now it is used everywhere. The reason for that is that it is not currently possible to expand the list of includes from a target directly in a add_custom_command invokation (though that may become possible in the future). There is not a big disadvantage to using the file anyway on unix, so having one code path instead of two is also a motivation.
Diffstat (limited to 'Modules/Qt4Macros.cmake')
-rw-r--r--Modules/Qt4Macros.cmake100
1 files changed, 62 insertions, 38 deletions
diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake
index 251d57c..7d7f5aa 100644
--- a/Modules/Qt4Macros.cmake
+++ b/Modules/Qt4Macros.cmake
@@ -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_options})
set(_QT4_DOING_OPTIONS FALSE)
+ set(_QT4_DOING_TARGET FALSE)
foreach(_currentArg ${ARGN})
- if ("${_currentArg}" STREQUAL "OPTIONS")
+ if ("x${_currentArg}" STREQUAL "xOPTIONS")
set(_QT4_DOING_OPTIONS TRUE)
+ elseif ("x${_currentArg}" STREQUAL "xTARGET")
+ set(_QT4_DOING_TARGET TRUE)
else ()
- if(_QT4_DOING_OPTIONS)
+ if(_QT4_DOING_TARGET)
+ set(${_qt4_target} "${_currentArg}")
+ elseif(_QT4_DOING_OPTIONS)
list(APPEND ${_qt4_options} "${_currentArg}")
else()
list(APPEND ${_qt4_files} "${_currentArg}")
@@ -92,34 +97,49 @@ endmacro()
# 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
- if (WIN32)
- # 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}")
- file (WRITE ${_moc_parameters_file} "${_moc_parameters}")
- add_custom_command(OUTPUT ${outfile}
- COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters
- DEPENDS ${infile}
- ${_moc_working_dir}
- VERBATIM)
- else ()
- add_custom_command(OUTPUT ${outfile}
- COMMAND ${QT_MOC_EXECUTABLE}
- ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile}
- DEPENDS ${infile} VERBATIM)
- endif ()
+ # 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}")
+
+ 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}
+ COMMAND ${QT_MOC_EXECUTABLE} ${_moc_extra_parameters_file}
+ DEPENDS ${infile}
+ ${_moc_working_dir}
+ VERBATIM)
endmacro ()
@@ -131,7 +151,11 @@ macro (QT4_GENERATE_MOC infile outfile )
if(NOT IS_ABSOLUTE "${outfile}")
set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
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
endmacro ()
@@ -141,12 +165,12 @@ endmacro ()
macro (QT4_WRAP_CPP outfiles )
# get include dirs
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})
get_filename_component(it ${it} ABSOLUTE)
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})
endforeach()
@@ -156,7 +180,7 @@ endmacro ()
# QT4_WRAP_UI(outfiles inputfile ... )
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})
get_filename_component(outfile ${it} NAME_WE)
@@ -175,7 +199,7 @@ endmacro ()
# QT4_ADD_RESOURCES(outfiles inputfile ... )
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})
get_filename_component(outfilename ${it} NAME_WE)
@@ -270,7 +294,7 @@ endmacro()
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(_basename ${_header} NAME_WE)
@@ -366,7 +390,7 @@ macro(QT4_AUTOMOC)
set(_header ${_abs_PATH}/${_basename}.h)
endif()
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})
endforeach ()
endif()
@@ -376,7 +400,7 @@ endmacro()
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_dirs)
set(_my_tsfiles)