mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 10:47:59 +08:00
VS: Refactor MSVC character set selection
This commit is contained in:
@@ -816,11 +816,14 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
|
|||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cm::optional<cmGeneratorTarget::MsvcCharSet> const charSet =
|
||||||
|
targetOptions.GetCharSet();
|
||||||
|
|
||||||
// If unicode is enabled change the character set to unicode, if not
|
// If unicode is enabled change the character set to unicode, if not
|
||||||
// then default to MBCS.
|
// then default to MBCS.
|
||||||
if (targetOptions.UsingUnicode()) {
|
if (charSet == cmGeneratorTarget::MsvcCharSet::Unicode) {
|
||||||
fout << "\t\t\tCharacterSet=\"1\">\n";
|
fout << "\t\t\tCharacterSet=\"1\">\n";
|
||||||
} else if (targetOptions.UsingSBCS()) {
|
} else if (charSet == cmGeneratorTarget::MsvcCharSet::SingleByte) {
|
||||||
fout << "\t\t\tCharacterSet=\"0\">\n";
|
fout << "\t\t\tCharacterSet=\"0\">\n";
|
||||||
} else {
|
} else {
|
||||||
fout << "\t\t\tCharacterSet=\"2\">\n";
|
fout << "\t\t\tCharacterSet=\"2\">\n";
|
||||||
@@ -1220,7 +1223,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
|
|||||||
fout << "\t\t\t\tSubSystem=\"8\"\n";
|
fout << "\t\t\t\tSubSystem=\"8\"\n";
|
||||||
|
|
||||||
if (!linkOptions.GetFlag("EntryPointSymbol")) {
|
if (!linkOptions.GetFlag("EntryPointSymbol")) {
|
||||||
char const* entryPointSymbol = targetOptions.UsingUnicode()
|
char const* entryPointSymbol = targetOptions.GetCharSet() ==
|
||||||
|
cmGeneratorTarget::MsvcCharSet::Unicode
|
||||||
? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
|
? (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup")
|
||||||
: (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
|
: (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup");
|
||||||
fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
|
fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n";
|
||||||
|
@@ -433,6 +433,17 @@ void cmVisualStudio10TargetGenerator::Generate()
|
|||||||
if (!this->ComputeLibOptions()) {
|
if (!this->ComputeLibOptions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
for (std::string const& config : this->Configurations) {
|
||||||
|
// Default character set if not populated above.
|
||||||
|
this->CharSet.emplace(
|
||||||
|
config,
|
||||||
|
(this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
|
||||||
|
this->GlobalGenerator->TargetsWindowsPhone() ||
|
||||||
|
this->GlobalGenerator->TargetsWindowsStore() ||
|
||||||
|
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS"))
|
||||||
|
? MsvcCharSet::Unicode
|
||||||
|
: MsvcCharSet::MultiByte);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::string path =
|
std::string path =
|
||||||
cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
||||||
@@ -1536,15 +1547,11 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
|
if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
|
||||||
this->ClOptions[config]->UsingUnicode()) ||
|
this->CharSet[config] == MsvcCharSet::Unicode)) {
|
||||||
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
|
|
||||||
this->GlobalGenerator->TargetsWindowsPhone() ||
|
|
||||||
this->GlobalGenerator->TargetsWindowsStore() ||
|
|
||||||
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
|
|
||||||
e1.Element("CharacterSet", "Unicode");
|
e1.Element("CharacterSet", "Unicode");
|
||||||
} else if (this->GeneratorTarget->GetType() <=
|
} else if (this->GeneratorTarget->GetType() <=
|
||||||
cmStateEnums::OBJECT_LIBRARY &&
|
cmStateEnums::OBJECT_LIBRARY &&
|
||||||
this->ClOptions[config]->UsingSBCS()) {
|
this->CharSet[config] == MsvcCharSet::SingleByte) {
|
||||||
e1.Element("CharacterSet", "NotSet");
|
e1.Element("CharacterSet", "NotSet");
|
||||||
} else {
|
} else {
|
||||||
e1.Element("CharacterSet", "MultiByte");
|
e1.Element("CharacterSet", "MultiByte");
|
||||||
@@ -3631,6 +3638,10 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cm::optional<MsvcCharSet> charSet = clOptions.GetCharSet()) {
|
||||||
|
this->CharSet.emplace(configName, *charSet);
|
||||||
|
}
|
||||||
|
|
||||||
if (this->ProjectType != VsProjectType::csproj &&
|
if (this->ProjectType != VsProjectType::csproj &&
|
||||||
(clOptions.IsManaged() || clOptions.HasFlag("CLRSupport"))) {
|
(clOptions.IsManaged() || clOptions.HasFlag("CLRSupport"))) {
|
||||||
this->Managed = true;
|
this->Managed = true;
|
||||||
@@ -4608,7 +4619,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
|||||||
if (this->GlobalGenerator->TargetsWindowsCE()) {
|
if (this->GlobalGenerator->TargetsWindowsCE()) {
|
||||||
linkOptions.AddFlag("SubSystem", "WindowsCE");
|
linkOptions.AddFlag("SubSystem", "WindowsCE");
|
||||||
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
|
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
|
||||||
if (this->ClOptions[config]->UsingUnicode()) {
|
if (this->CharSet[config] == MsvcCharSet::Unicode) {
|
||||||
linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
|
linkOptions.AddFlag("EntryPointSymbol", "wWinMainCRTStartup");
|
||||||
} else {
|
} else {
|
||||||
linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
|
linkOptions.AddFlag("EntryPointSymbol", "WinMainCRTStartup");
|
||||||
@@ -4621,7 +4632,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
|||||||
if (this->GlobalGenerator->TargetsWindowsCE()) {
|
if (this->GlobalGenerator->TargetsWindowsCE()) {
|
||||||
linkOptions.AddFlag("SubSystem", "WindowsCE");
|
linkOptions.AddFlag("SubSystem", "WindowsCE");
|
||||||
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
|
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
|
||||||
if (this->ClOptions[config]->UsingUnicode()) {
|
if (this->CharSet[config] == MsvcCharSet::Unicode) {
|
||||||
linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
|
linkOptions.AddFlag("EntryPointSymbol", "mainWCRTStartup");
|
||||||
} else {
|
} else {
|
||||||
linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
|
linkOptions.AddFlag("EntryPointSymbol", "mainACRTStartup");
|
||||||
|
@@ -276,6 +276,9 @@ private:
|
|||||||
using ToolSourceMap = std::map<std::string, ToolSources>;
|
using ToolSourceMap = std::map<std::string, ToolSources>;
|
||||||
ToolSourceMap Tools;
|
ToolSourceMap Tools;
|
||||||
|
|
||||||
|
using MsvcCharSet = cmGeneratorTarget::MsvcCharSet;
|
||||||
|
std::map<std::string, MsvcCharSet> CharSet;
|
||||||
|
|
||||||
std::set<std::string> ExpectedResxHeaders;
|
std::set<std::string> ExpectedResxHeaders;
|
||||||
std::set<std::string> ExpectedXamlHeaders;
|
std::set<std::string> ExpectedXamlHeaders;
|
||||||
std::set<std::string> ExpectedXamlSources;
|
std::set<std::string> ExpectedXamlSources;
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cm/iterator>
|
#include <cm/iterator>
|
||||||
|
#include <cm/optional>
|
||||||
#include <cmext/string_view>
|
#include <cmext/string_view>
|
||||||
|
|
||||||
#include "cmAlgorithms.h"
|
#include "cmAlgorithms.h"
|
||||||
@@ -134,44 +135,18 @@ bool cmVisualStudioGeneratorOptions::IsManaged() const
|
|||||||
return this->FlagMap.find("CompileAsManaged") != this->FlagMap.end();
|
return this->FlagMap.find("CompileAsManaged") != this->FlagMap.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmVisualStudioGeneratorOptions::CacheCharsetValue() const
|
cm::optional<cmGeneratorTarget::MsvcCharSet>
|
||||||
|
cmVisualStudioGeneratorOptions::GetCharSet() const
|
||||||
{
|
{
|
||||||
using MsvcCharSet = cmGeneratorTarget::MsvcCharSet;
|
// Look for a project- or user-specified character set definition.
|
||||||
|
for (std::string const& define : this->Defines) {
|
||||||
if (this->CachedCharset.has_value()) {
|
cmGeneratorTarget::MsvcCharSet charSet =
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MsvcCharSet newValue = MsvcCharSet::None;
|
|
||||||
|
|
||||||
// Look for a any charset definition.
|
|
||||||
// Real charset will be updated if something is found.
|
|
||||||
auto it = std::find_if(this->Defines.begin(), this->Defines.end(),
|
|
||||||
[&newValue](std::string const& define) {
|
|
||||||
newValue =
|
|
||||||
cmGeneratorTarget::GetMsvcCharSet(define);
|
cmGeneratorTarget::GetMsvcCharSet(define);
|
||||||
return newValue != MsvcCharSet::None;
|
if (charSet != cmGeneratorTarget::MsvcCharSet::None) {
|
||||||
});
|
return charSet;
|
||||||
|
|
||||||
if (it == this->Defines.end()) {
|
|
||||||
// Default to multi-byte, as Visual Studio does
|
|
||||||
newValue = MsvcCharSet::MultiByte;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this->CachedCharset = newValue;
|
return cm::nullopt;
|
||||||
}
|
|
||||||
|
|
||||||
bool cmVisualStudioGeneratorOptions::UsingUnicode() const
|
|
||||||
{
|
|
||||||
this->CacheCharsetValue();
|
|
||||||
return this->CachedCharset.value() ==
|
|
||||||
cmGeneratorTarget::MsvcCharSet::Unicode;
|
|
||||||
}
|
|
||||||
bool cmVisualStudioGeneratorOptions::UsingSBCS() const
|
|
||||||
{
|
|
||||||
this->CacheCharsetValue();
|
|
||||||
return this->CachedCharset.value() ==
|
|
||||||
cmGeneratorTarget::MsvcCharSet::SingleByte;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()
|
void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()
|
||||||
|
@@ -60,9 +60,8 @@ public:
|
|||||||
// Store options for verbose builds.
|
// Store options for verbose builds.
|
||||||
void SetVerboseMakefile(bool verbose);
|
void SetVerboseMakefile(bool verbose);
|
||||||
|
|
||||||
// Check for specific options.
|
// Detect a character set definition.
|
||||||
bool UsingUnicode() const;
|
cm::optional<cmGeneratorTarget::MsvcCharSet> GetCharSet() const;
|
||||||
bool UsingSBCS() const;
|
|
||||||
|
|
||||||
void FixCudaCodeGeneration();
|
void FixCudaCodeGeneration();
|
||||||
|
|
||||||
@@ -98,11 +97,7 @@ private:
|
|||||||
|
|
||||||
std::string UnknownFlagField;
|
std::string UnknownFlagField;
|
||||||
|
|
||||||
mutable cm::optional<cmGeneratorTarget::MsvcCharSet> CachedCharset;
|
|
||||||
|
|
||||||
void StoreUnknownFlag(std::string const& flag) override;
|
void StoreUnknownFlag(std::string const& flag) override;
|
||||||
|
|
||||||
FlagValue TakeFlag(std::string const& key);
|
FlagValue TakeFlag(std::string const& key);
|
||||||
|
|
||||||
void CacheCharsetValue() const;
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user