diff options
Diffstat (limited to 'devtools/create_project/msbuild.cpp')
-rw-r--r-- | devtools/create_project/msbuild.cpp | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/devtools/create_project/msbuild.cpp b/devtools/create_project/msbuild.cpp index 0f77d91852..23bf1bc28a 100644 --- a/devtools/create_project/msbuild.cpp +++ b/devtools/create_project/msbuild.cpp @@ -52,6 +52,9 @@ int MSBuildProvider::getVisualStudioVersion() { if (_version == 11) return 2012; + if (_version == 12) + return 2013; + error("Unsupported version passed to getVisualStudioVersion"); } @@ -66,7 +69,7 @@ inline void outputConfiguration(std::ostream &project, const std::string &config inline void outputConfigurationType(const BuildSetup &setup, std::ostream &project, const std::string &name, const std::string &config, int version) { project << "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='" << config << "'\" Label=\"Configuration\">\n" - "\t\t<ConfigurationType>" << ((name == setup.projectName || setup.devTools) ? "Application" : "StaticLibrary") << "</ConfigurationType>\n" + "\t\t<ConfigurationType>" << ((name == setup.projectName || setup.devTools || setup.tests) ? "Application" : "StaticLibrary") << "</ConfigurationType>\n" "\t\t<PlatformToolset>v" << version << "0</PlatformToolset>\n" "\t</PropertyGroup>\n"; } @@ -88,7 +91,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=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" + "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" "\t<ItemGroup Label=\"ProjectConfigurations\">\n"; outputConfiguration(project, "Debug", "Win32"); @@ -105,7 +108,7 @@ void MSBuildProvider::createProjectFile(const std::string &name, const std::stri "\t\t<ProjectGuid>{" << uuid << "}</ProjectGuid>\n" "\t\t<RootNamespace>" << name << "</RootNamespace>\n" "\t\t<Keyword>Win32Proj</Keyword>\n" - "\t\t<VCTargetsPath Condition=\"'$(VCTargetsPath11)' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''\">$(VCTargetsPath11)</VCTargetsPath>\n" + "\t\t<VCTargetsPath Condition=\"'$(VCTargetsPath" << _version << ")' != '' and '$(VSVersion)' == '' and $(VisualStudioVersion) == ''\">$(VCTargetsPath" << _version << ")</VCTargetsPath>\n" "\t</PropertyGroup>\n"; // Shared configuration @@ -156,10 +159,26 @@ void MSBuildProvider::createProjectFile(const std::string &name, const std::stri if (name == setup.projectName) writeReferences(setup, project); + // Output auto-generated test runner + if (setup.tests) { + project << "\t<ItemGroup>\n"; + project << "\t\t<ClCompile Include=\"test_runner.cpp\" />\n"; + project << "\t</ItemGroup>\n"; + } + project << "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n" "\t<ImportGroup Label=\"ExtensionTargets\">\n" - "\t</ImportGroup>\n" - "</Project>\n"; + "\t</ImportGroup>\n"; + + if (setup.tests) { + // We override the normal target to ignore the exit code (this allows us to have a clean output and not message about the command exit code) + project << "\t\t<Target Name=\"PostBuildEvent\">\n" + << "\t\t\t<Message Text=\"Description: Run tests\" />\n" + << "\t\t\t<Exec Command=\"$(TargetPath)\" IgnoreExitCode=\"true\" />\n" + << "\t\t</Target>\n"; + } + + project << "</Project>\n"; // Output filter file if necessary createFiltersFile(setup, name); @@ -184,7 +203,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=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"; + "<Project ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"; // Output the list of filters filters << "\t<ItemGroup>\n"; @@ -245,7 +264,7 @@ void MSBuildProvider::outputProjectSettings(std::ofstream &project, const std::s bool disableEditAndContinue = find(_disableEditAndContinue.begin(), _disableEditAndContinue.end(), name) != _disableEditAndContinue.end(); // Nothing to add here, move along! - if (!setup.devTools && name != setup.projectName && !enableLanguageExtensions && !disableEditAndContinue && warningsIterator == _projectWarnings.end()) + if ((!setup.devTools || !setup.tests) && name != setup.projectName && !enableLanguageExtensions && !disableEditAndContinue && warningsIterator == _projectWarnings.end()) return; std::string warnings = ""; @@ -257,7 +276,7 @@ void MSBuildProvider::outputProjectSettings(std::ofstream &project, const std::s "\t\t<ClCompile>\n"; // Language Extensions - if (setup.devTools || name == setup.projectName || enableLanguageExtensions) + if (setup.devTools || setup.tests || name == setup.projectName || enableLanguageExtensions) project << "\t\t\t<DisableLanguageExtensions>false</DisableLanguageExtensions>\n"; // Edit and Continue @@ -271,18 +290,18 @@ void MSBuildProvider::outputProjectSettings(std::ofstream &project, const std::s project << "\t\t</ClCompile>\n"; // Link configuration for main project - if (name == setup.projectName || setup.devTools) { + if (name == setup.projectName || setup.devTools || setup.tests) { std::string libraries; for (StringList::const_iterator i = setup.libraries.begin(); i != setup.libraries.end(); ++i) libraries += *i + ".lib;"; project << "\t\t<Link>\n" - "\t\t\t<OutputFile>$(OutDir)" << (setup.devTools ? name : setup.projectName) << ".exe</OutputFile>\n" + "\t\t\t<OutputFile>$(OutDir)" << ((setup.devTools || setup.tests) ? name : setup.projectName) << ".exe</OutputFile>\n" "\t\t\t<AdditionalDependencies>" << libraries << "%(AdditionalDependencies)</AdditionalDependencies>\n" "\t\t</Link>\n"; - if (!setup.devTools && setup.runBuildEvents) { + if (!setup.devTools && !setup.tests && setup.runBuildEvents) { project << "\t\t<PreBuildEvent>\n" "\t\t\t<Message>Generate revision</Message>\n" "\t\t\t<Command>" << getPreBuildEvent() << "</Command>\n" @@ -293,6 +312,11 @@ void MSBuildProvider::outputProjectSettings(std::ofstream &project, const std::s "\t\t\t<Message>Copy data files to the build folder</Message>\n" "\t\t\t<Command>" << getPostBuildEvent(isWin32, setup.createInstaller) << "</Command>\n" "\t\t</PostBuildEvent>\n"; + } else if (setup.tests) { + project << "\t\t<PreBuildEvent>\n" + "\t\t\t<Message>Generate runner.cpp</Message>\n" + "\t\t\t<Command>" << getTestPreBuildEvent(setup) << "</Command>\n" + "\t\t</PreBuildEvent>\n"; } } @@ -314,9 +338,8 @@ void MSBuildProvider::outputGlobalPropFile(const BuildSetup &setup, std::ofstrea definesList += REVISION_DEFINE ";"; properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" - "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" + "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" "\t<PropertyGroup>\n" - "\t\t<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>\n" "\t\t<_PropertySheetDisplayName>" << setup.projectDescription << "_Global</_PropertySheetDisplayName>\n" "\t\t<ExecutablePath>$(" << LIBS_DEFINE << ")\\bin;$(ExecutablePath)</ExecutablePath>\n" "\t\t<LibraryPath>$(" << LIBS_DEFINE << ")\\lib\\" << (bits == 32 ? "x86" : "x64") << ";$(LibraryPath)</LibraryPath>\n" @@ -328,9 +351,9 @@ void MSBuildProvider::outputGlobalPropFile(const BuildSetup &setup, std::ofstrea "\t\t<ClCompile>\n" "\t\t\t<DisableLanguageExtensions>true</DisableLanguageExtensions>\n" "\t\t\t<DisableSpecificWarnings>" << warnings << ";%(DisableSpecificWarnings)</DisableSpecificWarnings>\n" - "\t\t\t<AdditionalIncludeDirectories>$(" << LIBS_DEFINE << ")\\include;" << prefix << ";" << prefix << "\\engines;$(TargetDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" + "\t\t\t<AdditionalIncludeDirectories>$(" << LIBS_DEFINE << ")\\include;" << prefix << ";" << prefix << "\\engines;" << (setup.tests ? prefix + "\\test\\cxxtest;" : "") << "$(TargetDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n" "\t\t\t<PreprocessorDefinitions>" << definesList << "%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" - "\t\t\t<ExceptionHandling>" << (setup.devTools ? "Sync" : "") << "</ExceptionHandling>\n"; + "\t\t\t<ExceptionHandling>" << ((setup.devTools || setup.tests) ? "Sync" : "") << "</ExceptionHandling>\n"; #if NEEDS_RTTI properties << "\t\t\t<RuntimeTypeInfo>true</RuntimeTypeInfo>\n"; @@ -346,7 +369,7 @@ void MSBuildProvider::outputGlobalPropFile(const BuildSetup &setup, std::ofstrea "\t\t\t<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>\n" "\t\t\t<SubSystem>Console</SubSystem>\n"; - if (!setup.devTools) + if (!setup.devTools && !setup.tests) properties << "\t\t\t<EntryPointSymbol>WinMainCRTStartup</EntryPointSymbol>\n"; properties << "\t\t</Link>\n" @@ -368,12 +391,11 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b error("Could not open \"" + setup.outputDir + '/' + setup.projectDescription + "_" + outputType + (isWin32 ? "" : "64") + getPropertiesExtension() + "\" for writing"); properties << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" - "<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n" + "<Project DefaultTargets=\"Build\" ToolsVersion=\"" << (_version >= 12 ? _version : 4) << ".0\" 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" "\t<PropertyGroup>\n" - "\t\t<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>\n" "\t\t<_PropertySheetDisplayName>" << setup.projectDescription << "_" << outputType << outputBitness << "</_PropertySheetDisplayName>\n" "\t\t<LinkIncremental>" << (isRelease ? "false" : "true") << "</LinkIncremental>\n" "\t</PropertyGroup>\n" @@ -383,7 +405,7 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b if (isRelease) { properties << "\t\t\t<IntrinsicFunctions>true</IntrinsicFunctions>\n" "\t\t\t<WholeProgramOptimization>true</WholeProgramOptimization>\n" - "\t\t\t<PreprocessorDefinitions>WIN32;RELEASE_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" + "\t\t\t<PreprocessorDefinitions>WIN32;DISABLE_GUI_BUILTIN_THEME;RELEASE_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" "\t\t\t<StringPooling>true</StringPooling>\n" "\t\t\t<BufferSecurityCheck>false</BufferSecurityCheck>\n" "\t\t\t<DebugInformationFormat></DebugInformationFormat>\n" @@ -395,7 +417,7 @@ void MSBuildProvider::createBuildProp(const BuildSetup &setup, bool isRelease, b "\t\t\t<SetChecksum>true</SetChecksum>\n"; } else { properties << "\t\t\t<Optimization>Disabled</Optimization>\n" - "\t\t\t<PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" + "\t\t\t<PreprocessorDefinitions>WIN32;DISABLE_GUI_BUILTIN_THEME;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n" "\t\t\t<MinimalRebuild>true</MinimalRebuild>\n" "\t\t\t<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n" "\t\t\t<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n" |