mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
Merge topic 'automoc-moc-options-test'
1f4b374d6ecmQtAutoGenInitializer: Reduce string copiesb6f66b445acmQtAutoGenInitializer: Remove no-op calls55d93bdabfcmQtAutoGenInitializer: Improve const correctnessfeb56a666fcmTarget: Improve const correctness of AddUtility5e513e562fHelp: Add AUTOMOC_MOC_OPTIONS example5380ad9d58Tests: Add test for AUTOMOC_MOC_OPTIONS Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8523
This commit is contained in:
@@ -15,3 +15,39 @@ is created, or an empty string otherwise.
|
||||
|
||||
See the :manual:`cmake-qt(7)` manual for more information on using CMake
|
||||
with Qt.
|
||||
|
||||
EXAMPLE
|
||||
^^^^^^^
|
||||
|
||||
In this example, the ``moc`` tool is invoked with the ``-D_EXTRA_DEFINE``
|
||||
option when generating the moc file for ``object.cpp``.
|
||||
|
||||
``CMakeLists.txt``
|
||||
.. code-block:: cmake
|
||||
|
||||
add_executable(mocOptions object.cpp main.cpp)
|
||||
set_property(TARGET mocOptions PROPERTY AUTOMOC ON)
|
||||
target_compile_options(mocOptions PRIVATE "-D_EXTRA_DEFINE")
|
||||
set_property(TARGET mocOptions PROPERTY AUTOMOC_MOC_OPTIONS "-D_EXTRA_DEFINE")
|
||||
target_link_libraries(mocOptions Qt6::Core)
|
||||
|
||||
``object.hpp``
|
||||
.. code-block:: c++
|
||||
|
||||
#ifndef Object_HPP
|
||||
#define Object_HPP
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifdef _EXTRA_DEFINE
|
||||
class Object : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Object();
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1381,29 +1381,25 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
// '_autogen' target.
|
||||
const auto timestampTargetName =
|
||||
cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps");
|
||||
std::vector<std::string> timestampTargetProvides;
|
||||
cmCustomCommandLines timestampTargetCommandLines;
|
||||
|
||||
// Add additional autogen target dependencies to
|
||||
// '_autogen_timestamp_deps'.
|
||||
for (const cmTarget* t : this->AutogenTarget.DependTargets) {
|
||||
std::string depname = t->GetName();
|
||||
if (t->IsImported()) {
|
||||
auto ttype = t->GetType();
|
||||
auto const ttype = t->GetType();
|
||||
if (ttype == cmStateEnums::TargetType::STATIC_LIBRARY ||
|
||||
ttype == cmStateEnums::TargetType::SHARED_LIBRARY ||
|
||||
ttype == cmStateEnums::TargetType::UNKNOWN_LIBRARY) {
|
||||
depname = cmStrCat("$<TARGET_LINKER_FILE:", t->GetName(), ">");
|
||||
}
|
||||
}
|
||||
dependencies.push_back(depname);
|
||||
dependencies.emplace_back(std::move(depname));
|
||||
}
|
||||
|
||||
auto cc = cm::make_unique<cmCustomCommand>();
|
||||
cc->SetWorkingDirectory(this->Dir.Work.c_str());
|
||||
cc->SetByproducts(timestampTargetProvides);
|
||||
cc->SetDepends(dependencies);
|
||||
cc->SetCommandLines(timestampTargetCommandLines);
|
||||
cc->SetEscapeOldStyle(false);
|
||||
cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand(
|
||||
timestampTargetName, true, std::move(cc));
|
||||
@@ -1478,7 +1474,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
|
||||
}
|
||||
if (!useNinjaDepfile) {
|
||||
// Add additional autogen target dependencies to autogen target
|
||||
for (cmTarget* depTarget : this->AutogenTarget.DependTargets) {
|
||||
for (cmTarget const* depTarget : this->AutogenTarget.DependTargets) {
|
||||
autogenTarget->AddUtility(depTarget->GetName(), false, this->Makefile);
|
||||
}
|
||||
}
|
||||
@@ -2002,7 +1998,7 @@ static cmQtAutoGen::IntegerVersion parseMocVersion(std::string str)
|
||||
cmQtAutoGen::IntegerVersion result;
|
||||
|
||||
static const std::string prelude = "moc ";
|
||||
size_t pos = str.find(prelude);
|
||||
size_t const pos = str.find(prelude);
|
||||
if (pos == std::string::npos) {
|
||||
return result;
|
||||
}
|
||||
@@ -2120,7 +2116,7 @@ cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target,
|
||||
res.first = knownQtVersions.at(0);
|
||||
} else {
|
||||
// Pick a version from the known versions:
|
||||
for (auto it : knownQtVersions) {
|
||||
for (auto const& it : knownQtVersions) {
|
||||
if (it.Major == res.second) {
|
||||
res.first = it;
|
||||
break;
|
||||
|
||||
@@ -1210,7 +1210,8 @@ void cmTarget::SetLanguageStandardProperty(std::string const& lang,
|
||||
languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
|
||||
}
|
||||
|
||||
void cmTarget::AddUtility(std::string const& name, bool cross, cmMakefile* mf)
|
||||
void cmTarget::AddUtility(std::string const& name, bool cross,
|
||||
cmMakefile const* mf)
|
||||
{
|
||||
this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
|
||||
{ name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
|
||||
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
* commands. It is not a full path nor does it have an extension.
|
||||
*/
|
||||
void AddUtility(std::string const& name, bool cross,
|
||||
cmMakefile* mf = nullptr);
|
||||
cmMakefile const* mf = nullptr);
|
||||
void AddUtility(BT<std::pair<std::string, bool>> util);
|
||||
//! Get the utilities used by this target
|
||||
std::set<BT<std::pair<std::string, bool>>> const& GetUtilities() const;
|
||||
|
||||
10
Tests/QtAutogen/MocOptions2/CMakeLists.txt
Normal file
10
Tests/QtAutogen/MocOptions2/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(MocOptions2)
|
||||
include("../AutogenCoreTest.cmake")
|
||||
|
||||
# Test extra options passed to moc via AUTOMOC_MOC_OPTIONS
|
||||
add_executable(mocOptions object.cpp main.cpp)
|
||||
set_property(TARGET mocOptions PROPERTY AUTOMOC ON)
|
||||
target_compile_options(mocOptions PRIVATE "-D_EXTRA_DEFINE")
|
||||
set_property(TARGET mocOptions PROPERTY AUTOMOC_MOC_OPTIONS "-D_EXTRA_DEFINE")
|
||||
target_link_libraries(mocOptions ${QT_LIBRARIES})
|
||||
7
Tests/QtAutogen/MocOptions2/main.cpp
Normal file
7
Tests/QtAutogen/MocOptions2/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "object.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Object object;
|
||||
return 0;
|
||||
}
|
||||
5
Tests/QtAutogen/MocOptions2/object.cpp
Normal file
5
Tests/QtAutogen/MocOptions2/object.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "object.hpp"
|
||||
|
||||
Object::Object()
|
||||
{
|
||||
}
|
||||
15
Tests/QtAutogen/MocOptions2/object.hpp
Normal file
15
Tests/QtAutogen/MocOptions2/object.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef Object_HPP
|
||||
#define Object_HPP
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifdef _EXTRA_DEFINE
|
||||
class Object : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Object();
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -12,6 +12,7 @@ ADD_AUTOGEN_TEST(ManySources manySources)
|
||||
ADD_AUTOGEN_TEST(MocInterfaceMacroNames)
|
||||
ADD_AUTOGEN_TEST(MocOnly mocOnly)
|
||||
ADD_AUTOGEN_TEST(MocOptions mocOptions)
|
||||
ADD_AUTOGEN_TEST(MocOptions2)
|
||||
ADD_AUTOGEN_TEST(ObjectLibrary someProgram)
|
||||
ADD_AUTOGEN_TEST(Parallel parallel)
|
||||
ADD_AUTOGEN_TEST(Parallel1 parallel1)
|
||||
|
||||
Reference in New Issue
Block a user