aboutsummaryrefslogtreecommitdiff
path: root/devtools/create_project
diff options
context:
space:
mode:
authorSupSuper2019-04-15 18:59:00 +0100
committerMatan Bareket2019-04-20 07:47:25 -0400
commit5c0529abc2fd724bdd9e5d52f9394e4f1eacb8b1 (patch)
tree563379bfee83ae7d7cd08e7e246ef355cef839e1 /devtools/create_project
parent71e4bb108a292044f71f260633e7373b239424da (diff)
downloadscummvm-rg350-5c0529abc2fd724bdd9e5d52f9394e4f1eacb8b1.tar.gz
scummvm-rg350-5c0529abc2fd724bdd9e5d52f9394e4f1eacb8b1.tar.bz2
scummvm-rg350-5c0529abc2fd724bdd9e5d52f9394e4f1eacb8b1.zip
CREATE_PROJECT: Refactor Visual Studio version differences
Moved most generation differences to a MSVCVersion class, makes it easier to support new versions without tracking down if-checks everywhere.
Diffstat (limited to 'devtools/create_project')
-rw-r--r--devtools/create_project/create_project.cpp63
-rw-r--r--devtools/create_project/create_project.h32
-rw-r--r--devtools/create_project/msbuild.cpp62
-rw-r--r--devtools/create_project/msbuild.h4
-rw-r--r--devtools/create_project/msvc.cpp12
-rw-r--r--devtools/create_project/msvc.h16
-rw-r--r--devtools/create_project/visualstudio.cpp11
-rw-r--r--devtools/create_project/visualstudio.h3
8 files changed, 108 insertions, 95 deletions
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp
index b415882758..c2a6fc0e26 100644
--- a/devtools/create_project/create_project.cpp
+++ b/devtools/create_project/create_project.cpp
@@ -133,6 +133,7 @@ int main(int argc, char *argv[]) {
setup.features = getAllFeatures();
ProjectType projectType = kProjectNone;
+ const MSVCVersion* msvc = NULL;
int msvcVersion = 12;
// Parse command line arguments
@@ -192,10 +193,6 @@ int main(int argc, char *argv[]) {
msvcVersion = atoi(argv[++i]);
- if (msvcVersion != 9 && msvcVersion != 10 && msvcVersion != 11 && msvcVersion != 12 && msvcVersion != 14 && msvcVersion != 15) {
- std::cerr << "ERROR: Unsupported version: \"" << msvcVersion << "\" passed to \"--msvc-version\"!\n";
- return -1;
- }
} else if (!strncmp(argv[i], "--enable-engine=", 16)) {
const char *names = &argv[i][16];
if (!*names) {
@@ -482,6 +479,12 @@ int main(int argc, char *argv[]) {
break;
case kProjectMSVC:
+ msvc = getMSVCVersion(msvcVersion);
+ if (!msvc) {
+ std::cerr << "ERROR: Unsupported version: \"" << msvcVersion << "\" passed to \"--msvc-version\"!\n";
+ return -1;
+ }
+
////////////////////////////////////////////////////////////////////////////
// For Visual Studio, all warnings are on by default in the project files,
// so we pass a list of warnings to disable globally or per-project
@@ -584,7 +587,7 @@ int main(int argc, char *argv[]) {
globalWarnings.push_back("6385");
globalWarnings.push_back("6386");
- if (msvcVersion == 14 || msvcVersion == 15) {
+ if (msvcVersion >= 14) {
globalWarnings.push_back("4267");
globalWarnings.push_back("4577");
}
@@ -608,9 +611,9 @@ int main(int argc, char *argv[]) {
projectWarnings["sci"].push_back("4373");
if (msvcVersion == 9)
- provider = new CreateProjectTool::VisualStudioProvider(globalWarnings, projectWarnings, msvcVersion);
+ provider = new CreateProjectTool::VisualStudioProvider(globalWarnings, projectWarnings, msvcVersion, *msvc);
else
- provider = new CreateProjectTool::MSBuildProvider(globalWarnings, projectWarnings, msvcVersion);
+ provider = new CreateProjectTool::MSBuildProvider(globalWarnings, projectWarnings, msvcVersion, *msvc);
break;
@@ -700,14 +703,13 @@ void displayHelp(const char *exe) {
" directory\n"
"\n"
"MSVC specific settings:\n"
- " --msvc-version version set the targeted MSVC version. Possible values:\n"
- " 9 stands for \"Visual Studio 2008\"\n"
- " 10 stands for \"Visual Studio 2010\"\n"
- " 11 stands for \"Visual Studio 2012\"\n"
- " 12 stands for \"Visual Studio 2013\"\n"
- " 14 stands for \"Visual Studio 2015\"\n"
- " 15 stands for \"Visual Studio 2017\"\n"
- " The default is \"12\", thus \"Visual Studio 2013\"\n"
+ " --msvc-version version set the targeted MSVC version. Possible values:\n";
+
+ const MSVCList msvc = getAllMSVCVersions();
+ for (MSVCList::const_iterator i = msvc.begin(); i != msvc.end(); ++i)
+ cout << " " << i->version << " stands for \"" << i->name << "\"\n";
+
+ cout << " The default is \"12\", thus \"Visual Studio 2013\"\n"
" --build-events Run custom build events as part of the build\n"
" (default: false)\n"
" --installer Create installer after the build (implies --build-events)\n"
@@ -1082,6 +1084,16 @@ const Tool s_tools[] = {
{ "create_translations", true},
{ "qtable", true}
};
+
+const MSVCVersion s_msvc[] = {
+// Ver Name Solution Project Toolset LLVM
+ { 9, "Visual Studio 2008", "10.00", "2008", "4.0", "v90", "LLVM-vs2008" },
+ { 10, "Visual Studio 2010", "11.00", "2010", "4.0", "v100", "LLVM-vs2010" },
+ { 11, "Visual Studio 2012", "11.00", "2012", "4.0", "v110", "LLVM-vs2012" },
+ { 12, "Visual Studio 2013", "12.00", "2013", "12.0", "v120", "LLVM-vs2013" },
+ { 14, "Visual Studio 2015", "12.00", "14", "14.0", "v140", "LLVM-vs2014" },
+ { 15, "Visual Studio 2017", "12.00", "15", "15.0", "v141", "llvm" }
+};
} // End of anonymous namespace
FeatureList getAllFeatures() {
@@ -1147,6 +1159,27 @@ ToolList getAllTools() {
return tools;
}
+MSVCList getAllMSVCVersions() {
+ const size_t msvcCount = sizeof(s_msvc) / sizeof(s_msvc[0]);
+
+ MSVCList msvcVersions;
+ for (size_t i = 0; i < msvcCount; ++i)
+ msvcVersions.push_back(s_msvc[i]);
+
+ return msvcVersions;
+}
+
+const MSVCVersion *getMSVCVersion(int version) {
+ const size_t msvcCount = sizeof(s_msvc) / sizeof(s_msvc[0]);
+
+ for (size_t i = 0; i < msvcCount; ++i) {
+ if (s_msvc[i].version == version)
+ return &s_msvc[i];
+ }
+
+ return NULL;
+}
+
namespace CreateProjectTool {
//////////////////////////////////////////////////////////////////////////
diff --git a/devtools/create_project/create_project.h b/devtools/create_project/create_project.h
index 932950c555..8295deb3c2 100644
--- a/devtools/create_project/create_project.h
+++ b/devtools/create_project/create_project.h
@@ -277,6 +277,38 @@ struct BuildSetup {
#endif
void NORETURN_PRE error(const std::string &message) NORETURN_POST;
+/**
+ * Structure to describe a Visual Studio version specification.
+ *
+ * This includes various generation details for MSVC projects,
+ * as well as describe the versions supported.
+ */
+struct MSVCVersion {
+ int version; ///< Version number passed as parameter.
+ const char* name; ///< Full program name.
+ const char* solutionFormat; ///< Format used for solution files.
+ const char* solutionVersion; ///< Version number used in solution files.
+ const char* project; ///< Version number used in project files.
+ const char* toolsetMSVC; ///< Toolset version for MSVC compiler.
+ const char* toolsetLLVM; ///< Toolset version for Clang/LLVM compiler.
+};
+typedef std::list<MSVCVersion> MSVCList;
+
+/**
+ * Creates a list of all supported versions of Visual Studio.
+ *
+ * @return A list including all versions available.
+ */
+MSVCList getAllMSVCVersions();
+
+/**
+ * Returns the definitions for a specific Visual Studio version.
+ *
+ * @param version The requested version.
+ * @return The version information, or NULL if the version isn't supported.
+ */
+const MSVCVersion *getMSVCVersion(int version);
+
namespace CreateProjectTool {
/**
diff --git a/devtools/create_project/msbuild.cpp b/devtools/create_project/msbuild.cpp
index 58efa88768..a2cde964e2 100644
--- a/devtools/create_project/msbuild.cpp
+++ b/devtools/create_project/msbuild.cpp
@@ -29,12 +29,11 @@
namespace CreateProjectTool {
//////////////////////////////////////////////////////////////////////////
-// MSBuild Provider (Visual Studio 2010)
+// MSBuild Provider (Visual Studio 2010 and later)
//////////////////////////////////////////////////////////////////////////
-MSBuildProvider::MSBuildProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version)
- : MSVCProvider(global_warnings, project_warnings, version) {
-
+MSBuildProvider::MSBuildProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion& msvc)
+ : MSVCProvider(global_warnings, project_warnings, version, msvc) {
}
const char *MSBuildProvider::getProjectExtension() {
@@ -45,32 +44,6 @@ const char *MSBuildProvider::getPropertiesExtension() {
return ".props";
}
-int MSBuildProvider::getVisualStudioVersion() {
- if (_version == 10)
- return 2010;
-
- if (_version == 11)
- return 2012;
-
- if (_version == 12)
- return 2013;
-
- if (_version == 14)
- return 14;
-
- if (_version == 15)
- return 15;
-
- error("Unsupported version passed to getVisualStudioVersion");
-}
-
-int MSBuildProvider::getSolutionVersion() {
- if (_version == 14 || _version == 15)
- return 14;
-
- return _version + 1;
-}
-
namespace {
inline void outputConfiguration(std::ostream &project, const std::string &config, const std::string &platform) {
@@ -80,7 +53,7 @@ inline void outputConfiguration(std::ostream &project, const std::string &config
"\t\t</ProjectConfiguration>\n";
}
-inline void outputConfigurationType(const BuildSetup &setup, std::ostream &project, const std::string &name, const std::string &config, std::string toolset) {
+inline void outputConfigurationType(const BuildSetup &setup, std::ostream &project, const std::string &name, const std::string &config, const std::string &toolset) {
project << "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='" << config << "'\" Label=\"Configuration\">\n"
"\t\t<ConfigurationType>" << ((name == setup.projectName || setup.devTools || setup.tests) ? "Application" : "StaticLibrary") << "</ConfigurationType>\n"
"\t\t<PlatformToolset>" << toolset << "</PlatformToolset>\n"
@@ -104,7 +77,7 @@ void MSBuildProvider::createProjectFile(const std::string &name, const std::stri
error("Could not open \"" + projectFile + "\" for writing");
project << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
+ "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << _msvcVersion.project << "\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
"\t<ItemGroup Label=\"ProjectConfigurations\">\n";
outputConfiguration(project, "Debug", "Win32");
@@ -129,17 +102,14 @@ void MSBuildProvider::createProjectFile(const std::string &name, const std::stri
// Shared configuration
project << "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n";
- std::string version = _version == 15 ? "v141" : "v" + toString(_version) + "0";
- std::string llvm = "LLVM-vs" + toString(getVisualStudioVersion());
-
- outputConfigurationType(setup, project, name, "Release|Win32", version);
- outputConfigurationType(setup, project, name, "Analysis|Win32", version);
- outputConfigurationType(setup, project, name, "LLVM|Win32", llvm);
- outputConfigurationType(setup, project, name, "Debug|Win32", version);
- outputConfigurationType(setup, project, name, "Release|x64", version);
- outputConfigurationType(setup, project, name, "LLVM|x64", llvm);
- outputConfigurationType(setup, project, name, "Analysis|x64", version);
- outputConfigurationType(setup, project, name, "Debug|x64", version);
+ outputConfigurationType(setup, project, name, "Release|Win32", _msvcVersion.toolsetMSVC);
+ outputConfigurationType(setup, project, name, "Analysis|Win32", _msvcVersion.toolsetMSVC);
+ outputConfigurationType(setup, project, name, "LLVM|Win32", _msvcVersion.toolsetLLVM);
+ outputConfigurationType(setup, project, name, "Debug|Win32", _msvcVersion.toolsetMSVC);
+ outputConfigurationType(setup, project, name, "Release|x64", _msvcVersion.toolsetMSVC);
+ outputConfigurationType(setup, project, name, "LLVM|x64", _msvcVersion.toolsetLLVM);
+ outputConfigurationType(setup, project, name, "Analysis|x64", _msvcVersion.toolsetMSVC);
+ outputConfigurationType(setup, project, name, "Debug|x64", _msvcVersion.toolsetMSVC);
project << "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n"
"\t<ImportGroup Label=\"ExtensionSettings\">\n"
@@ -234,7 +204,7 @@ void MSBuildProvider::createFiltersFile(const BuildSetup &setup, const std::stri
error("Could not open \"" + filtersFile + "\" for writing");
filters << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<Project ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
+ "<Project ToolsVersion=\"" << _msvcVersion.project << "\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n";
// Output the list of filters
filters << "\t<ItemGroup>\n";
@@ -367,7 +337,7 @@ void MSBuildProvider::outputGlobalPropFile(const BuildSetup &setup, std::ofstrea
definesList += REVISION_DEFINE ";";
properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
+ "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << _msvcVersion.project << "\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
"\t<PropertyGroup>\n"
"\t\t<_PropertySheetDisplayName>" << setup.projectDescription << "_Global</_PropertySheetDisplayName>\n"
"\t\t<ExecutablePath>$(" << LIBS_DEFINE << ")\\bin;$(" << LIBS_DEFINE << ")\\bin\\" << (bits == 32 ? "x86" : "x64") << ";$(ExecutablePath)</ExecutablePath>\n"
@@ -421,7 +391,7 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b
error("Could not open \"" + setup.outputDir + '/' + setup.projectDescription + "_" + configuration + (isWin32 ? "" : "64") + getPropertiesExtension() + "\" for writing");
properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
+ "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << _msvcVersion.project << "\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
"\t<ImportGroup Label=\"PropertySheets\">\n"
"\t\t<Import Project=\"" << setup.projectDescription << "_Global" << (isWin32 ? "" : "64") << ".props\" />\n"
"\t</ImportGroup>\n"
diff --git a/devtools/create_project/msbuild.h b/devtools/create_project/msbuild.h
index f92e68ede8..cb01059f3f 100644
--- a/devtools/create_project/msbuild.h
+++ b/devtools/create_project/msbuild.h
@@ -29,7 +29,7 @@ namespace CreateProjectTool {
class MSBuildProvider : public MSVCProvider {
public:
- MSBuildProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version);
+ MSBuildProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion &msvc);
protected:
void createProjectFile(const std::string &name, const std::string &uuid, const BuildSetup &setup, const std::string &moduleDir,
@@ -48,8 +48,6 @@ protected:
const char *getProjectExtension();
const char *getPropertiesExtension();
- int getVisualStudioVersion();
- int getSolutionVersion();
private:
struct FileEntry {
diff --git a/devtools/create_project/msvc.cpp b/devtools/create_project/msvc.cpp
index 1ca8c7f230..8781005d56 100644
--- a/devtools/create_project/msvc.cpp
+++ b/devtools/create_project/msvc.cpp
@@ -31,8 +31,8 @@ namespace CreateProjectTool {
//////////////////////////////////////////////////////////////////////////
// MSVC Provider (Base class)
//////////////////////////////////////////////////////////////////////////
-MSVCProvider::MSVCProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version)
- : ProjectProvider(global_warnings, project_warnings, version) {
+MSVCProvider::MSVCProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion &msvc)
+ : ProjectProvider(global_warnings, project_warnings, version), _msvcVersion(msvc) {
_enableLanguageExtensions = tokenize(ENABLE_LANGUAGE_EXTENSIONS, ',');
_disableEditAndContinue = tokenize(DISABLE_EDIT_AND_CONTINUE, ',');
@@ -52,8 +52,8 @@ void MSVCProvider::createWorkspace(const BuildSetup &setup) {
if (!solution)
error("Could not open \"" + setup.outputDir + '/' + setup.projectName + ".sln\" for writing");
- solution << "Microsoft Visual Studio Solution File, Format Version " << getSolutionVersion() << ".00\n";
- solution << "# Visual Studio " << getVisualStudioVersion() << "\n";
+ solution << "Microsoft Visual Studio Solution File, Format Version " << _msvcVersion.solutionFormat << "\n";
+ solution << "# Visual Studio " << _msvcVersion.solutionVersion << "\n";
// Write main project
if (!setup.devTools) {
@@ -162,10 +162,6 @@ void MSVCProvider::createGlobalProp(const BuildSetup &setup) {
outputGlobalPropFile(setup, properties, 64, x64Defines, convertPathToWin(setup.filePrefix), setup.runBuildEvents);
}
-int MSVCProvider::getSolutionVersion() {
- return _version + 1;
-}
-
std::string MSVCProvider::getPreBuildEvent() const {
std::string cmdLine = "";
diff --git a/devtools/create_project/msvc.h b/devtools/create_project/msvc.h
index ce228b8e95..b10cb569d4 100644
--- a/devtools/create_project/msvc.h
+++ b/devtools/create_project/msvc.h
@@ -29,9 +29,11 @@ namespace CreateProjectTool {
class MSVCProvider : public ProjectProvider {
public:
- MSVCProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version);
+ MSVCProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion &msvcVersion);
protected:
+ const MSVCVersion _msvcVersion;
+
StringList _enableLanguageExtensions;
StringList _disableEditAndContinue;
@@ -70,7 +72,7 @@ protected:
* @param setup Description of the desired build setup.
* @param isRelease Type of property file
* @param isWin32 Bitness of property file
- * @param enableAnalysis PREfast support
+ * @param configuration Name of property file
*/
virtual void createBuildProp(const BuildSetup &setup, bool isRelease, bool isWin32, std::string configuration) = 0;
@@ -80,16 +82,6 @@ protected:
virtual const char *getPropertiesExtension() = 0;
/**
- * Get the Visual Studio version (used by the VS shell extension to launch the correct VS version)
- */
- virtual int getVisualStudioVersion() = 0;
-
- /**
- * Get the Solution version (used in the sln file header)
- */
- virtual int getSolutionVersion();
-
- /**
* Get the command line for the revision tool (shared between all Visual Studio based providers)
*/
std::string getPreBuildEvent() const;
diff --git a/devtools/create_project/visualstudio.cpp b/devtools/create_project/visualstudio.cpp
index 110e643bbd..44bbf6ba91 100644
--- a/devtools/create_project/visualstudio.cpp
+++ b/devtools/create_project/visualstudio.cpp
@@ -32,8 +32,8 @@ namespace CreateProjectTool {
// Visual Studio Provider (Visual Studio 2008)
//////////////////////////////////////////////////////////////////////////
-VisualStudioProvider::VisualStudioProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version)
- : MSVCProvider(global_warnings, project_warnings, version) {
+VisualStudioProvider::VisualStudioProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion& msvc)
+ : MSVCProvider(global_warnings, project_warnings, version, msvc) {
}
const char *VisualStudioProvider::getProjectExtension() {
@@ -44,13 +44,6 @@ const char *VisualStudioProvider::getPropertiesExtension() {
return ".vsprops";
}
-int VisualStudioProvider::getVisualStudioVersion() {
- if (_version == 9)
- return 2008;
-
- error("Unsupported version passed to getVisualStudioVersion");
-}
-
void VisualStudioProvider::createProjectFile(const std::string &name, const std::string &uuid, const BuildSetup &setup, const std::string &moduleDir,
const StringList &includeList, const StringList &excludeList) {
const std::string projectFile = setup.outputDir + '/' + name + getProjectExtension();
diff --git a/devtools/create_project/visualstudio.h b/devtools/create_project/visualstudio.h
index 7eb66c4f2d..29ef9da835 100644
--- a/devtools/create_project/visualstudio.h
+++ b/devtools/create_project/visualstudio.h
@@ -29,7 +29,7 @@ namespace CreateProjectTool {
class VisualStudioProvider : public MSVCProvider {
public:
- VisualStudioProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version);
+ VisualStudioProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version, const MSVCVersion& msvc);
protected:
void createProjectFile(const std::string &name, const std::string &uuid, const BuildSetup &setup, const std::string &moduleDir,
@@ -46,7 +46,6 @@ protected:
const char *getProjectExtension();
const char *getPropertiesExtension();
- int getVisualStudioVersion();
void outputConfiguration(std::ostream &project, const BuildSetup &setup, const std::string &libraries, const std::string &config, const std::string &platform, const std::string &props, const bool isWin32);
void outputConfiguration(const BuildSetup &setup, std::ostream &project, const std::string &toolConfig, const std::string &config, const std::string &platform, const std::string &props);