Visual Studio: Allow setting Single Byte Character Set (#12189)
For Visual Studio using the Preprocessor Define _SBCS. This behavior is similar to the way that _UNICODE and _MBCS work already. Added tests to confirm this behavior.
This commit is contained in:
parent
e2042b68d3
commit
ba89e92ba6
|
@ -774,6 +774,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
|
||||||
{
|
{
|
||||||
fout << "\t\t\tCharacterSet=\"1\">\n";
|
fout << "\t\t\tCharacterSet=\"1\">\n";
|
||||||
}
|
}
|
||||||
|
else if(targetOptions.UsingSBCS())
|
||||||
|
{
|
||||||
|
fout << "\t\t\tCharacterSet=\"0\">\n";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fout << "\t\t\tCharacterSet=\"2\">\n";
|
fout << "\t\t\tCharacterSet=\"2\">\n";
|
||||||
|
|
|
@ -394,6 +394,11 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
|
||||||
{
|
{
|
||||||
this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
|
this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
|
||||||
}
|
}
|
||||||
|
else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY &&
|
||||||
|
this->ClOptions[*i]->UsingSBCS())
|
||||||
|
{
|
||||||
|
this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
|
this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
|
||||||
|
|
|
@ -117,6 +117,20 @@ bool cmVisualStudioGeneratorOptions::UsingUnicode()
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool cmVisualStudioGeneratorOptions::UsingSBCS()
|
||||||
|
{
|
||||||
|
// Look for the a _SBCS definition.
|
||||||
|
for(std::vector<std::string>::const_iterator di = this->Defines.begin();
|
||||||
|
di != this->Defines.end(); ++di)
|
||||||
|
{
|
||||||
|
if(*di == "_SBCS")
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmVisualStudioGeneratorOptions::Parse(const char* flags)
|
void cmVisualStudioGeneratorOptions::Parse(const char* flags)
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
|
|
||||||
// Check for specific options.
|
// Check for specific options.
|
||||||
bool UsingUnicode();
|
bool UsingUnicode();
|
||||||
|
bool UsingSBCS();
|
||||||
|
|
||||||
bool IsDebug();
|
bool IsDebug();
|
||||||
// Write options to output.
|
// Write options to output.
|
||||||
|
|
|
@ -1306,6 +1306,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
IF(${CMAKE_TEST_GENERATOR} MATCHES "Visual Studio")
|
IF(${CMAKE_TEST_GENERATOR} MATCHES "Visual Studio")
|
||||||
|
ADD_TEST_MACRO(SBCS SBCS)
|
||||||
|
|
||||||
ADD_TEST(VSExternalInclude ${CMAKE_CTEST_COMMAND}
|
ADD_TEST(VSExternalInclude ${CMAKE_CTEST_COMMAND}
|
||||||
--build-and-test
|
--build-and-test
|
||||||
"${CMake_SOURCE_DIR}/Tests/VSExternalInclude"
|
"${CMake_SOURCE_DIR}/Tests/VSExternalInclude"
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
# a SBCS test case
|
||||||
|
project (SBCS)
|
||||||
|
|
||||||
|
add_definitions(-D_SBCS)
|
||||||
|
|
||||||
|
add_executable (SBCS SBCS.cxx)
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Test to verify that _SBCS being defined causes CharacterSet to be set to 0 (Single Byte Character Set)
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
#ifdef _UNICODE
|
||||||
|
bool UnicodeSet=true;
|
||||||
|
#else
|
||||||
|
bool UnicodeSet=false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MBCS
|
||||||
|
bool MBCSSet=true;
|
||||||
|
#else
|
||||||
|
bool MBCSSet=false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// if neither _UNICODE nor _MBCS is set, CharacterSet must be set to SBCS.
|
||||||
|
bool SBCSSet=(!UnicodeSet && !MBCSSet);
|
||||||
|
|
||||||
|
// Reverse boolean to indicate error case correctly
|
||||||
|
return !SBCSSet;
|
||||||
|
}
|
Loading…
Reference in New Issue