1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "msvc.h"
#include "config.h"
#include <algorithm>
#include <cstring>
#include <fstream>
namespace CreateProjectTool {
//////////////////////////////////////////////////////////////////////////
// MSVC Provider (Base class)
//////////////////////////////////////////////////////////////////////////
MSVCProvider::MSVCProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, StringList &global_errors, const int version, const MSVCVersion &msvc)
: ProjectProvider(global_warnings, project_warnings, global_errors, version), _msvcVersion(msvc) {
_enableLanguageExtensions = tokenize(ENABLE_LANGUAGE_EXTENSIONS, ',');
_disableEditAndContinue = tokenize(DISABLE_EDIT_AND_CONTINUE, ',');
// NASM not supported for Windows on AMD64 target
StringList amd64_disabled_features;
amd64_disabled_features.push_back("nasm");
_arch_disabled_features[ARCH_AMD64] = amd64_disabled_features;
// NASM not supported for WoA target
StringList arm64_disabled_features;
arm64_disabled_features.push_back("nasm");
_arch_disabled_features[ARCH_ARM64] = arm64_disabled_features;
}
std::string MSVCProvider::getLibraryFromFeature(const char *feature, const BuildSetup &setup, bool isRelease) const {
static const MSVCLibrary s_libraries[] = {
// Libraries
{ "sdl", "SDL.lib", "SDLd.lib", "winmm.lib imm32.lib version.lib setupapi.lib" },
{ "sdl2", "SDL2.lib", "SDL2d.lib", "winmm.lib imm32.lib version.lib setupapi.lib" },
{ "zlib", "zlib.lib", "zlibd.lib", nullptr },
{ "mad", "mad.lib", nullptr, nullptr },
{ "fribidi", "fribidi.lib", nullptr, nullptr },
{ "ogg", "ogg.lib", nullptr, nullptr },
{ "vorbis", "vorbis.lib vorbisfile.lib", nullptr, nullptr },
{ "tremor", "vorbisidec.lib", nullptr, nullptr },
{ "flac", "FLAC.lib", nullptr, nullptr },
{ "png", "libpng16.lib", "libpng16d.lib", nullptr },
{ "gif", "gif.lib", nullptr, nullptr },
{ "faad", "faad.lib", nullptr, nullptr },
{ "mikmod", "mikmod.lib", nullptr, nullptr },
{ "openmpt", "openmpt.lib", nullptr, nullptr },
{ "mpeg2", "mpeg2.lib", nullptr, nullptr },
{ "theoradec", "theora.lib", nullptr, nullptr },
{ "vpx", "vpx.lib", nullptr, nullptr },
{ "freetype2", "freetype.lib", "freetyped.lib", nullptr },
{ "jpeg", "jpeg.lib", nullptr, nullptr },
{"fluidsynth", "fluidsynth.lib", nullptr, nullptr },
{ "fluidlite", "fluidlite.lib", nullptr, nullptr },
{ "libcurl", "libcurl.lib", "libcurl-d.lib", "ws2_32.lib wldap32.lib crypt32.lib normaliz.lib" },
{ "sdlnet", "SDL_net.lib", nullptr, "iphlpapi.lib" },
{ "sdl2net", "SDL2_net.lib", "SDL2_netd.lib", "iphlpapi.lib" },
{ "discord", "discord-rpc.lib", nullptr, nullptr },
{ "retrowave", "RetroWave.lib", nullptr, nullptr },
{ "a52", "a52.lib", nullptr, nullptr },
{ "mpcdec", "libmpcdec.lib", "libmpcdec_d.lib", nullptr },
// Feature flags with library dependencies
{ "updates", "WinSparkle.lib", nullptr, nullptr },
{ "tts", nullptr, nullptr, "sapi.lib" },
{ "opengl", nullptr, nullptr, nullptr },
{ "enet", nullptr, nullptr, "winmm.lib ws2_32.lib" }
};
// HACK for switching SDL_net to SDL2_net
const char *sdl2net = "sdl2net";
if (std::strcmp(feature, "sdlnet") == 0 && setup.useSDL2) {
feature = sdl2net;
}
const MSVCLibrary *library = nullptr;
for (unsigned int i = 0; i < sizeof(s_libraries) / sizeof(s_libraries[0]); i++) {
if (std::strcmp(feature, s_libraries[i].feature) == 0) {
library = &s_libraries[i];
break;
}
}
std::string libs;
if (library) {
// Dependencies come first
if (library->depends) {
libs += library->depends;
libs += " ";
}
// Vcpkg already adds the libs
if (!setup.useVcpkg) {
const char *basename = library->release;
// Debug name takes priority
if (!isRelease && library->debug) {
basename = library->debug;
}
if (basename) {
libs += basename;
}
}
}
return libs;
}
std::string MSVCProvider::outputLibraryDependencies(const BuildSetup &setup, bool isRelease) const {
std::string libs;
if (setup.useSDL2) {
libs += getLibraryFromFeature("sdl2", setup, isRelease);
} else {
libs += getLibraryFromFeature("sdl", setup, isRelease);
}
libs += " ";
for (FeatureList::const_iterator i = setup.features.begin(); i != setup.features.end(); ++i) {
if (i->enable) {
std::string lib = getLibraryFromFeature(i->name, setup, isRelease);
if (!lib.empty())
libs += lib + " ";
}
}
return libs;
}
void MSVCProvider::createWorkspace(const BuildSetup &setup) {
UUIDMap::const_iterator svmUUID = _allProjUuidMap.find(setup.projectName);
if (svmUUID == _allProjUuidMap.end())
error("No UUID for \"" + setup.projectName + "\" project created");
const std::string svmProjectUUID = svmUUID->second;
assert(!svmProjectUUID.empty());
std::string solutionUUID = createUUID(setup.projectName + ".sln");
std::ofstream solution((setup.outputDir + '/' + setup.projectName + ".sln").c_str());
if (!solution || !solution.is_open()) {
error("Could not open \"" + setup.outputDir + '/' + setup.projectName + ".sln\" for writing");
return;
}
solution << "Microsoft Visual Studio Solution File, Format Version " << _msvcVersion.solutionFormat << "\n";
solution << "# Visual Studio " << _msvcVersion.solutionVersion << "\n";
if (_version >= 12) {
solution << "VisualStudioVersion = " << _msvcVersion.project << ".0.0\n";
solution << "MinimumVisualStudioVersion = 10.0.40219.1\n";
}
// Write main project
if (!setup.devTools) {
solution << "Project(\"{" << solutionUUID << "}\") = \"" << setup.projectName << "\", \"" << setup.projectName << getProjectExtension() << "\", \"{" << svmProjectUUID << "}\"\n";
// Project dependencies are moved to vcxproj files in Visual Studio 2010
if (_version < 10)
writeReferences(setup, solution);
solution << "EndProject\n";
}
// Note we assume that the UUID map only includes UUIDs for enabled engines!
for (UUIDMap::const_iterator i = _engineUuidMap.begin(); i != _engineUuidMap.end(); ++i) {
solution << "Project(\"{" << solutionUUID << "}\") = \"" << i->first << "\", \"" << i->first << getProjectExtension() << "\", \"{" << i->second << "}\"\n"
<< "EndProject\n";
}
solution << "Global\n"
"\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
for (std::list<MSVC_Architecture>::const_iterator arch = _archs.begin(); arch != _archs.end(); ++arch) {
solution << "\t\tDebug|" << getMSVCConfigName(*arch) << " = Debug|" << getMSVCConfigName(*arch) << "\n"
<< "\t\tASan|" << getMSVCConfigName(*arch) << " = ASan|" << getMSVCConfigName(*arch) << "\n"
<< "\t\tLLVM|" << getMSVCConfigName(*arch) << " = LLVM|" << getMSVCConfigName(*arch) << "\n"
<< "\t\tRelease|" << getMSVCConfigName(*arch) << " = Release|" << getMSVCConfigName(*arch) << "\n";
}
solution << "\tEndGlobalSection\n"
"\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n";
for (UUIDMap::const_iterator i = _allProjUuidMap.begin(); i != _allProjUuidMap.end(); ++i) {
for (std::list<MSVC_Architecture>::const_iterator arch = _archs.begin(); arch != _archs.end(); ++arch) {
solution << "\t\t{" << i->second << "}.Debug|" << getMSVCConfigName(*arch) << ".ActiveCfg = Debug|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.Debug|" << getMSVCConfigName(*arch) << ".Build.0 = Debug|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.ASan|" << getMSVCConfigName(*arch) << ".ActiveCfg = ASan|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.ASan|" << getMSVCConfigName(*arch) << ".Build.0 = ASan|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.LLVM|" << getMSVCConfigName(*arch) << ".ActiveCfg = LLVM|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.LLVM|" << getMSVCConfigName(*arch) << ".Build.0 = LLVM|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.Release|" << getMSVCConfigName(*arch) << ".ActiveCfg = Release|" << getMSVCConfigName(*arch) << "\n"
<< "\t\t{" << i->second << "}.Release|" << getMSVCConfigName(*arch) << ".Build.0 = Release|" << getMSVCConfigName(*arch) << "\n";
}
}
solution << "\tEndGlobalSection\n"
<< "\tGlobalSection(SolutionProperties) = preSolution\n"
<< "\t\tHideSolutionNode = FALSE\n"
<< "\tEndGlobalSection\n"
<< "EndGlobal\n";
}
void MSVCProvider::createOtherBuildFiles(const BuildSetup &setup) {
// Create the global property file
createGlobalProp(setup);
// Create the configuration property files (for Debug and Release with 32 and 64bits versions)
// Note: we use the debug properties for the asan configuration
for (std::list<MSVC_Architecture>::const_iterator arch = _archs.begin(); arch != _archs.end(); ++arch) {
createBuildProp(setup, true, *arch, "Release");
createBuildProp(setup, false, *arch, "Debug");
createBuildProp(setup, false, *arch, "ASan");
createBuildProp(setup, false, *arch, "LLVM");
}
}
void MSVCProvider::addResourceFiles(const BuildSetup &setup, StringList &includeList, StringList &excludeList) {
includeList.push_back(setup.srcDir + "/icons/" + setup.projectName + ".ico");
includeList.push_back(setup.srcDir + "/dists/" + setup.projectName + ".rc");
}
void MSVCProvider::createGlobalProp(const BuildSetup &setup) {
for (std::list<MSVC_Architecture>::const_iterator arch = _archs.begin(); arch != _archs.end(); ++arch) {
std::ofstream properties((setup.outputDir + '/' + setup.projectDescription + "_Global" + getMSVCArchName(*arch) + getPropertiesExtension()).c_str());
if (!properties)
error("Could not open \"" + setup.outputDir + '/' + setup.projectDescription + "_Global" + getMSVCArchName(*arch) + getPropertiesExtension() + "\" for writing");
BuildSetup archSetup = setup;
std::map<MSVC_Architecture, StringList>::const_iterator arch_disabled_features_it = _arch_disabled_features.find(*arch);
if (arch_disabled_features_it != _arch_disabled_features.end()) {
for (StringList::const_iterator feature = arch_disabled_features_it->second.begin(); feature != arch_disabled_features_it->second.end(); ++feature) {
archSetup = removeFeatureFromSetup(archSetup, *feature);
}
}
outputGlobalPropFile(archSetup, properties, *arch, archSetup.defines, convertPathToWin(archSetup.filePrefix));
properties.close();
}
}
std::string MSVCProvider::getPreBuildEvent() const {
std::string cmdLine = "";
cmdLine = "@echo off\n"
"echo Executing Pre-Build script...\n"
"echo.\n"
"@call "$(SolutionDir)../../devtools/create_project/scripts/prebuild.cmd" "$(SolutionDir)/../.." "$(SolutionDir)"\n"
"EXIT /B0";
return cmdLine;
}
std::string MSVCProvider::getTestPreBuildEvent(const BuildSetup &setup) const {
// Build list of folders containing tests
std::string target = "";
for (StringList::const_iterator it = setup.testDirs.begin(); it != setup.testDirs.end(); ++it)
target += " $(SolutionDir)" + *it + "*.h";
return ""$(SolutionDir)../../test/cxxtest/cxxtestgen.py" --runner=ParenPrinter --no-std --no-eh -o "$(SolutionDir)test_runner.cpp"" + target;
}
std::string MSVCProvider::getPostBuildEvent(MSVC_Architecture arch, const BuildSetup &setup, bool isRelease) const {
std::string cmdLine = "";
cmdLine = "@echo off\n"
"echo Executing Post-Build script...\n"
"echo.\n"
"@call "$(SolutionDir)../../devtools/create_project/scripts/postbuild.cmd" "$(SolutionDir)/../.." "$(OutDir)" ";
cmdLine += (setup.useSDL2) ? "SDL2" : "SDL";
if (setup.useVcpkg) {
cmdLine += " "$(_ZVcpkgCurrentInstalledDir)";
if (!isRelease) {
cmdLine += "debug/";
}
cmdLine += "bin/" ";
} else {
std::string libsPath;
if (setup.libsDir.empty())
libsPath = "%" LIBS_DEFINE "%";
else
libsPath = convertPathToWin(setup.libsDir);
cmdLine += " "";
cmdLine += libsPath;
cmdLine += "/lib/";
cmdLine += getMSVCArchName(arch);
cmdLine += "/$(Configuration)" ";
}
// Specify if installer needs to be built or not
cmdLine += (setup.createInstaller ? "1" : "0");
cmdLine += "\n"
"EXIT /B0";
return cmdLine;
}
} // namespace CreateProjectTool
|