Skip to content

Commit d619325

Browse files
committed
VisualStudio Importer: Define UNICODE=1;_UNICODE=1 if CharacterSet is Unicode
These defines are set by msbuild if CharacterSet is set to Unicode
1 parent e25ca46 commit d619325

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

lib/importproject.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static std::list<std::string> toStringList(const std::string &s)
648648
return ret;
649649
}
650650

651-
static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::string,std::string,cppcheck::stricmp> &variables, std::string &includePath, bool *useOfMfc)
651+
static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::string, std::string, cppcheck::stricmp> &variables, std::string &includePath, bool *useOfMfc, bool *useUnicode)
652652
{
653653
if (useOfMfc) {
654654
for (const tinyxml2::XMLElement *e = node->FirstChildElement(); e; e = e->NextSiblingElement()) {
@@ -658,6 +658,14 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::
658658
}
659659
}
660660
}
661+
if (useUnicode) {
662+
for (const tinyxml2::XMLElement *e = node->FirstChildElement(); e; e = e->NextSiblingElement()) {
663+
if (std::strcmp(e->Name(), "CharacterSet") == 0) {
664+
*useUnicode = std::strcmp(e->GetText(), "Unicode") == 0;
665+
break;
666+
}
667+
}
668+
}
661669

662670
const char* labelAttribute = node->Attribute("Label");
663671
if (labelAttribute && std::strcmp(labelAttribute, "UserMacros") == 0) {
@@ -719,7 +727,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map<std::s
719727
}
720728
}
721729
} else if (std::strcmp(name,"PropertyGroup")==0) {
722-
importPropertyGroup(node, variables, includePath, nullptr);
730+
importPropertyGroup(node, variables, includePath, nullptr, nullptr);
723731
} else if (std::strcmp(name,"ItemDefinitionGroup")==0) {
724732
itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories);
725733
}
@@ -737,6 +745,7 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
737745
std::vector<SharedItemsProject> sharedItemsProjects;
738746

739747
bool useOfMfc = false;
748+
bool useUnicode = false;
740749

741750
tinyxml2::XMLDocument doc;
742751
const tinyxml2::XMLError error = doc.LoadFile(filename.c_str());
@@ -777,7 +786,7 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
777786
} else if (std::strcmp(name, "ItemDefinitionGroup") == 0) {
778787
itemDefinitionGroupList.emplace_back(node, additionalIncludeDirectories);
779788
} else if (std::strcmp(name, "PropertyGroup") == 0) {
780-
importPropertyGroup(node, variables, includePath, &useOfMfc);
789+
importPropertyGroup(node, variables, includePath, &useOfMfc, &useUnicode);
781790
} else if (std::strcmp(name, "ImportGroup") == 0) {
782791
const char *labelAttribute = node->Attribute("Label");
783792
if (labelAttribute && std::strcmp(labelAttribute, "PropertySheets") == 0) {
@@ -879,6 +888,9 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
879888
fs.defines += ";__AVX512__";
880889
additionalIncludePaths += ';' + i.additionalIncludePaths;
881890
}
891+
if (useUnicode) {
892+
fs.defines += ";UNICODE=1;_UNICODE=1";
893+
}
882894
fsSetDefines(fs, fs.defines);
883895
fsSetIncludePaths(fs, Path::getPathFromFilename(filename), toStringList(includePath + ';' + additionalIncludePaths), variables);
884896
for (const auto &path : sharedItemsIncludePaths) {

0 commit comments

Comments
 (0)