Example #1
0
int vs_write_cpp()
{
	const char* str;
	int i, b;

	VsPkgData* data = (VsPkgData*)prj_get_data();

	/* Open the file and write the header */
	if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "vcproj")))
		return 0;

	prj_select_config(0);
	io_print("<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n");
	
	tag_open("VisualStudioProject");
	tag_attr("ProjectType=\"Visual C++\"");

	switch (version)
	{
	case VS2002:
		str = "7.00";
		break;
	case VS2003:
		str = "7.10";
		break;
	case VS2005:
		str = "8.00";
		break;
	case VS2008:
		str = "9.00";
		break;
	}
	tag_attr("Version=\"%s\"", str);

	tag_attr("Name=\"%s\"", prj_get_pkgname());
	tag_attr("ProjectGUID=\"{%s}\"", data->projGuid);

	if (version >= VS2005)
		tag_attr("RootNamespace=\"%s\"", prj_get_pkgname());

	tag_attr("Keyword=\"%s\"", prj_has_flag("managed") ? "ManagedCProj" : "Win32Proj");  

	tag_open("Platforms");
	tag_open("Platform");
	tag_attr("Name=\"Win32\"");
	tag_close("Platform", 0);
	tag_close("Platforms", 1);

	if (version >= VS2005)
	{
		tag_open("ToolFiles");
		tag_close("ToolFiles", 1);
	}

	/* Write configurations */
	tag_open("Configurations");
	for (i = 0; i < prj_get_numconfigs(); ++i)
	{
		int optimization, debug, runtime, symbols, configTypeId;
		const char* pchHeader = prj_get_pch_header();

		prj_select_config(i);

		if (prj_is_kind("winexe") || prj_is_kind("exe") || prj_is_kind("cxxtestgen") || prj_is_kind("run"))
		{
			configTypeId = 1;
		}
		else if (prj_is_kind("dll"))
		{
			configTypeId = 2;
		}
		else if (prj_is_kind("lib"))
		{
			configTypeId = 4;
		}
		else if (prj_is_kind("aspnet"))
		{
			puts("** Error: C++ ASP.NET projects are not supported");
			return 0;
		}
		else
		{
			printf("** Error: unknown package kind '%s'\n", prj_get_kind());
			return 0;
		}

		if (prj_has_flag("optimize-speed"))
			optimization = 2;
		else if (prj_has_flag("optimize-size"))
			optimization = 1;
		else if (prj_has_flag("optimize"))
			optimization = 3;
		else
			optimization = 0;

		debug = (optimization ==0);

		if (prj_has_flag("static-runtime"))
			runtime = (debug) ? 1 : 0;
		else
			runtime = (debug) ? 3 : 2;

		if (prj_has_flag("no-symbols"))
			symbols = 0;
		else
			symbols = (prj_has_flag("managed") || prj_has_flag("no-edit-and-continue")) ? 3 : 4;

		tag_open("Configuration");
		tag_attr("Name=\"%s|Win32\"", prj_get_cfgname());
		tag_attr("OutputDirectory=\"%s\"", prj_get_outdir());
		tag_attr("IntermediateDirectory=\"%s\"", prj_get_objdir());
		tag_attr("ConfigurationType=\"%d\"", configTypeId);
		tag_attr("CharacterSet=\"%d\"", prj_has_flag("unicode") ? 1 : 2);
		if (prj_has_flag("managed")) 
			tag_attr("ManagedExtensions=\"%s\"", S_TRUE);

		/* Write out tool blocks */
		for (b = 0; blocks[version][b] != BlocksEnd; ++b)
		{
			tag_open("Tool");
			switch (blocks[version][b])
			{
			case VCPreBuildEventTool:
            tag_attr("Name=\"VCPreBuildEventTool\"");
				break;
			case VCCustomBuildTool:
            tag_attr("Name=\"VCCustomBuildTool\"");
				if (prj_is_kind("run"))
				{
					tag_attr("Description=\"Running CxxTest Test Suite\"");
					tag_attr_open("CommandLine");
					print_list(prj_get_links(), "", "", " ", vs_filter_links);
					print_list(prj_get_buildoptions(), " ", "", "", NULL);
					tag_attr_close();
					// This so that we're always run (and never "up-to-date")
					tag_attr("Outputs=\".\\dummy.file.thats.never.created\"");
				}
				else if (prj_is_kind("cxxtestgen"))
				{
					char *rootfile = strdup(prj_get_cxxtest_rootfile());
					char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows"));
					char *options = strdup(prj_get_cxxtest_rootoptions());

					tag_attr("Description=\"Generating test_root.cpp\"");
					tag_attr("CommandLine=\"%s%s --root %s -o &quot;%s&quot;\"",
						endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"",
						ctpath,
						options,
						rootfile);

					tag_attr("Outputs=\"%s\"", rootfile);

					free(options);
					free(ctpath);
					free(rootfile);
				}
				break;
			case VCXMLDataGeneratorTool:
            tag_attr("Name=\"VCXMLDataGeneratorTool\"");
				break;
			case VCManagedWrapperGeneratorTool:
				tag_attr("Name=\"VCManagedWrapperGeneratorTool\"");
				break;
			case VCAuxiliaryManagedWrapperGeneratorTool:
				tag_attr("Name=\"VCAuxiliaryManagedWrapperGeneratorTool\"");
				break;
			case VCWebServiceProxyGeneratorTool:
            tag_attr("Name=\"VCWebServiceProxyGeneratorTool\"");
				break;
			case VCMIDLTool:
            tag_attr("Name=\"VCMIDLTool\"");
				break;
			case VCManagedResourceCompilerTool:
            tag_attr("Name=\"VCManagedResourceCompilerTool\"");
				break;
			case VCResourceCompilerTool:
				tag_attr("Name=\"VCResourceCompilerTool\"");
				if (prj_get_numincpaths() > 0)
				{
					tag_attr_open("AdditionalIncludeDirectories");
					print_list(prj_get_incpaths(), "", "", ";", NULL);
					tag_attr_close();
				}
				break;
			case VCPreLinkEventTool:
            tag_attr("Name=\"VCPreLinkEventTool\"");
				break;
			case VCALinkTool:
            tag_attr("Name=\"VCALinkTool\"");
				break;
			case VCManifestTool:
            tag_attr("Name=\"VCManifestTool\"");
				break;
			case VCXDCMakeTool:
            tag_attr("Name=\"VCXDCMakeTool\"");
				break;
			case VCBscMakeTool:
            tag_attr("Name=\"VCBscMakeTool\"");
				break;
			case VCFxCopTool:
            tag_attr("Name=\"VCFxCopTool\"");
				break;
			case VCAppVerifierTool:
            tag_attr("Name=\"VCAppVerifierTool\"");
				break;
			case VCWebDeploymentTool:
            tag_attr("Name=\"VCWebDeploymentTool\"");
				break;
			case VCPostBuildEventTool:
				tag_attr("Name=\"VCPostBuildEventTool\"");
				break;
			case VCCLCompilerTool:
				tag_attr("Name=\"VCCLCompilerTool\"");

				if (prj_get_numbuildoptions() > 0)
				{
					tag_attr_open("AdditionalOptions");
					print_list(prj_get_buildoptions(), "", "", " ", NULL);
					tag_attr_close();
				}

				tag_attr("Optimization=\"%d\"", optimization);

				if (prj_has_flag("no-frame-pointer")) 
					tag_attr("OmitFramePointers=\"%s\"", S_TRUE);

				if (prj_get_numincpaths() > 0)
				{
					tag_attr_open("AdditionalIncludeDirectories");
					print_list(prj_get_incpaths(), "", "", ";", NULL);
					tag_attr_close();
				}

				if (prj_has_flag("managed"))
					tag_attr("AdditionalUsingDirectories=\"%s\"", prj_get_bindir());

				if (prj_get_numdefines() > 0)
				{
					tag_attr_open("PreprocessorDefinitions");
					print_list(prj_get_defines(), "", "", ";", NULL);
					tag_attr_close();
				}

				if (debug && !prj_has_flag("managed"))
					tag_attr("MinimalRebuild=\"%s\"", S_TRUE);

				if (prj_has_flag("no-exceptions")) 
					tag_attr("ExceptionHandling=\"%s\"", S_FALSE);

				if (debug && !prj_has_flag("managed"))
					tag_attr("BasicRuntimeChecks=\"3\"");
				
				if (!debug) 
					tag_attr("StringPooling=\"%s\"", S_TRUE);
				
				tag_attr("RuntimeLibrary=\"%d\"", runtime);
				tag_attr("EnableFunctionLevelLinking=\"%s\"", S_TRUE);

				if (version < VS2005 && !prj_has_flag("no-rtti"))
					tag_attr("RuntimeTypeInfo=\"%s\"", S_TRUE);
				if (version >= VS2005 && prj_has_flag("no-rtti"))
					tag_attr("RuntimeTypeInfo=\"%s\"", S_FALSE);

				if (version < VS2005 && prj_has_flag("native-wchar_t"))
					tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_TRUE);
				if (version >= VS2005 && prj_has_flag("no-native-wchar_t"))
					tag_attr("TreatWChar_tAsBuiltInType=\"%s\"", S_FALSE);

				if (pchHeader)
				{
					tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 3 : 2);
					tag_attr("PrecompiledHeaderThrough=\"%s\"", pchHeader);
				}
				else
					tag_attr("UsePrecompiledHeader=\"%d\"", version < VS2005 ? 2 : 0);

				tag_attr("WarningLevel=\"%d\"", prj_has_flag("extra-warnings") ? 4 : 3);
				if (prj_has_flag("fatal-warnings"))
					tag_attr("WarnAsError=\"%s\"", S_TRUE);
				if (version < VS2008 && !prj_has_flag("managed")) 
					tag_attr("Detect64BitPortabilityProblems=\"%s\"", prj_has_flag("no-64bit-checks") ? S_FALSE : S_TRUE);

				tag_attr("DebugInformationFormat=\"%d\"", symbols);
				break;
			case VCLinkerTool:
				if (!prj_is_kind("lib"))
				{
					tag_attr("Name=\"VCLinkerTool\"");
					if (prj_has_flag("no-import-lib"))
						tag_attr("IgnoreImportLibrary=\"%s\"", S_TRUE);

					if (prj_has_flag("use-library-dep-inputs") && version >= VS2005)
						tag_attr("UseLibraryDependencyInputs=\"%s\"", S_TRUE);

					if (prj_get_numlinkoptions() > 0)
					{
						tag_attr_open("AdditionalOptions");
						print_list(prj_get_linkoptions(), " ", "", "", NULL);
						tag_attr_close();
					}

					if (prj_get_numlinks() > 0)
					{
						tag_attr_open("AdditionalDependencies");
						print_list(prj_get_links(), "", ".lib", " ", vs_filter_links);
						tag_attr_close();
					}

					tag_attr("OutputFile=\"$(OutDir)/%s\"", path_getname(prj_get_target()));
					tag_attr("LinkIncremental=\"%d\"", debug ? 2 : 1);

					tag_attr_open("AdditionalLibraryDirectories");
					io_print(prj_get_libdir());
					print_list(prj_get_libpaths(), ";", "", "", NULL);
					tag_attr_close();

					/* Look for a .def file for DLLs */
					if (prj_find_filetype(".def") != NULL)
						tag_attr("ModuleDefinitionFile=\"%s\"", prj_find_filetype(".def"));

					if (prj_has_flag("no-manifest"))
						tag_attr("GenerateManifest=\"%s\"", S_FALSE);

					tag_attr("GenerateDebugInformation=\"%s\"", symbols ? S_TRUE : S_FALSE);
					if (symbols) 
						tag_attr("ProgramDatabaseFile=\"$(OutDir)/%s.pdb\"", path_getbasename(prj_get_target()));

					tag_attr("SubSystem=\"%d\"", prj_is_kind("exe") ? 1 : 2);
					if (!debug) tag_attr("OptimizeReferences=\"2\"");
					if (!debug) tag_attr("EnableCOMDATFolding=\"2\"");

					if ((prj_is_kind("exe") || prj_is_kind("winexe")) && !prj_has_flag("no-main"))
					{
						tag_attr("EntryPointSymbol=\"mainCRTStartup\"");
					}
					else if (prj_is_kind("dll")) 
					{
						tag_attr_open("ImportLibrary");
						if (prj_has_flag("no-import-lib"))
							io_print(prj_get_objdir());
						else
							io_print(prj_get_libdir());
						io_print("/%s.lib", path_getbasename(prj_get_target()));
						tag_attr_close();
					}
					tag_attr("TargetMachine=\"1\"");
				}
				else
				{
					tag_attr("Name=\"VCLibrarianTool\"");
					tag_attr("OutputFile=\"$(OutDir)/%s.lib\"", path_getbasename(prj_get_target()));
				}
				break;
			}
			tag_close("", 0);
		}

		tag_close("Configuration", 1);
	}
	tag_close("Configurations", 1);

	if (version > VS2002)
	{
		tag_open("References");
		tag_close("References", 1);
	}

	tag_open("Files");
	print_source_tree("", vs_list_files);
	/*if (prj_is_kind("cxxtestgen"))
	{
		char *rootfile = strdup(prj_get_cxxtest_rootfile());
		char *ctpath = strdup(path_translate(prj_get_cxxtestpath(), "windows"));
		int i;

		tag_open("File");
		tag_attr_open("RelativePath");
		if (rootfile[0] != '.')
			io_print(".\\");
		io_print(rootfile);
		tag_attr_close();

		for (i = 0; i < prj_get_numconfigs(); ++i)
		{
			char *options;
			prj_select_config(i);

			options = strdup(prj_get_cxxtest_rootoptions());

			tag_open("FileConfiguration");
			tag_attr("Name=\"%s|Win32\"", prj_get_cfgname());

			tag_open("Tool");
			tag_attr("Name=\"VCCustomBuildTool\"");
			tag_attr("Description=\"Generating test_root.cpp\"");
			tag_attr("CommandLine=\"%s%s --root %s -o &quot;%s&quot;\"",
				endsWith(prj_get_cxxtestpath(), ".pl")?"perl ":"",
				ctpath,
				options,
				rootfile);

			tag_attr("Outputs=\"%s\"", rootfile);
			tag_close("Tool", 0);
			tag_close("FileConfiguration", 1);

			free(options);
		}
		tag_close("File", 1);
		free(ctpath);
		free(rootfile);
	}*/
	tag_close("Files", 1);

	tag_open("Globals");
	tag_close("Globals", 1);
	tag_close("VisualStudioProject", 1);

	io_closefile();
	return 1;
}
Example #2
0
int cb_cpp()
{
	int i;

	/* Write the file */
	if (!io_openfile(path_join(prj_get_pkgpath(), prj_get_pkgname(), "cbp")))
		return 0;

	io_print("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n");
	io_print("<CodeBlocks_project_file>\n");
	io_print("\t<FileVersion major=\"1\" minor=\"6\" />\n");
	io_print("\t<Project>\n");
	io_print("\t\t<Option title=\"%s\" />\n", prj_get_pkgname());
	io_print("\t\t<Option pch_mode=\"2\" />\n");
	io_print("\t\t<Option compiler=\"gcc\" />\n");
	io_print("\t\t<Build>\n");

	for (i = 0; i < prj_get_numconfigs(); ++i)
	{
		int kindCode;

		prj_select_config(i);

		io_print("\t\t\t<Target title=\"%s\">\n", prj_get_cfgname());
		io_print("\t\t\t\t<Option output=\"%s\" prefix_auto=\"0\" extension_auto=\"0\" />\n", prj_get_target());
		io_print("\t\t\t\t<Option object_output=\"%s\" />\n", prj_get_objdir());

		if (prj_is_kind("winexe")) 
			kindCode = 0;
		else if (prj_is_kind("exe"))    
			kindCode = 1;
		else if (prj_is_kind("lib"))    
			kindCode = 2;
		else if (prj_is_kind("dll"))    
			kindCode = 3;
		else
		{
			printf("** Unsupported project kind %s\n", prj_get_kind());
			return 0;
		}
		io_print("\t\t\t\t<Option type=\"%d\" />\n", kindCode);

		io_print("\t\t\t\t<Option compiler=\"gcc\" />\n");

		if (prj_is_kind("dll"))
		{
			io_print("\t\t\t\t<Option createDefFile=\"0\" />\n");
			if (prj_has_flag("no-import-lib"))
				io_print("\t\t\t\t<Option createStaticLib=\"0\" />\n");
			else
				io_print("\t\t\t\t<Option createStaticLib=\"1\" />\n");
		}

		io_print("\t\t\t\t<Compiler>\n");
		if (prj_has_flag("extra-warnings"))
			print_opt("-Wall");
		if (prj_has_flag("fatal-warnings"))
			print_opt("-Werror");
		if (prj_has_flag("no-exceptions"))
			print_opt("--no-exceptions");
		if (prj_has_flag("no-frame-pointer"))
			print_opt("-fomit-frame-pointer");
		if (prj_has_flag("no-rtti"))
			print_opt("--no-rtti");
		if (!prj_has_flag("no-symbols"))
			print_opt("-g");
		if (prj_has_flag("optimize-size"))
			print_opt("-Os");
		if (prj_has_flag("optimize-speed"))
			print_opt("-O3");
		if (prj_has_flag("optimize") && !prj_has_flag("optimize-size") && !prj_has_flag("optimize-speed"))
			print_opt("-O");

		if (prj_has_pch())
		{
			/* Warns you if your pch file is out of date */
			print_opt("-Winvalid-pch");
			/* Force include the pch header so the user doesn't need to */
			io_print("\t\t\t\t\t<Add option=\"-include &quot;%s&quot;\" />\n", prj_get_pch_header());
		}
		
		print_list(prj_get_defines(), "\t\t\t\t\t<Add option=\"-D", "\" />\n", "", NULL);
		print_list(prj_get_buildoptions(), "\t\t\t\t\t<Add option=\"", "\" />\n", "", NULL);
		print_list(prj_get_incpaths(), "\t\t\t\t\t<Add directory=\"", "\" />\n", "", NULL); 
		io_print("\t\t\t\t</Compiler>\n");

		io_print("\t\t\t\t<Linker>\n");
		if (prj_has_flag("no-symbols"))
			print_opt("-s");
		print_list(prj_get_linkoptions(), "\t\t\t\t\t<Add option=\"", "\" />\n", "", NULL);

		io_print("\t\t\t\t\t<Add directory=\"%s\" />\n", prj_get_bindir());
		if (!matches(prj_get_bindir(), prj_get_libdir()))
		io_print("\t\t\t\t\t<Add directory=\"%s\" />\n", prj_get_libdir());
		print_list(prj_get_libpaths(), "\t\t\t\t\t<Add directory=\"", "\" />\n", "", NULL);
		print_list(prj_get_links(), "\t\t\t\t\t<Add directory=\"", "\" />\n", "", filterLinksForPaths);
		print_list(prj_get_links(), "\t\t\t\t\t<Add library=\"", "\" />\n", "", filterLinks);
		io_print("\t\t\t\t</Linker>\n");
        
        if (prj_find_filetype(".rc"))
        {
			io_print("\t\t\t\t<ResourceCompiler>\n");
			print_list(prj_get_respaths(), "\t\t\t\t\t<Add directory=\"", "\" />\n", "", NULL);
			io_print("\t\t\t\t</ResourceCompiler>\n");
        }

		if (prj_get_numprebuildcommands() > 0 || prj_get_numpostbuildcommands() > 0)
		{
			io_print("\t\t\t\t<ExtraCommands>\n");
			
			if (prj_get_numprebuildcommands() > 0)
				print_list(prj_get_prebuildcommands(), "\t\t\t\t\t<Add before=\"", "\" />\n", "", NULL);
		
			if (prj_get_numpostbuildcommands() > 0)
				print_list(prj_get_postbuildcommands(), "\t\t\t\t\t<Add after=\"", "\" />\n", "", NULL);

			io_print("\t\t\t\t</ExtraCommands>\n");
		}	

		io_print("\t\t\t</Target>\n");
	}

	io_print("\t\t</Build>\n");

	print_list(prj_get_files(), "", "", "", listFiles);

	io_print("\t\t<Extensions />\n");
	io_print("\t</Project>\n");
	io_print("</CodeBlocks_project_file>\n");

	io_closefile();
	return 1;
}