mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 22:30:13 -06:00
AUTOMOC: Skip PCH when all sources files skip the PCH file too
Fixes: #23464
This commit is contained in:
@@ -1792,13 +1792,16 @@ void cmQtAutoGenInitializer::AddGeneratedSource(ConfigString const& filename,
|
||||
// XXX(xcode-per-cfg-src): Drop the Xcode-specific part of the condition
|
||||
// when the Xcode generator supports per-config sources.
|
||||
if (!this->MultiConfig || this->GlobalGen->IsXcode()) {
|
||||
this->AddGeneratedSource(filename.Default, genVars, prepend);
|
||||
cmSourceFile* sf =
|
||||
this->AddGeneratedSource(filename.Default, genVars, prepend);
|
||||
handleSkipPch(sf);
|
||||
return;
|
||||
}
|
||||
for (auto const& cfg : this->ConfigsList) {
|
||||
std::string const& filenameCfg = filename.Config.at(cfg);
|
||||
// Register source at makefile
|
||||
this->RegisterGeneratedSource(filenameCfg);
|
||||
cmSourceFile* sf = this->RegisterGeneratedSource(filenameCfg);
|
||||
handleSkipPch(sf);
|
||||
// Add source file to target for this configuration.
|
||||
this->GenTarget->AddSource(
|
||||
cmStrCat("$<$<CONFIG:"_s, cfg, ">:"_s, filenameCfg, ">"_s), prepend);
|
||||
@@ -2158,3 +2161,18 @@ bool cmQtAutoGenInitializer::GetQtExecutable(GenVarsT& genVars,
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmQtAutoGenInitializer::handleSkipPch(cmSourceFile* sf)
|
||||
{
|
||||
bool skipPch = true;
|
||||
for (auto const& pair : this->AutogenTarget.Sources) {
|
||||
if (!pair.first->GetIsGenerated() &&
|
||||
!pair.first->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
|
||||
skipPch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipPch) {
|
||||
sf->SetProperty("SKIP_PRECOMPILE_HEADERS", "ON");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,8 @@ private:
|
||||
bool GetQtExecutable(GenVarsT& genVars, const std::string& executable,
|
||||
bool ignoreMissingTarget) const;
|
||||
|
||||
void handleSkipPch(cmSourceFile* sf);
|
||||
|
||||
cmQtAutoGenGlobalInitializer* GlobalInitializer = nullptr;
|
||||
cmGeneratorTarget* GenTarget = nullptr;
|
||||
cmGlobalGenerator* GlobalGen = nullptr;
|
||||
|
||||
17
Tests/RunCMake/Ninja/QtAutoMocSkipPch.cmake
Normal file
17
Tests/RunCMake/Ninja/QtAutoMocSkipPch.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
enable_language(CXX)
|
||||
|
||||
set(QtX Qt${with_qt_version})
|
||||
|
||||
find_package(${QtX} REQUIRED COMPONENTS Core)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
add_library(simple_lib SHARED simple_lib.cpp)
|
||||
add_executable(app_with_qt app.cpp app_qt.cpp)
|
||||
|
||||
target_link_libraries(app_with_qt PRIVATE simple_lib ${QtX}::Core)
|
||||
|
||||
set_source_files_properties(app.cpp app_qt.cpp
|
||||
PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||
|
||||
target_precompile_headers(app_with_qt PRIVATE [["QObject"]])
|
||||
@@ -357,6 +357,22 @@ function(run_QtAutoMocDeps)
|
||||
run_ninja("${RunCMake_TEST_BINARY_DIR}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(run_QtAutoMocSkipPch)
|
||||
set(QtX Qt${CMake_TEST_Qt_version})
|
||||
if(CMake_TEST_${QtX}Core_Version VERSION_GREATER_EQUAL 5.15.0)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/QtAutoMocSkipPch-build)
|
||||
run_cmake_with_options(QtAutoMocSkipPch
|
||||
"-Dwith_qt_version=${CMake_TEST_Qt_version}"
|
||||
"-D${QtX}_DIR=${${QtX}_DIR}"
|
||||
"-D${QtX}Core_DIR=${${QtX}Core_DIR}"
|
||||
"-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}"
|
||||
)
|
||||
# Build the project.
|
||||
run_ninja("${RunCMake_TEST_BINARY_DIR}")
|
||||
endif()
|
||||
endfunction()
|
||||
if(CMake_TEST_Qt_version)
|
||||
run_QtAutoMocDeps()
|
||||
run_QtAutoMocSkipPch()
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user