Commit 9945b3b5 authored by Brad King's avatar Brad King
Browse files

VS: Restore support for PCH in CXX but not C within once target

Fix logic from commit 9df1f33c (VisualStudio: move PCH rules to
projects when possible., 2020-10-15, v3.20.0-rc1~638^2) to explicitly
disable PCH on sources that should not use the target-wide PCH rules.

Fixes: #21827
parent d9fd32b3
Pipeline #215168 passed with stages
in 83 minutes and 8 seconds
......@@ -2423,8 +2423,10 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
const bool makePCH = (sf.GetFullPath() == pchSource);
const bool useSharedPCH = !skipPCH && (lang == linkLanguage);
const bool useDifferentLangPCH = !skipPCH && (lang != linkLanguage);
const bool useNoPCH = skipPCH && (lang != linkLanguage) &&
!this->GeneratorTarget->GetPchHeader(config, linkLanguage).empty();
const bool needsPCHFlags =
(makePCH || useSharedPCH || useDifferentLangPCH);
(makePCH || useSharedPCH || useDifferentLangPCH || useNoPCH);
// if we have flags or defines for this config then
// use them
......@@ -2471,6 +2473,8 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
if (makePCH) {
pchOptions =
this->GeneratorTarget->GetPchCreateCompileOptions(config, lang);
} else if (useNoPCH) {
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
} else if (useSharedPCH) {
std::string pchHeader =
this->GeneratorTarget->GetPchHeader(config, lang);
......
enable_language(C)
enable_language(CXX)
add_executable(main
no_pch.c
use_pch.cxx
)
target_include_directories(main PUBLIC include)
target_precompile_headers(main PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/include/cxx_pch.h>"
)
enable_testing()
add_test(NAME main COMMAND main)
......@@ -14,6 +14,7 @@ run_cmake(PchDebugGenex)
run_test(PchInterface)
run_cmake(PchPrologueEpilogue)
run_test(SkipPrecompileHeaders)
run_test(CXXnotC)
run_test(PchReuseFrom)
run_test(PchReuseFromPrefixed)
run_test(PchReuseFromSubdir)
......
#ifdef CXX_PCH
# error "CXX PCH included in C source."
#endif
int no_pch(void)
{
return 0;
}
#include "cxx_pch.h"
#ifndef CXX_PCH
# error "CXX PCH not included in CXX source."
#endif
extern "C" int no_pch(void);
int main()
{
return no_pch();
}
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