diff options
Diffstat (limited to 'devtools/create_project/create_project.cpp')
-rw-r--r-- | devtools/create_project/create_project.cpp | 231 |
1 files changed, 166 insertions, 65 deletions
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index e71816f575..91690c2128 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -20,7 +20,7 @@ * */ -//#define ENABLE_XCODE +#define ENABLE_XCODE // HACK to allow building with the SDL backend on MinGW // see bug #1800764 "TOOLS: MinGW tools building broken" @@ -31,6 +31,7 @@ #include "config.h" #include "create_project.h" +#include "cmake.h" #include "codeblocks.h" #include "msvc.h" #include "visualstudio.h" @@ -53,7 +54,7 @@ #define USE_WIN32_API #endif -#ifdef USE_WIN32_API +#if (defined(_WIN32) || defined(WIN32)) #include <windows.h> #else #include <sstream> @@ -83,10 +84,18 @@ std::string unifyPath(const std::string &path); * @param exe Name of the executable. */ void displayHelp(const char *exe); + +/** + * Build a list of options to enable or disable GCC warnings + * + * @param globalWarnings Resulting list of warnings + */ +void addGCCWarnings(StringList &globalWarnings); } // End of anonymous namespace enum ProjectType { kProjectNone, + kProjectCMake, kProjectCodeBlocks, kProjectMSVC, kProjectXcode @@ -124,7 +133,7 @@ int main(int argc, char *argv[]) { setup.features = getAllFeatures(); ProjectType projectType = kProjectNone; - int msvcVersion = 9; + int msvcVersion = 12; // Parse command line arguments using std::cout; @@ -141,6 +150,14 @@ int main(int argc, char *argv[]) { return 0; + } else if (!std::strcmp(argv[i], "--cmake")) { + if (projectType != kProjectNone) { + std::cerr << "ERROR: You cannot pass more than one project type!\n"; + return -1; + } + + projectType = kProjectCMake; + } else if (!std::strcmp(argv[i], "--codeblocks")) { if (projectType != kProjectNone) { std::cerr << "ERROR: You cannot pass more than one project type!\n"; @@ -175,7 +192,7 @@ int main(int argc, char *argv[]) { msvcVersion = atoi(argv[++i]); - if (msvcVersion != 9 && msvcVersion != 10 && msvcVersion != 11 && msvcVersion != 12) { + if (msvcVersion != 9 && msvcVersion != 10 && msvcVersion != 11 && msvcVersion != 12 && msvcVersion != 14) { std::cerr << "ERROR: Unsupported version: \"" << msvcVersion << "\" passed to \"--msvc-version\"!\n"; return -1; } @@ -267,6 +284,8 @@ int main(int argc, char *argv[]) { setup.devTools = true; } else if (!std::strcmp(argv[i], "--tests")) { setup.tests = true; + } else if (!std::strcmp(argv[i], "--sdl1")) { + setup.useSDL2 = false; } else { std::cerr << "ERROR: Unknown parameter \"" << argv[i] << "\"\n"; return -1; @@ -332,10 +351,53 @@ int main(int argc, char *argv[]) { StringList featureDefines = getFeatureDefines(setup.features); setup.defines.splice(setup.defines.begin(), featureDefines); - // Windows only has support for the SDL backend, so we hardcode it here (along with winmm) - setup.defines.push_back("WIN32"); + if (projectType == kProjectXcode) { + setup.defines.push_back("POSIX"); + // Define both MACOSX, and IPHONE, but only one of them will be associated to the + // correct target by the Xcode project provider. + // This define will help catching up target dependend files, like "browser_osx.mm" + // The suffix ("_osx", or "_ios") will be used by the project provider to filter out + // the files, according to the target. + setup.defines.push_back("MACOSX"); + setup.defines.push_back("IPHONE"); + } else if (projectType == kProjectMSVC || projectType == kProjectCodeBlocks) { + // Windows only has support for the SDL backend, so we hardcode it here (along with winmm) + setup.defines.push_back("WIN32"); + } else { + // As a last resort, select the backend files to build based on the platform used to build create_project. + // This is broken when cross compiling. +#if defined(_WIN32) || defined(WIN32) + setup.defines.push_back("WIN32"); +#else + setup.defines.push_back("POSIX"); +#endif + } + + bool updatesEnabled = false; + for (FeatureList::const_iterator i = setup.features.begin(); i != setup.features.end(); ++i) { + if (i->enable && !strcmp(i->name, "updates")) + updatesEnabled = true; + } + if (updatesEnabled) { + setup.defines.push_back("USE_SPARKLE"); + if (projectType != kProjectXcode) + setup.libraries.push_back("winsparkle"); + else + setup.libraries.push_back("sparkle"); + } + setup.defines.push_back("SDL_BACKEND"); - setup.libraries.push_back("sdl"); + if (!setup.useSDL2) { + cout << "\nBuilding against SDL 1.2\n\n"; + setup.libraries.push_back("sdl"); + } else { + cout << "\nBuilding against SDL 2.0\n\n"; + // TODO: This also defines USE_SDL2 in the preprocessor, we don't do + // this in our configure/make based build system. Adapt create_project + // to replicate this behavior. + setup.defines.push_back("USE_SDL2"); + setup.libraries.push_back("sdl2"); + } setup.libraries.push_back("winmm"); // Add additional project-specific library @@ -360,50 +422,25 @@ int main(int argc, char *argv[]) { std::cerr << "ERROR: No project type has been specified!\n"; return -1; + case kProjectCMake: + if (setup.devTools || setup.tests) { + std::cerr << "ERROR: Building tools or tests is not supported for the CMake project type!\n"; + return -1; + } + + addGCCWarnings(globalWarnings); + + provider = new CreateProjectTool::CMakeProvider(globalWarnings, projectWarnings); + + break; + case kProjectCodeBlocks: if (setup.devTools || setup.tests) { std::cerr << "ERROR: Building tools or tests is not supported for the CodeBlocks project type!\n"; return -1; } - //////////////////////////////////////////////////////////////////////////// - // Code::Blocks is using GCC behind the scenes, so we need to pass a list - // of options to enable or disable warnings - //////////////////////////////////////////////////////////////////////////// - // - // -Wall - // enable all warnings - // - // -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder - // disable annoying and not-so-useful warnings - // - // -Wpointer-arith -Wcast-qual -Wcast-align - // -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings - // enable even more warnings... - // - // -fno-rtti -fno-exceptions -fcheck-new - // disable RTTI and exceptions, and enable checking of pointers returned - // by "new" - // - //////////////////////////////////////////////////////////////////////////// - - globalWarnings.push_back("-Wall"); - globalWarnings.push_back("-Wno-long-long"); - globalWarnings.push_back("-Wno-multichar"); - globalWarnings.push_back("-Wno-unknown-pragmas"); - globalWarnings.push_back("-Wno-reorder"); - globalWarnings.push_back("-Wpointer-arith"); - globalWarnings.push_back("-Wcast-qual"); - globalWarnings.push_back("-Wcast-align"); - globalWarnings.push_back("-Wshadow"); - globalWarnings.push_back("-Wimplicit"); - globalWarnings.push_back("-Wnon-virtual-dtor"); - globalWarnings.push_back("-Wwrite-strings"); - // The following are not warnings at all... We should consider adding them to - // a different list of parameters. - globalWarnings.push_back("-fno-rtti"); - globalWarnings.push_back("-fno-exceptions"); - globalWarnings.push_back("-fcheck-new"); + addGCCWarnings(globalWarnings); provider = new CreateProjectTool::CodeBlocksProvider(globalWarnings, projectWarnings); @@ -440,6 +477,9 @@ int main(int argc, char *argv[]) { // 4250 ('class1' : inherits 'class2::member' via dominance) // two or more members have the same name. Should be harmless // + // 4267 ('var' : conversion from 'size_t' to 'type', possible loss of data) + // throws tons and tons of warnings (no immediate plan to fix all usages) + // // 4310 (cast truncates constant value) // used in some engines // @@ -455,6 +495,8 @@ int main(int argc, char *argv[]) { // 4512 ('class' : assignment operator could not be generated) // some classes use const items and the default assignment operator cannot be generated // + // 4577 ('noexcept' used with no exception handling mode specified) + // // 4702 (unreachable code) // mostly thrown after error() calls (marked as NORETURN) // @@ -482,6 +524,8 @@ int main(int argc, char *argv[]) { // 4355 ('this' : used in base member initializer list) // only disabled for specific engines where it is used in a safe way // + // 4373 (previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers) + // // 4510 ('class' : default constructor could not be generated) // // 4511 ('class' : copy constructor could not be generated) @@ -510,6 +554,11 @@ int main(int argc, char *argv[]) { globalWarnings.push_back("6385"); globalWarnings.push_back("6386"); + if (msvcVersion == 14) { + globalWarnings.push_back("4267"); + globalWarnings.push_back("4577"); + } + projectWarnings["agi"].push_back("4510"); projectWarnings["agi"].push_back("4610"); @@ -526,6 +575,8 @@ int main(int argc, char *argv[]) { projectWarnings["m4"].push_back("4355"); + projectWarnings["sci"].push_back("4373"); + if (msvcVersion == 9) provider = new CreateProjectTool::VisualStudioProvider(globalWarnings, projectWarnings, msvcVersion); else @@ -563,7 +614,7 @@ int main(int argc, char *argv[]) { globalWarnings.push_back("-fno-exceptions"); globalWarnings.push_back("-fcheck-new"); - provider = new CreateProjectTool::XCodeProvider(globalWarnings, projectWarnings); + provider = new CreateProjectTool::XcodeProvider(globalWarnings, projectWarnings); break; } @@ -607,6 +658,7 @@ void displayHelp(const char *exe) { " Additionally there are the following switches for changing various settings:\n" "\n" "Project specific settings:\n" + " --cmake build CMake project files\n" " --codeblocks build Code::Blocks project files\n" " --msvc build Visual Studio project files\n" " --xcode build XCode project files\n" @@ -623,6 +675,7 @@ void displayHelp(const char *exe) { " 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" " The default is \"9\", thus \"Visual Studio 2008\"\n" " --build-events Run custom build events as part of the build\n" " (default: false)\n" @@ -646,6 +699,9 @@ void displayHelp(const char *exe) { " --enable-<name> enable inclusion of the feature \"name\"\n" " --disable-<name> disable inclusion of the feature \"name\"\n" "\n" + "SDL settings:\n" + " --sdl1 link to SDL 1.2, instead of SDL 2.0\n" + "\n" " There are the following features available:\n" "\n"; @@ -657,6 +713,41 @@ void displayHelp(const char *exe) { cout.setf(std::ios_base::right, std::ios_base::adjustfield); } +void addGCCWarnings(StringList &globalWarnings) { + //////////////////////////////////////////////////////////////////////////// + // + // -Wall + // enable all warnings + // + // -Wno-long-long -Wno-multichar -Wno-unknown-pragmas -Wno-reorder + // disable annoying and not-so-useful warnings + // + // -Wpointer-arith -Wcast-qual -Wcast-align + // -Wshadow -Wimplicit -Wnon-virtual-dtor -Wwrite-strings + // enable even more warnings... + // + // -fno-exceptions -fcheck-new + // disable exceptions, and enable checking of pointers returned by "new" + // + //////////////////////////////////////////////////////////////////////////// + + globalWarnings.push_back("-Wall"); + globalWarnings.push_back("-Wno-long-long"); + globalWarnings.push_back("-Wno-multichar"); + globalWarnings.push_back("-Wno-unknown-pragmas"); + globalWarnings.push_back("-Wno-reorder"); + globalWarnings.push_back("-Wpointer-arith"); + globalWarnings.push_back("-Wcast-qual"); + globalWarnings.push_back("-Wcast-align"); + globalWarnings.push_back("-Wshadow"); + globalWarnings.push_back("-Wnon-virtual-dtor"); + globalWarnings.push_back("-Wwrite-strings"); + // The following are not warnings at all... We should consider adding them to + // a different list of parameters. + globalWarnings.push_back("-fno-exceptions"); + globalWarnings.push_back("-fcheck-new"); +} + /** * Parse the configure.engine file of a given engine directory and return a * list of all defined engines. @@ -902,16 +993,19 @@ TokenList tokenize(const std::string &input, char separator) { namespace { const Feature s_features[] = { // Libraries - { "libz", "USE_ZLIB", "zlib", true, "zlib (compression) support" }, - { "mad", "USE_MAD", "libmad", true, "libmad (MP3) support" }, - { "vorbis", "USE_VORBIS", "libvorbisfile_static libvorbis_static libogg_static", true, "Ogg Vorbis support" }, - { "flac", "USE_FLAC", "libFLAC_static", true, "FLAC support" }, - { "png", "USE_PNG", "libpng", true, "libpng support" }, - { "faad", "USE_FAAD", "libfaad", false, "AAC support" }, - { "mpeg2", "USE_MPEG2", "libmpeg2", false, "MPEG-2 support" }, - { "theora", "USE_THEORADEC", "libtheora_static", true, "Theora decoding support" }, - {"freetype", "USE_FREETYPE2", "freetype", true, "FreeType support" }, - { "jpeg", "USE_JPEG", "jpeg-static", true, "libjpeg support" }, + { "libz", "USE_ZLIB", "zlib", true, "zlib (compression) support" }, + { "mad", "USE_MAD", "libmad", true, "libmad (MP3) support" }, + { "vorbis", "USE_VORBIS", "libvorbisfile_static libvorbis_static libogg_static", true, "Ogg Vorbis support" }, + { "flac", "USE_FLAC", "libFLAC_static win_utf8_io_static", true, "FLAC support" }, + { "png", "USE_PNG", "libpng16", true, "libpng support" }, + { "faad", "USE_FAAD", "libfaad", false, "AAC support" }, + { "mpeg2", "USE_MPEG2", "libmpeg2", false, "MPEG-2 support" }, + { "theora", "USE_THEORADEC", "libtheora_static", true, "Theora decoding support" }, + { "freetype", "USE_FREETYPE2", "freetype", true, "FreeType support" }, + { "jpeg", "USE_JPEG", "jpeg-static", true, "libjpeg support" }, + {"fluidsynth", "USE_FLUIDSYNTH", "libfluidsynth", true, "FluidSynth support" }, + { "libcurl", "USE_LIBCURL", "libcurl", true, "libcurl support" }, + { "sdlnet", "USE_SDL_NET", "SDL_net", true, "SDL_net support" }, // Feature flags { "bink", "USE_BINK", "", true, "Bink video support" }, @@ -920,12 +1014,15 @@ const Feature s_features[] = { { "16bit", "USE_RGB_COLOR", "", true, "16bit color support" }, { "mt32emu", "USE_MT32EMU", "", true, "integrated MT-32 emulator" }, { "nasm", "USE_NASM", "", true, "IA-32 assembly support" }, // This feature is special in the regard, that it needs additional handling. - { "opengl", "USE_OPENGL", "opengl32", true, "OpenGL support" }, + { "opengl", "USE_OPENGL", "", true, "OpenGL support" }, + { "opengles", "USE_GLES", "", true, "forced OpenGL ES mode" }, { "taskbar", "USE_TASKBAR", "", true, "Taskbar integration support" }, + { "cloud", "USE_CLOUD", "", true, "Cloud integration support" }, { "translation", "USE_TRANSLATION", "", true, "Translation support" }, { "vkeybd", "ENABLE_VKEYBD", "", false, "Virtual keyboard support"}, { "keymapper", "ENABLE_KEYMAPPER", "", false, "Keymapper support"}, { "eventrecorder", "ENABLE_EVENTRECORDER", "", false, "Event recorder support"}, + { "updates", "USE_UPDATES", "", false, "Updates support"}, { "langdetect", "USE_DETECTLANG", "", true, "System language detection support" } // This feature actually depends on "translation", there // is just no current way of properly detecting this... }; @@ -1023,18 +1120,24 @@ void splitFilename(const std::string &fileName, std::string &name, std::string & ext = (dot == std::string::npos) ? std::string() : fileName.substr(dot + 1); } +std::string basename(const std::string &fileName) { + const std::string::size_type slash = fileName.find_last_of('/'); + if (slash == std::string::npos) return fileName; + return fileName.substr(slash + 1); +} + bool producesObjectFile(const std::string &fileName) { std::string n, ext; splitFilename(fileName, n, ext); - if (ext == "cpp" || ext == "c" || ext == "asm") + if (ext == "cpp" || ext == "c" || ext == "asm" || ext == "m" || ext == "mm") return true; else return false; } std::string toString(int num) { - return static_cast<std::ostringstream*>(&(std::ostringstream() << num))->str(); + return static_cast<std::ostringstream*>(&(std::ostringstream() << num))->str(); } /** @@ -1116,7 +1219,7 @@ bool compareNodes(const FileNode *l, const FileNode *r) { FileList listDirectory(const std::string &dir) { FileList result; -#ifdef USE_WIN32_API +#if defined(_WIN32) || defined(WIN32) WIN32_FIND_DATA fileInformation; HANDLE fileHandle = FindFirstFile((dir + "/*").c_str(), &fileInformation); @@ -1267,8 +1370,9 @@ void ProjectProvider::createProject(BuildSetup &setup) { for (UUIDMap::const_iterator i = _uuidMap.begin(); i != _uuidMap.end(); ++i) { if (i->first == setup.projectName) continue; - + // Retain the files between engines if we're creating a single project in.clear(); ex.clear(); + const std::string moduleDir = setup.srcDir + targetFolder + i->first; createModuleList(moduleDir, setup.defines, setup.testDirs, in, ex); @@ -1278,7 +1382,6 @@ void ProjectProvider::createProject(BuildSetup &setup) { if (setup.tests) { // Create the main project file. in.clear(); ex.clear(); - createModuleList(setup.srcDir + "/backends", setup.defines, setup.testDirs, in, ex); createModuleList(setup.srcDir + "/backends/platform/sdl", setup.defines, setup.testDirs, in, ex); createModuleList(setup.srcDir + "/base", setup.defines, setup.testDirs, in, ex); @@ -1293,7 +1396,6 @@ void ProjectProvider::createProject(BuildSetup &setup) { } else if (!setup.devTools) { // Last but not least create the main project file. in.clear(); ex.clear(); - // File list for the Project file createModuleList(setup.srcDir + "/backends", setup.defines, setup.testDirs, in, ex); createModuleList(setup.srcDir + "/backends/platform/sdl", setup.defines, setup.testDirs, in, ex); @@ -1308,8 +1410,7 @@ void ProjectProvider::createProject(BuildSetup &setup) { createModuleList(setup.srcDir + "/image", setup.defines, setup.testDirs, in, ex); // Resource files - in.push_back(setup.srcDir + "/icons/" + setup.projectName + ".ico"); - in.push_back(setup.srcDir + "/dists/" + setup.projectName + ".rc"); + addResourceFiles(setup, in, ex); // Various text files in.push_back(setup.srcDir + "/AUTHORS"); |