Commit dbda5906 authored by Sebastian Holtermann's avatar Sebastian Holtermann

Autogen: Per-config file suffixes. New AUTOGEN_BUILD_DIR target property.

Closes #14760
Closes #14313
parent 0965002e
......@@ -119,6 +119,7 @@ Properties on Targets
/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY
/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG
/prop_tgt/ARCHIVE_OUTPUT_NAME
/prop_tgt/AUTOGEN_BUILD_DIR
/prop_tgt/AUTOGEN_TARGET_DEPENDS
/prop_tgt/AUTOMOC_DEPEND_FILTERS
/prop_tgt/AUTOMOC_MOC_OPTIONS
......
......@@ -68,14 +68,24 @@ be included by the user in the C++ implementation file with a preprocessor
``#include``.
Included ``moc_*.cpp`` and ``*.moc`` files will be generated in the
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/include`` directory which is
``<AUTOGEN_BUILD_DIR>/include`` directory which is
automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
(This differs from CMake 3.7 and below; see their documentation for details.)
* For multi configuration generators, except Xcode, the include directory is
``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
Not included ``moc_<basename>.cpp`` files will be generated in custom
folders to avoid name collisions and included in a separate
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/moc_compilation.cpp``
file which is compiled into the target.
``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file which is compiled
into the target.
* For multi configuration generators, except Xcode, the file is
``<AUTOGEN_BUILD_DIR>/mocs_compilation_<CONFIG>.cpp``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
The ``moc`` command line will consume the :prop_tgt:`COMPILE_DEFINITIONS` and
:prop_tgt:`INCLUDE_DIRECTORIES` target properties from the target it is being
......@@ -109,10 +119,15 @@ searched for first in the vicinity of including file and afterwards in the
optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target.
The generated generated ``ui_*.h`` files are placed in the
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/include`` directory which is
``<AUTOGEN_BUILD_DIR>/include`` directory which is
automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
(This differs from CMake 3.7 and below; see their documentation for details.)
* For multi configuration generators, except Xcode, the include directory is
``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
The :prop_tgt:`AUTOUIC` target property may be pre-set for all following
targets by setting the :variable:`CMAKE_AUTOUIC` variable. The
:prop_tgt:`AUTOUIC_OPTIONS` target property may be populated to set options
......
AUTOGEN_BUILD_DIR
-----------------
Directory where :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC`
generate files for the target.
The directory is created on demand and automatically added to the
:prop_dir:`ADDITIONAL_MAKE_CLEAN_FILES`.
When unset or empty the directory ``<dir>/<target-name>_autogen`` is used where
``<dir>`` is :variable:`CMAKE_CURRENT_BINARY_DIR` and ``<target-name>``
is :prop_tgt:`NAME`.
By default :prop_tgt:`AUTOGEN_BUILD_DIR` is unset.
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
......@@ -13,13 +13,17 @@ source files at build time and invoke moc accordingly.
* If an ``#include`` statement like ``#include "moc_<basename>.cpp"`` is found,
the ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in an otherwise empty
line of the ``<basename>.h(xx)`` header file. ``moc`` is run on the header file to
generate ``moc_<basename>.cpp`` in the
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/include`` directory
which is automatically added to the target's
:prop_tgt:`INCLUDE_DIRECTORIES`. This allows the compiler to find the
included ``moc_<basename>.cpp`` file regardless of the location the
original source.
line of the ``<basename>.h(xx)`` header file. ``moc`` is run on the header
file to generate ``moc_<basename>.cpp`` in the
``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added
to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
This allows the compiler to find the included ``moc_<basename>.cpp`` file
regardless of the location the original source.
* For multi configuration generators, except Xcode, the include directory is
``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
* If an ``#include`` statement like ``#include "<basename>.moc"`` is found,
then ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in the current source
......@@ -28,10 +32,19 @@ source files at build time and invoke moc accordingly.
* Header files that are not included by an ``#include "moc_<basename>.cpp"``
statement are nonetheless scanned for ``Q_OBJECT`` or ``Q_GADGET`` macros.
The resulting ``moc_<basename>.cpp`` files are generated in custom
directories and automatically included in the generated
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/moc_compilation.cpp`` file,
which is compiled as part of the target. The custom directories help to
avoid name collisions for moc files with the same ``<basename>``.
directories and automatically included in a generated
``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file,
which is compiled as part of the target.
* For multi configuration generators, except Xcode, the file names are
``moc_<basename>_<CONFIG>.cpp`` and
``<AUTOGEN_BUILD_DIR>/mocs_compilation_<CONFIG>.cpp``.
* The custom directories with checksum
based names help to avoid name collisions for moc files with the same
``<basename>``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
* Additionally, header files with the same base name as a source file,
(like ``<basename>.h``) or ``_p`` appended to the base name (like
......
......@@ -14,8 +14,13 @@ and invoke ``uic`` accordingly. If an ``#include`` statement like
searched for first in the vicinity of ``source.cpp`` and afterwards in the
optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target.
``uic`` is run on the ``foo.ui`` file to generate ``ui_foo.h`` in the directory
``<CMAKE_CURRENT_BINARY_DIR>/<TARGETNAME>_autogen/include``,
which is added to the target's :prop_tgt:`INCLUDE_DIRECTORIES` automatically.
``<AUTOGEN_BUILD_DIR>/include``,
which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
* For multi configuration generators, except Xcode, the include directory is
``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
This property is initialized by the value of the :variable:`CMAKE_AUTOUIC`
variable if it is set when a target is created.
......
AutoGen build dir
-----------------
* The new target property :prop_tgt:`AUTOGEN_BUILD_DIR` was introduced which
allows to set a custom output directory for
:prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC`.
# Target names
set(AM_TARGET_NAME @_autogen_target_name@)
set(AM_ORIGIN_TARGET_NAME @_origin_target_name@)
# Directories and files
set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/")
set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/")
......
This diff is collapsed.
This diff is collapsed.
......@@ -107,8 +107,8 @@ private:
const std::map<std::string, std::set<std::string> >& mocDepends);
bool MocGenerateFile(
const std::string& sourceFile, const std::string& mocFileName,
const std::string& subDir,
const std::map<std::string, std::set<std::string> >& mocDepends);
const std::map<std::string, std::set<std::string> >& mocDepends,
bool included);
// -- Uic file generation
bool UicFindIncludedFile(std::string& absFile, const std::string& sourceFile,
......@@ -139,8 +139,8 @@ private:
const std::map<std::string, std::string>& genFiles,
std::multimap<std::string, std::string>& collisions) const;
std::string ChecksumedPath(const std::string& sourceFile,
const char* basePrefix,
const char* baseSuffix) const;
const std::string& basePrefix,
const std::string& baseSuffix) const;
bool MakeParentDirectory(const char* logPrefix,
const std::string& filename) const;
bool FileDiffers(const std::string& filename, const std::string& content);
......@@ -157,15 +157,15 @@ private:
bool MocFindIncludedFile(std::string& absFile, const std::string& sourceFile,
const std::string& includeString) const;
// -- Target names
std::string OriginTargetName;
std::string AutogenTargetName;
// -- Meta
std::string ConfigSuffix;
// -- Directories
std::string ProjectSourceDir;
std::string ProjectBinaryDir;
std::string CurrentSourceDir;
std::string CurrentBinaryDir;
std::string AutogenBuildDir;
std::string AutogenIncludeDir;
// -- Qt environment
std::string QtMajorVersion;
std::string MocExecutable;
......@@ -189,8 +189,8 @@ private:
bool MocPredefsChanged;
bool MocRelaxedMode;
bool MocRunFailed;
std::string MocCppFilenameRel;
std::string MocCppFilenameAbs;
std::string MocCompFileRel;
std::string MocCompFileAbs;
std::string MocPredefsFileRel;
std::string MocPredefsFileAbs;
std::vector<std::string> MocSkipList;
......
......@@ -64,6 +64,6 @@ target_link_libraries(MyWidget KI18n ${QT_GUI_TARGET})
add_executable(QtAutoUicInterface main.cpp)
target_compile_definitions(QtAutoUicInterface
PRIVATE
UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/LibWidget_autogen/include/ui_libwidget.h"
UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/MyWidget_autogen/include/ui_mywidget.h"
UI_LIBWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/LibWidget_autogen/include_${CMAKE_BUILD_TYPE}/ui_libwidget.h"
UI_MYWIDGET_H="${CMAKE_CURRENT_BINARY_DIR}/MyWidget_autogen/include_${CMAKE_BUILD_TYPE}/ui_mywidget.h"
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment