mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-21 14:40:26 -06:00
Merge topic 'vs-pch-one-lang'
9945b3b565VS: Restore support for PCH in CXX but not C within once targetd9fd32b3b3cmVisualStudio10TargetGenerator: Refactor per-source PCH logic Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5836
This commit is contained in:
@@ -2413,18 +2413,20 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
// 1. We have SKIP_PRECOMPILE_HEADERS == true
|
||||
// 2. We are creating the pre-compiled header
|
||||
// 3. We are a different language than the linker language AND pch is
|
||||
// enabled
|
||||
const std::string pchSource =
|
||||
// enabled.
|
||||
std::string const& linkLanguage =
|
||||
this->GeneratorTarget->GetLinkerLanguage(config);
|
||||
std::string const& pchSource =
|
||||
this->GeneratorTarget->GetPchSource(config, lang);
|
||||
const bool skipPCH =
|
||||
pchSource.empty() || sf.GetPropertyAsBool("SKIP_PRECOMPILE_HEADERS");
|
||||
const bool makePCH = (sf.GetFullPath() == pchSource);
|
||||
const bool useSharedPCH =
|
||||
!skipPCH && (lang == this->GeneratorTarget->GetLinkerLanguage(config));
|
||||
const bool useDifferentLangPCH =
|
||||
!skipPCH && (lang != this->GeneratorTarget->GetLinkerLanguage(config));
|
||||
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);
|
||||
|
||||
15
Tests/RunCMake/PrecompileHeaders/CXXnotC.cmake
Normal file
15
Tests/RunCMake/PrecompileHeaders/CXXnotC.cmake
Normal file
@@ -0,0 +1,15 @@
|
||||
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)
|
||||
|
||||
1
Tests/RunCMake/PrecompileHeaders/include/cxx_pch.h
Normal file
1
Tests/RunCMake/PrecompileHeaders/include/cxx_pch.h
Normal file
@@ -0,0 +1 @@
|
||||
#define CXX_PCH
|
||||
7
Tests/RunCMake/PrecompileHeaders/no_pch.c
Normal file
7
Tests/RunCMake/PrecompileHeaders/no_pch.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifdef CXX_PCH
|
||||
# error "CXX PCH included in C source."
|
||||
#endif
|
||||
int no_pch(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
9
Tests/RunCMake/PrecompileHeaders/use_pch.cxx
Normal file
9
Tests/RunCMake/PrecompileHeaders/use_pch.cxx
Normal file
@@ -0,0 +1,9 @@
|
||||
#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();
|
||||
}
|
||||
Reference in New Issue
Block a user