mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Merge topic 'automoc-cxx-standard'
429a452705Autogen: Add target's C++ standard to moc_predef.h21f812e57cAutogen: Split creation and setup of custom targets into separate steps Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8359
This commit is contained in:
@@ -1543,10 +1543,12 @@ bool cmGlobalGenerator::Compute()
|
||||
return false;
|
||||
}
|
||||
|
||||
// Iterate through all targets and set up AUTOMOC, AUTOUIC and AUTORCC
|
||||
if (!this->QtAutoGen()) {
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
cmQtAutoGenGlobalInitializer qtAutoGen(this->LocalGenerators);
|
||||
if (!qtAutoGen.InitializeCustomTargets()) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Add generator specific helper commands
|
||||
for (const auto& localGen : this->LocalGenerators) {
|
||||
@@ -1563,6 +1565,12 @@ bool cmGlobalGenerator::Compute()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
if (!qtAutoGen.SetupCustomTargets()) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto& localGen : this->LocalGenerators) {
|
||||
cmMakefile* mf = localGen->GetMakefile();
|
||||
for (const auto& g : mf->GetInstallGenerators()) {
|
||||
@@ -1763,16 +1771,6 @@ void cmGlobalGenerator::ComputeTargetOrder(cmGeneratorTarget const* gt,
|
||||
entry->second = index++;
|
||||
}
|
||||
|
||||
bool cmGlobalGenerator::QtAutoGen()
|
||||
{
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
cmQtAutoGenGlobalInitializer initializer(this->LocalGenerators);
|
||||
return initializer.generate();
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool cmGlobalGenerator::AddHeaderSetVerification()
|
||||
{
|
||||
for (auto const& gen : this->LocalGenerators) {
|
||||
|
||||
@@ -637,10 +637,6 @@ protected:
|
||||
|
||||
void CxxModuleSupportCheck() const;
|
||||
|
||||
/// @brief Qt AUTOMOC/UIC/RCC target generation
|
||||
/// @return true on success
|
||||
bool QtAutoGen();
|
||||
|
||||
bool AddHeaderSetVerification();
|
||||
|
||||
bool AddAutomaticSources();
|
||||
|
||||
@@ -264,11 +264,6 @@ cmQtAutoGenGlobalInitializer::GetCompilerFeatures(
|
||||
return res;
|
||||
}
|
||||
|
||||
bool cmQtAutoGenGlobalInitializer::generate()
|
||||
{
|
||||
return (this->InitializeCustomTargets() && this->SetupCustomTargets());
|
||||
}
|
||||
|
||||
bool cmQtAutoGenGlobalInitializer::InitializeCustomTargets()
|
||||
{
|
||||
// Initialize global autogen targets
|
||||
|
||||
@@ -51,14 +51,12 @@ public:
|
||||
|
||||
Keywords const& kw() const { return this->Keywords_; }
|
||||
|
||||
bool generate();
|
||||
bool InitializeCustomTargets();
|
||||
bool SetupCustomTargets();
|
||||
|
||||
private:
|
||||
friend class cmQtAutoGenInitializer;
|
||||
|
||||
bool InitializeCustomTargets();
|
||||
bool SetupCustomTargets();
|
||||
|
||||
void GetOrCreateGlobalTarget(cmLocalGenerator* localGen,
|
||||
std::string const& name,
|
||||
std::string const& comment);
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "cmSourceFile.h"
|
||||
#include "cmSourceFileLocationKind.h"
|
||||
#include "cmSourceGroup.h"
|
||||
#include "cmStandardLevelResolver.h"
|
||||
#include "cmState.h"
|
||||
#include "cmStateTypes.h"
|
||||
#include "cmStringAlgorithms.h"
|
||||
@@ -1699,8 +1700,22 @@ bool cmQtAutoGenInitializer::SetupWriteAutogenInfo()
|
||||
jval[1u] = pair.second;
|
||||
});
|
||||
info.SetConfig("MOC_COMPILATION_FILE", this->Moc.CompilationFile);
|
||||
info.SetArray("MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
|
||||
info.SetConfig("MOC_PREDEFS_FILE", this->Moc.PredefsFile);
|
||||
|
||||
cmStandardLevelResolver resolver{ this->Makefile };
|
||||
auto CompileOptionFlag =
|
||||
resolver.GetCompileOptionDef(this->GenTarget, "CXX", "");
|
||||
|
||||
auto CompileOptionValue =
|
||||
this->GenTarget->Makefile->GetSafeDefinition(CompileOptionFlag);
|
||||
|
||||
if (!CompileOptionValue.empty()) {
|
||||
if (this->Moc.PredefsCmd.size() >= 3) {
|
||||
this->Moc.PredefsCmd.insert(this->Moc.PredefsCmd.begin() + 1,
|
||||
CompileOptionValue);
|
||||
}
|
||||
}
|
||||
info.SetArray("MOC_PREDEFS_CMD", this->Moc.PredefsCmd);
|
||||
}
|
||||
|
||||
// Write uic settings
|
||||
|
||||
1
Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt
Normal file
1
Tests/RunCMake/Autogen/MocPredefs-build-stderr.txt
Normal file
@@ -0,0 +1 @@
|
||||
.*
|
||||
60
Tests/RunCMake/Autogen/MocPredefs-check.cxx
Normal file
60
Tests/RunCMake/Autogen/MocPredefs-check.cxx
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "check_predefs.h"
|
||||
|
||||
#define TO_STRING(x) TO_STRING0(x)
|
||||
#define TO_STRING0(x) #x
|
||||
|
||||
int main()
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(__STRICT_ANSI__)
|
||||
# if !defined(CHECK___STRICT_ANSI__)
|
||||
std::cout << "__STRICT_ANSI__: Expected " << TO_STRING(__STRICT_ANSI__)
|
||||
<< " but it is not defined.\n";
|
||||
ret = 1;
|
||||
# elif __STRICT_ANSI__ != CHECK___STRICT_ANSI__
|
||||
std::cout << "__STRICT_ANSI__: Expected " << TO_STRING(__STRICT_ANSI__)
|
||||
<< " but got: " << TO_STRING(CHECK___STRICT_ANSI__) << "\n";
|
||||
ret = 1;
|
||||
# endif
|
||||
#elif defined(CHECK___STRICT_ANSI__)
|
||||
std::cout << "__STRICT_ANSI__: Expected undefined but got: "
|
||||
<< TO_STRING(CHECK___STRICT_ANSI__) << "\n";
|
||||
ret = 1;
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
# if !defined(CHECK___cplusplus)
|
||||
std::cout << "__cplusplus: Expected " << TO_STRING(__cplusplus)
|
||||
<< " but it is not defined.\n";
|
||||
ret = 1;
|
||||
# elif __cplusplus != CHECK___cplusplus
|
||||
std::cout << "__cplusplus: Expected " << TO_STRING(__cplusplus)
|
||||
<< " but got: " << TO_STRING(CHECK___cplusplus) << "\n";
|
||||
ret = 1;
|
||||
# endif
|
||||
#elif defined(CHECK___cplusplus)
|
||||
std::cout << "__cplusplus: Expected undefined but got: "
|
||||
<< TO_STRING(CHECK___cplusplus) << "\n";
|
||||
ret = 1;
|
||||
#endif
|
||||
|
||||
#if defined(_MSVC_LANG)
|
||||
# if !defined(CHECK__MSVC_LANG)
|
||||
std::cout << "_MSVC_LANG: Expected " << TO_STRING(_MSVC_LANG)
|
||||
<< " but it is not defined.\n";
|
||||
ret = 1;
|
||||
# elif _MSVC_LANG != CHECK__MSVC_LANG
|
||||
std::cout << "_MSVC_LANG: Expected " << TO_STRING(_MSVC_LANG)
|
||||
<< " but got: " << TO_STRING(CHECK__MSVC_LANG) << "\n";
|
||||
ret = 1;
|
||||
# endif
|
||||
#elif defined(CHECK__MSVC_LANG)
|
||||
std::cout << "_MSVC_LANG: Expected undefined but got: "
|
||||
<< TO_STRING(CHECK__MSVC_LANG) << "\n";
|
||||
ret = 1;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
3
Tests/RunCMake/Autogen/MocPredefs-prefix.cmake
Normal file
3
Tests/RunCMake/Autogen/MocPredefs-prefix.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
file(READ ${in} predefs)
|
||||
string(REGEX REPLACE "#define +" "#define CHECK_" predefs "${predefs}")
|
||||
file(WRITE ${out} "${predefs}")
|
||||
40
Tests/RunCMake/Autogen/MocPredefs.cmake
Normal file
40
Tests/RunCMake/Autogen/MocPredefs.cmake
Normal file
@@ -0,0 +1,40 @@
|
||||
cmake_policy(SET CMP0129 NEW)
|
||||
enable_language(CXX)
|
||||
|
||||
find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
add_library(MocPredefs MocPredefs.cxx)
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_COMPILER_PREDEFINES_COMMAND)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "LCC" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "1.26")
|
||||
return()
|
||||
endif()
|
||||
|
||||
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(_isMultiConfig)
|
||||
set(moc_predefs_h "moc_predefs_$<CONFIG>.h")
|
||||
set(check_dir "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
|
||||
else()
|
||||
set(moc_predefs_h "moc_predefs.h")
|
||||
set(check_dir "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
add_custom_command(TARGET MocPredefs POST_BUILD VERBATIM COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-Din=${CMAKE_CURRENT_BINARY_DIR}/MocPredefs_autogen/${moc_predefs_h}
|
||||
-Dout=${check_dir}/check_predefs.h
|
||||
-P${CMAKE_CURRENT_SOURCE_DIR}/MocPredefs-prefix.cmake
|
||||
)
|
||||
|
||||
add_executable(MocPredefs-check MocPredefs-check.cxx)
|
||||
target_include_directories(MocPredefs-check PRIVATE ${check_dir})
|
||||
add_dependencies(MocPredefs-check MocPredefs)
|
||||
|
||||
add_custom_target(MocPredefs-run-check ALL VERBATIM COMMAND MocPredefs-check)
|
||||
3
Tests/RunCMake/Autogen/MocPredefs.cxx
Normal file
3
Tests/RunCMake/Autogen/MocPredefs.cxx
Normal file
@@ -0,0 +1,3 @@
|
||||
void MocPredefs()
|
||||
{
|
||||
}
|
||||
@@ -15,4 +15,11 @@ if (DEFINED with_qt_version)
|
||||
run_cmake(CMP0111-imported-target-full)
|
||||
run_cmake(CMP0111-imported-target-libname)
|
||||
run_cmake(CMP0111-imported-target-implib-only)
|
||||
|
||||
block()
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MocPredefs-build)
|
||||
run_cmake(MocPredefs)
|
||||
set(RunCMake_TEST_NO_CLEAN 1)
|
||||
run_cmake_command(MocPredefs-build ${CMAKE_COMMAND} --build . --config Debug)
|
||||
endblock()
|
||||
endif ()
|
||||
|
||||
Reference in New Issue
Block a user