/// <summary>
 /// We create targets to build any custom build rules associated with
 /// this configuration.
 /// </summary>
 private void createCustomBuildRuleTargets(ProjectConfigurationInfo_CPP configuration)
 {
     foreach (CustomBuildRuleInfo_CPP ruleInfo in configuration.getCustomBuildRuleInfos())
     {
         createCustomBuildRuleTarget(configuration, ruleInfo);
     }
 }
        /// <summary>
        /// Creates a target for one custom build rule.
        /// </summary>
        private void createCustomBuildRuleTarget(ProjectConfigurationInfo_CPP configuration, CustomBuildRuleInfo_CPP ruleInfo)
        {
            // The rule might be built by one of the other projects in this solution.
            // If so, we need to change the folder name to the adjusted output folder
            // name we generate. (This means that we need to know if the project that
            // generates it is a C++ or C# project.)
            string executablePath = Path.Combine(configuration.ParentProjectInfo.RootFolderAbsolute, ruleInfo.RelativePathToExecutable);

            ProjectInfo.ProjectTypeEnum projectType = m_projectInfo.ParentSolution.isOutputObject(executablePath);

            string folderPrefix = "";

            switch (projectType)
            {
            case ProjectInfo.ProjectTypeEnum.CPP_EXECUTABLE:
                folderPrefix = m_projectConfig.CPPFolderPrefix;
                break;

            case ProjectInfo.ProjectTypeEnum.CSHARP_EXECUTABLE:
                folderPrefix = m_projectConfig.CSharpFolderPrefix;
                break;
            }

            // We add the target to the makefile...
            m_file.WriteLine("# Custom build rule for " + ruleInfo.RelativePathToFile);
            string targetName = getCustomRuleTargetName(configuration, ruleInfo);

            m_file.WriteLine(".PHONY: " + targetName);
            m_file.WriteLine(targetName + ":");
            m_file.WriteLine("\t" + ruleInfo.getCommandLine(folderPrefix));

            m_file.WriteLine("");
        }
        /// <summary>
        /// Gets the target name for the configuration and rule passed in.
        /// </summary>
        private string getCustomRuleTargetName(ProjectConfigurationInfo_CPP configurationInfo, CustomBuildRuleInfo_CPP ruleInfo)
        {
            // The target-name has this form:
            //     [configuration]_CustomBuildRule_[rule-name]_[file-name]
            // For example:
            //     Release_CustomBuildRule_Splitter_TextUtils.code
            string fileName = Path.GetFileName(ruleInfo.RelativePathToFile);

            return(String.Format("{0}_CustomBuildRule_{1}_{2}", configurationInfo.Name, ruleInfo.RuleName, fileName));
        }
Example #4
0
        public static void createCudaLinker(
            StreamWriter writer,
            ProjectInfo_CPP projectInfo,
            ProjectConfigurationInfo_CPP configurationInfo,
            ProjectInfo_CUDA projectCudaInfo)
        {
            if (!projectCudaInfo.IsCUDA || projectCudaInfo.CompileInfos.Count == 0)
            {
                return;
            }

            var projectSettings = MakeItSoConfig.Instance.getProjectConfig(projectInfo.Name);

            var intermediateFolder = MakefileBuilder_Project_CPP.getIntermediateFolder(projectInfo, configurationInfo);

            string files = "";

            foreach (var info in projectCudaInfo.CompileInfos)
            {
                var filename = info.File;

                if (projectSettings.filesOrDirectoriesShouldBeRemoved(filename))
                {
                    continue;
                }

                string path = String.Format("{0}/{1}", intermediateFolder, filename);
                if (filename.StartsWith(".."))
                {
                    var tmp = filename.Replace("../", "");
                    path = String.Format("{0}/{1}", intermediateFolder, tmp);
                }
                string objectPath = Path.ChangeExtension(path, ".o");

                files += objectPath + " ";
            }


            // TODO
            string sm = "sm_20";
            {
                var compileInfo = projectCudaInfo.CompileInfos.Count > 0 ? projectCudaInfo.CompileInfos[0] : projectCudaInfo.AllCompileInfo;

                var opt  = compileInfo.getOption(configurationInfo.Name);
                var gens = getCodeGenerations(opt);
                sm = gens[1];
            }

            var linkedFile = getLinkedCudaFile(intermediateFolder);

            writer.WriteLine("# Link gpu code files.");
            writer.WriteLine("{0}: {1}", linkedFile, files);
            writer.WriteLine("\t$(NVCC) -arch={0} -dlink {1} -o {2}", sm, files, linkedFile);
            writer.WriteLine("");
        }
Example #5
0
        /// <summary>
        /// Parses the configuration (e.g. Debug, Release) passed in.
        /// </summary>
        private void parseConfiguration(VCConfiguration vcConfiguration)
        {
            ProjectConfigurationInfo_CPP configurationInfo = new ProjectConfigurationInfo_CPP();

            configurationInfo.ParentProjectInfo = m_projectInfo;

            IVCCollection sheets    = Utils.call(() => (vcConfiguration.PropertySheets as IVCCollection));
            int           numSheets = Utils.call(() => (sheets.Count));

            for (int i = 1; i <= numSheets; ++i)
            {
                VCPropertySheet sheet = Utils.call(() => (sheets.Item(i) as VCPropertySheet));

                // 1. The thing is that VCPropertySheet and VCConfiguration have more-or-less
                //    identical interfaces. So we should be able to merge them fairly easily.
                //
                // 2. We should try multiple layers of inheritance

                IVCCollection    tools        = Utils.call(() => (sheet.Tools as IVCCollection));
                VCCLCompilerTool compilerTool = Utils.call(() => (tools.Item("VCCLCompilerTool") as VCCLCompilerTool));
            }

            // The configuration name...
            configurationInfo.Name = Utils.call(() => (vcConfiguration.ConfigurationName));

            // The project type.
            // Note: we are assuming that all the configurations for the project build the
            //       same type of target.
            m_projectInfo.ProjectType = parseConfiguration_Type(vcConfiguration);

            // We get the intermediates folder and output folder...
            configurationInfo.IntermediateFolder = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.IntermediateDirectory));
            configurationInfo.OutputFolder       = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.OutputDirectory));

            // We get compiler settings, such as the include path and
            // preprocessor definitions...
            parseConfiguration_CompilerSettings(vcConfiguration, configurationInfo);

            // We get linker settings, such as any libs to link and the library path...
            parseConfiguration_LinkerSettings(vcConfiguration, configurationInfo);

            // We parse librarian settings (how libraries are linked)...
            parseConfiguration_LibrarianSettings(vcConfiguration, configurationInfo);

            // We see if there are any pre- or post- build events set up for this
            // configuration. The only types of events we know how to deal with are
            // ones that invoke a .cmd file. For these we convert them to invoke
            // a .sh file with the same name.
            parseConfiguration_PreBuildEvent(vcConfiguration, configurationInfo);
            parseConfiguration_PostBuildEvent(vcConfiguration, configurationInfo);

            // We add the configuration to the collection of them for the project...
            m_projectInfo.addConfigurationInfo(configurationInfo);
        }
        /// <summary>
        /// Creates targets to compile the files for the configuration passed in.
        /// </summary>
        private void createFileTargets(ProjectConfigurationInfo_CPP configurationInfo)
        {
            // For example:
            //
            //   -include debug/main.d
            //   main.o: main.cpp
            //       g++ -c main.cpp [include-path] -o debug/main.o
            //       g++ -MM main.cpp [include-path] > debug/main.d

            // We find settings that aply to all files in the configuration...
            string intermediateFolder      = getIntermediateFolder(configurationInfo);
            string includePath             = String.Format("$({0})", getIncludePathVariableName(configurationInfo));
            string preprocessorDefinitions = String.Format("$({0})", getPreprocessorDefinitionsVariableName(configurationInfo));
            string compilerFlags           = String.Format("$({0})", getCompilerFlagsVariableName(configurationInfo));

            // We write a section of the makefile to compile each file...
            foreach (string filename in m_projectInfo.getFiles())
            {
                var projectSettings = MakeItSoConfig.Instance.getProjectConfig(m_projectInfo.Name);

                if (projectSettings.filesOrDirectoriesShouldBeRemoved(filename))
                {
                    continue;
                }

                // We work out the filename, the object filename and the
                // dependencies filename...
                string path = String.Format("{0}/{1}", intermediateFolder, filename);
                if (filename.StartsWith(".."))
                {
                    var tmp = filename.Replace("../", "");
                    path = String.Format("{0}/{1}", intermediateFolder, tmp);
                }
                string objectPath       = Path.ChangeExtension(path, ".o");
                string dependenciesPath = Path.ChangeExtension(path, ".d");

                // We decide which compiler to use...
                string compiler = "$(CPP_COMPILER)";
                if (Path.GetExtension(filename).ToLower() == ".c")
                {
                    compiler = "$(C_COMPILER)";
                }

                // We create the target...
                m_file.WriteLine("# Compiles file {0} for the {1} configuration...", filename, configurationInfo.Name);
                m_file.WriteLine("-include {0}", dependenciesPath);
                m_file.WriteLine("{0}: {1}", objectPath, filename);
                m_file.WriteLine("\t{0} {1} {2} -c {3} {4} -o {5}", compiler, preprocessorDefinitions, compilerFlags, filename, includePath, objectPath);
                m_file.WriteLine("\t{0} {1} {2} -MM {3} {4} > {5}", compiler, preprocessorDefinitions, compilerFlags, filename, includePath, dependenciesPath);
                m_file.WriteLine("");
            }
        }
Example #7
0
        /// <summary>
        /// Parses the configuration (e.g. Debug, Release) passed in.
        /// </summary>
        private void parseConfiguration(VCConfiguration vcConfiguration)
        {
            // The configuration name...
            String configName = Utils.call(() => (vcConfiguration.ConfigurationName));

            if (!MakeItSoConfig.Instance.ShouldConvertConfig(configName))
            {
                return;
            }
            VCPlatform vcPlatform   = Utils.call(() => (vcConfiguration.Platform as VCPlatform));
            String     platformName = Utils.call(() => (vcPlatform.Name));

            if (!MakeItSoConfig.Instance.ShouldConvertPlatform(platformName))
            {
                return;
            }

            ProjectConfigurationInfo_CPP configurationInfo = new ProjectConfigurationInfo_CPP();

            configurationInfo.ParentProjectInfo = m_projectInfo;
            configurationInfo.Name = configName + "_" + platformName;

            // The project type.
            // Note: we are assuming that all the configurations for the project build the
            //       same type of target.
            m_projectInfo.ProjectType = parseConfiguration_Type(vcConfiguration);

            // We get the intermediates and output folder, and the Target Name.
            configurationInfo.IntermediateFolder = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.IntermediateDirectory));
            configurationInfo.OutputFolder       = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.OutputDirectory));
            configurationInfo.TargetName         = parseConfiguration_TargetName(vcConfiguration);

            // We get compiler settings, such as the include path and
            // preprocessor definitions...
            parseConfiguration_CompilerSettings(vcConfiguration, configurationInfo);

            // We get linker settings, such as any libs to link and the library path...
            parseConfiguration_LinkerSettings(vcConfiguration, configurationInfo);

            // We parse librarian settings (how libraries are linked)...
            parseConfiguration_LibrarianSettings(vcConfiguration, configurationInfo);

            // We see if there are any pre- or post- build events set up for this
            // configuration. The only types of events we know how to deal with are
            // ones that invoke a .cmd file. For these we convert them to invoke
            // a .sh file with the same name.
            parseConfiguration_PreBuildEvent(vcConfiguration, configurationInfo);
            parseConfiguration_PostBuildEvent(vcConfiguration, configurationInfo);

            // We add the configuration to the collection of them for the project...
            m_projectInfo.addConfigurationInfo(configurationInfo);
        }
        /// <summary>
        /// Parses the configuration (e.g. Debug, Release) passed in.
        /// </summary>
        private void parseConfiguration(VCConfiguration vcConfiguration)
        {
            ProjectConfigurationInfo_CPP configurationInfo = new ProjectConfigurationInfo_CPP();

            configurationInfo.ParentProjectInfo = m_projectInfo;

            // The configuration name...
            configurationInfo.Name = Utils.call(() => (vcConfiguration.ConfigurationName));

            // The project type.
            // Note: we are assuming that all the configurations for the project build the
            //       same type of target.
            m_projectInfo.ProjectType = parseConfiguration_Type(vcConfiguration);

            // We get the intermediates and output folder, and the Target Name.
            configurationInfo.IntermediateFolder = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.IntermediateDirectory));
            configurationInfo.OutputFolder       = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.OutputDirectory));
            configurationInfo.TargetName         = parseConfiguration_TargetName(vcConfiguration);

            // Convert to relative path.
            {
                var url1 = new Uri(m_solutionRootFolder);
                var url2 = new Uri(url1, configurationInfo.OutputFolder);

                var relative = url1.MakeRelativeUri(url2);
                configurationInfo.OutputFolder = relative.ToString();
            }

            // We get compiler settings, such as the include path and
            // preprocessor definitions...
            parseConfiguration_CompilerSettings(vcConfiguration, configurationInfo);

            // We get linker settings, such as any libs to link and the library path...
            parseConfiguration_LinkerSettings(vcConfiguration, configurationInfo);

            // We parse librarian settings (how libraries are linked)...
            parseConfiguration_LibrarianSettings(vcConfiguration, configurationInfo);

            // We see if there are any pre- or post- build events set up for this
            // configuration. The only types of events we know how to deal with are
            // ones that invoke a .cmd file. For these we convert them to invoke
            // a .sh file with the same name.
            parseConfiguration_PreBuildEvent(vcConfiguration, configurationInfo);
            parseConfiguration_PostBuildEvent(vcConfiguration, configurationInfo);

            // We add the configuration to the collection of them for the project...
            m_projectInfo.addConfigurationInfo(configurationInfo);
        }
        /// <summary>
        /// Creates a target for the pre-build event, if there is one.
        /// </summary>
        private void createPreBuildEventTarget(ProjectConfigurationInfo_CPP configurationInfo)
        {
            if (configurationInfo.PreBuildEvent == "")
            {
                return;
            }

            m_file.WriteLine("# Pre-build step...");
            string targetName = getPreBuildTargetName(configurationInfo);

            m_file.WriteLine(".PHONY: " + targetName);
            m_file.WriteLine(targetName + ":");
            m_file.WriteLine("\t" + configurationInfo.PreBuildEvent);

            m_file.WriteLine("");
        }
Example #10
0
        public static void createFileTargets(
            StreamWriter writer,
            ProjectInfo_CPP projectInfo,
            ProjectConfigurationInfo_CPP configurationInfo,
            ProjectInfo_CUDA projectCudaInfo)
        {
            if (!projectCudaInfo.IsCUDA)
            {
                return;
            }

            var includePath             = String.Format("$({0})", MakefileBuilder_Project_CPP.getIncludePathVariableName(configurationInfo));
            var preprocessorDefinitions = String.Format("$({0})", MakefileBuilder_Project_CPP.getPreprocessorDefinitionsVariableName(configurationInfo));
            var intermediateFolder      = MakefileBuilder_Project_CPP.getIntermediateFolder(projectInfo, configurationInfo);

            var projectSettings = MakeItSoConfig.Instance.getProjectConfig(projectInfo.Name);

            foreach (var info in projectCudaInfo.CompileInfos)
            {
                var filename = info.File;

                if (projectSettings.filesOrDirectoriesShouldBeRemoved(filename))
                {
                    continue;
                }

                var    opt          = info.getOption(configurationInfo.Name);
                string compileFlags = getCudaCompileFlags(configurationInfo, opt);

                string path = String.Format("{0}/{1}", intermediateFolder, filename);
                if (filename.StartsWith(".."))
                {
                    var tmp = filename.Replace("../", "");
                    path = String.Format("{0}/{1}", intermediateFolder, tmp);
                }
                string objectPath = Path.ChangeExtension(path, ".o");

                writer.WriteLine("# Compiles file {0} for the {1} configuration...", filename, configurationInfo.Name);
                writer.WriteLine("{0}: {1}", objectPath, filename);
                writer.WriteLine("\t$(NVCC) {0} {1} {2} -c {3} -o {4}", compileFlags, includePath, preprocessorDefinitions, filename, objectPath);
                writer.WriteLine("");
            }
        }
Example #11
0
        /// <summary>
        /// Finds the collection of additional libraries to link into this project.
        /// </summary>
        private void parseLinkerSettings_Libraries(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            List <string> additionalDepenedencies = ToolPropertyCollector.Get(vcConfiguration, "VCLinkerTool", (tool) =>
            {
                var linkerTool = tool as VCLinkerTool;
                string str     = Utils.call(() => (linkerTool.AdditionalDependencies));
                if (str == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(str, ' '));
            });

            foreach (string additionalLibrary in additionalDepenedencies)
            {
                // We add the library to the project...
                string rawName = Path.GetFileNameWithoutExtension(additionalLibrary);
                configurationInfo.addLibraryRawName(rawName);
            }
        }
Example #12
0
        /// <summary>
        /// We parse the post-build events.
        /// </summary>
        private void parseConfiguration_PostBuildEvent(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We see if there is a pre-build event...
            IVCCollection        tools          = Utils.call(() => (vcConfiguration.Tools as IVCCollection));
            VCPostBuildEventTool postBuildEvent = Utils.call(() => (tools.Item("VCPostBuildEventTool") as VCPostBuildEventTool));

            if (postBuildEvent == null)
            {
                return;
            }
            string commandLine = Utils.call(() => (postBuildEvent.CommandLine));

            configurationInfo.PostBuildEvent = convertBuildEventCommandLine(commandLine);
        }
Example #13
0
        /// <summary>
        /// Parses the configuration (e.g. Debug, Release) passed in.
        /// </summary>
        private void parseConfiguration(VCConfiguration vcConfiguration)
        {
            ProjectConfigurationInfo_CPP configurationInfo = new ProjectConfigurationInfo_CPP();

            configurationInfo.ParentProjectInfo = m_projectInfo;

            // The configuration name...
            configurationInfo.Name = Utils.call(() => (vcConfiguration.ConfigurationName));

            // The project type.
            // Note: we are assuming that all the configurations for the project build the
            //       same type of target.
            m_projectInfo.ProjectType = parseConfiguration_Type(vcConfiguration);

            // Do not proceed for "invalid" configurations:
            // 'Makefile' configurations cannot be automatically converted and therefore will be deemed invalid.
            if (m_projectInfo.ProjectType == ProjectInfo.ProjectTypeEnum.INVALID)
            {
                Log.log("  unsupported configuration type - skipping");
                return;
            }

            // We get the intermediates folder and output folder...
            configurationInfo.IntermediateFolder = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.IntermediateDirectory));
            configurationInfo.OutputFolder       = parseConfiguration_Folder(vcConfiguration, () => (vcConfiguration.OutputDirectory));

            // Get Unicode / MBCS settings
            switch (Utils.call(() => (vcConfiguration.CharacterSet)))
            {
            case charSet.charSetMBCS:
                configurationInfo.CharacterSet = CharacterSet.MBCS;
                break;

            case charSet.charSetUnicode:
                configurationInfo.CharacterSet = CharacterSet.Unicode;
                break;

            case charSet.charSetNotSet:
                configurationInfo.CharacterSet = CharacterSet.NotSet;
                break;
            }

            // We get compiler settings, such as the include path and
            // preprocessor definitions...
            parseConfiguration_CompilerSettings(vcConfiguration, configurationInfo);

            // We get linker settings, such as any libs to link and the library path...
            parseConfiguration_LinkerSettings(vcConfiguration, configurationInfo);

            // We parse librarian settings (how libraries are linked)...
            parseConfiguration_LibrarianSettings(vcConfiguration, configurationInfo);

            // We see if there are any pre- or post- build events set up for this
            // configuration. The only types of events we know how to deal with are
            // ones that invoke a .cmd file. For these we convert them to invoke
            // a .sh file with the same name.
            parseConfiguration_PreBuildEvent(vcConfiguration, configurationInfo);
            parseConfiguration_PostBuildEvent(vcConfiguration, configurationInfo);

            // We add the configuration to the collection of them for the project...
            m_projectInfo.addConfigurationInfo(configurationInfo);
        }
 /// <summary>
 /// Returns the preprocessor-definitions variable name for the configuration passed in.
 /// For example "Debug_Preprocessor_Definitions".
 /// </summary>
 private string getPreprocessorDefinitionsVariableName(ProjectConfigurationInfo_CPP configuration)
 {
     return(configuration.Name + "_Preprocessor_Definitions");
 }
 /// <summary>
 /// Returns the compiler-flags variable name for the configuration passed in.
 /// For example "Debug_Compiler_Flags".
 /// </summary>
 private string getCompilerFlagsVariableName(ProjectConfigurationInfo_CPP configuration)
 {
     return(configuration.Name + "_Compiler_Flags");
 }
 /// <summary>
 /// Returns the include-path variable name for the configuration passed in.
 /// For example "Debug_Include_Path".
 /// </summary>
 private string getIncludePathVariableName(ProjectConfigurationInfo_CPP configuration)
 {
     return(configuration.Name + "_Include_Path");
 }
 /// <summary>
 /// Returns the libraries variable name for the configuration passed in.
 /// For example "Debug_Libraries".
 /// </summary>
 private string getLibrariesVariableName(ProjectConfigurationInfo_CPP configuration)
 {
     return(configuration.Name + "_Libraries");
 }
Example #18
0
        /// <summary>
        /// Processes the preprocessor definitions of a given compiler tool and inherits (from the next property sheets) as necessary.
        /// </summary>
        private void parseCompilerSettings_PreprocessorDefinitions(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            List <string> definitions = ToolPropertyCollector.Get(vcConfiguration, "VCCLCompilerTool", (tool) =>
            {
                var compilerTool = tool as VCCLCompilerTool;
                string str       = Utils.call(() => (compilerTool.PreprocessorDefinitions));
                if (str == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(str, ';'));
            });

            foreach (var definition in definitions)
            {
                configurationInfo.addPreprocessorDefinition(definition);
            }
        }
 /// <summary>
 /// Returns the implictly-linked-objects variable name for the configuration passed in.
 /// For example "Debug_Implicitly_Linked_Objects".
 /// </summary>
 private string getImplicitlyLinkedObjectsVariableName(ProjectConfigurationInfo_CPP configuration)
 {
     return(configuration.Name + "_Implicitly_Linked_Objects");
 }
Example #20
0
        /// <summary>
        /// Finds the collection of preprocessor definitions for the configuration passed in.
        /// </summary>
        private void parseCompilerSettings_PreprocessorDefinitions(VCConfiguration vcConfiguration, VCCLCompilerTool compilerTool, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We read the delimited string of preprocessor definitions, and
            // split them...
            string strPreprocessorDefinitions = Utils.call(() => (compilerTool.PreprocessorDefinitions));

            if (strPreprocessorDefinitions == null)
            {
                return;
            }
            List <string> preprocessorDefinitions = Utils.split(strPreprocessorDefinitions, ';');

            // We add the definitions to the parsed configuration (removing ones that
            // aren't relevant to a linux build)...
            foreach (string definition in preprocessorDefinitions)
            {
                configurationInfo.addPreprocessorDefinition(definition);
            }
        }
Example #21
0
        /// <summary>
        /// Finds the collection of include paths for the configuration passed in.
        /// </summary>
        private void parseCompilerSettings_IncludePath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            List <string> paths = ToolPropertyCollector.Get(vcConfiguration, "VCCLCompilerTool", (tool) =>
            {
                var compilerTool = tool as VCCLCompilerTool;
                string strAdditionalIncludeDirectories = Utils.call(() => (compilerTool.AdditionalIncludeDirectories));
                if (strAdditionalIncludeDirectories == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(strAdditionalIncludeDirectories, ';', ',').Select(s => s.Trim('"')).ToList());
            });

            foreach (var path in paths)
            {
                // Resolve variables
                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(path)));
                if (resolvedPath != "")
                {
                    // Make sure all paths are relative to the project root folder
                    string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                    configurationInfo.addIncludePath(relativePath);
                }
            }
        }
 /// <summary>
 /// Gets the name for the pre-build event target for the configuration
 /// passed in.
 /// </summary>
 private string getPreBuildTargetName(ProjectConfigurationInfo_CPP configurationInfo)
 {
     return(configurationInfo.Name + "_PreBuildEvent");
 }
Example #23
0
        /// <summary>
        /// We parse the librarian settings, ie link options for libraries.
        /// </summary>
        private void parseConfiguration_LibrarianSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We get the librarian 'tool'...
            IVCCollection   tools         = Utils.call(() => (vcConfiguration.Tools as IVCCollection));
            VCLibrarianTool librarianTool = Utils.call(() => (tools.Item("VCLibrarianTool") as VCLibrarianTool));

            if (librarianTool == null)
            {
                // Not all projects have a librarian tool...
                return;
            }

            // We find if this library is set to link together other libraries it depends on...
            // (We are assuming that all configurations of the project have the same link-library-dependencies setting.)
            m_projectInfo.LinkLibraryDependencies = Utils.call(() => (librarianTool.LinkLibraryDependencies));
        }
Example #24
0
        /// <summary>
        /// Finds the library path for the configuration passed in.
        /// </summary>
        private void parseLinkerSettings_LibraryPath(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // Get the library paths across all property sheets
            List <string> libraryPaths = ToolPropertyCollector.Get(vcConfiguration, "VCLinkerTool", (tool) =>
            {
                var linkerTool = tool as VCLinkerTool;
                string str     = Utils.call(() => (linkerTool.AdditionalLibraryDirectories));
                if (str == null)
                {
                    return(null);
                }
                // The string may be quoted. We need to remove the quotes.
                // (TODO: We might need to handle quotes in a smarter manner.)
                return(Utils.split(str, ';').Select(s => s.Trim('"')).ToList());
            });

            // Process the library paths
            foreach (string libraryPath in libraryPaths)
            {
                if (libraryPath == "")
                {
                    continue;
                }

                string resolvedPath = Utils.call(() => (vcConfiguration.Evaluate(libraryPath)));
                if (resolvedPath == "")
                {
                    continue;
                }

                string relativePath = Utils.makeRelativePath(m_projectInfo.RootFolderAbsolute, resolvedPath);
                configurationInfo.addLibraryPath(relativePath);
            }
        }
Example #25
0
        /// <summary>
        /// Reads miscellaneous linker settings.
        /// </summary>
        private void parseLinkerSettings_Misc(VCConfiguration vcConfiguration, VCLinkerTool linkerTool, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // Whether we implicitly link in libraries we depend on.
            // (We are assuming that all configurations of the project have the
            // same link-library-dependencies setting.)
            m_projectInfo.LinkLibraryDependencies = Utils.call(() => (linkerTool.LinkLibraryDependencies));

            // Generate debug info...
            bool debugInfo = Utils.call(() => (linkerTool.GenerateDebugInformation));

            if (debugInfo == true
                &&
                configurationInfo.getPreprocessorDefinitions().Contains("NDEBUG") == false)
            {
                configurationInfo.addCompilerFlag("-g");
            }
        }
Example #26
0
        /// <summary>
        /// Finds the linker settings, such as the collection of libraries to link,
        /// for the configuration passed in.
        /// </summary>
        private void parseConfiguration_LinkerSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We get the linker-settings 'tool'...
            IVCCollection tools      = Utils.call(() => (vcConfiguration.Tools as IVCCollection));
            VCLinkerTool  linkerTool = Utils.call(() => (tools.Item("VCLinkerTool") as VCLinkerTool));

            if (linkerTool == null)
            {
                // Not all projects have a linker tools...
                return;
            }

            // And extract various details from it...
            parseLinkerSettings_LibraryPath(vcConfiguration, configurationInfo);
            parseLinkerSettings_Libraries(vcConfiguration, configurationInfo);
            parseLinkerSettings_Misc(vcConfiguration, linkerTool, configurationInfo);
        }
        /// <summary>
        /// Creates a configuration target.
        /// </summary>
        private void createConfigurationTarget(ProjectConfigurationInfo_CPP configurationInfo)
        {
            // For example:
            //
            //   .PHONY: Debug
            //   Debug: debug/main.o debug/math.o debug/utility.o
            //       g++ debug/main.o debug/math.o debug/utility.o -o output/hello.exe

            // The target name...
            m_file.WriteLine("# Builds the {0} configuration...", configurationInfo.Name);
            m_file.WriteLine(".PHONY: {0}", configurationInfo.Name);

            // The targets that this target depends on...
            var dependencies = new List <string>();

            dependencies.Add("create_folders");

            // Is there a pre-build event for this configuration?
            if (configurationInfo.PreBuildEvent != "")
            {
                string preBuildTargetName = getPreBuildTargetName(configurationInfo);
                dependencies.Add(preBuildTargetName);
            }

            // We add any custom build targets as dependencies...
            foreach (CustomBuildRuleInfo_CPP ruleInfo in configurationInfo.getCustomBuildRuleInfos())
            {
                string ruleTargetName = getCustomRuleTargetName(configurationInfo, ruleInfo);
                dependencies.Add(ruleTargetName);
            }

            // The object files the target depends on...
            string intermediateFolder = getIntermediateFolder(configurationInfo);
            var    objectFiles        = new List <string>();

            foreach (string filename in m_projectInfo.getFiles())
            {
                string path = String.Format("{0}/{1}.o", intermediateFolder, Path.GetFileNameWithoutExtension(filename));
                objectFiles.Add(path);
                dependencies.Add(path);
            }

            // We write the dependencies...
            m_file.WriteLine("{0}: {1}", configurationInfo.Name, Utils.join(" ", dependencies));

            // We find variables needed for the link step...
            string outputFolder = getOutputFolder(configurationInfo);

            // The link step...
            switch (m_projectInfo.ProjectType)
            {
            // Creates a C++ executable...
            case ProjectInfo_CPP.ProjectTypeEnum.CPP_EXECUTABLE:
            {
                m_file.WriteLine("\t$(CPP_COMPILER) {0} $({1}) $({2}) -Wl,-rpath,./ -o {3}/{4}.exe",
                                 Utils.join(" ", objectFiles),
                                 getLibraryPathVariableName(configurationInfo),
                                 getLibrariesVariableName(configurationInfo),
                                 outputFolder,
                                 m_projectInfo.Name);
                break;
            }

            // Creates a static library...
            case ProjectInfo_CPP.ProjectTypeEnum.CPP_STATIC_LIBRARY:
            {
                m_file.WriteLine("\tar rcs {0}/lib{1}.a {2} $({3})",
                                 outputFolder,
                                 m_projectInfo.Name,
                                 Utils.join(" ", objectFiles),
                                 getImplicitlyLinkedObjectsVariableName(configurationInfo));
                break;
            }

            // Creates a DLL (shared-objects) library...
            case ProjectInfo_CPP.ProjectTypeEnum.CPP_DLL:
            {
                string dllName, pic;
                if (MakeItSoConfig.Instance.IsCygwinBuild == true)
                {
                    dllName = String.Format("lib{0}.dll", m_projectInfo.Name);
                    pic     = "";
                }
                else
                {
                    dllName = String.Format("lib{0}.so", m_projectInfo.Name);
                    pic     = "-fPIC";
                }

                m_file.WriteLine("\t$(CPP_COMPILER) {0} -shared -Wl,-soname,{1} -o {2}/{1} {3} $({4}) $({5}) $({6})",
                                 pic,
                                 dllName,
                                 outputFolder,
                                 Utils.join(" ", objectFiles),
                                 getImplicitlyLinkedObjectsVariableName(configurationInfo),
                                 getLibraryPathVariableName(configurationInfo),
                                 getLibrariesVariableName(configurationInfo));
                break;
            }
            }

            // The post-build step, if there is one...
            if (configurationInfo.PostBuildEvent != "")
            {
                m_file.WriteLine("\t" + configurationInfo.PostBuildEvent);
            }

            m_file.WriteLine("");
        }
Example #28
0
        /// <summary>
        /// Finds compiler settings, such as the include path, for the configuration
        /// passed in.
        /// </summary>
        private void parseConfiguration_CompilerSettings(VCConfiguration vcConfiguration, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // We get the compiler-settings 'tool'...
            IVCCollection    tools        = Utils.call(() => (vcConfiguration.Tools as IVCCollection));
            VCCLCompilerTool compilerTool = Utils.call(() => (tools.Item("VCCLCompilerTool") as VCCLCompilerTool));

            if (compilerTool == null)
            {
                // This should not usually happen
                Log.log("  warning: configuration has no compiler tool");
                return;
            }

            // And extract various details from it...
            parseCompilerSettings_IncludePath(vcConfiguration, configurationInfo);
            parseCompilerSettings_PreprocessorDefinitions(vcConfiguration, configurationInfo);
            parseCompilerSettings_CompilerFlags(vcConfiguration, compilerTool, configurationInfo);
        }
 /// <summary>
 /// Returns the folder to use for intermediate files.
 /// </summary>
 private string getOutputFolder(ProjectConfigurationInfo_CPP configuration)
 {
     return(Utils.addPrefixToFolderPath(configuration.OutputFolder, m_projectConfig.CPPFolderPrefix));
 }
Example #30
0
        /// <summary>
        /// Finds compiler flags.
        /// </summary>
        private void parseCompilerSettings_CompilerFlags(VCConfiguration vcConfiguration, VCCLCompilerTool compilerTool, ProjectConfigurationInfo_CPP configurationInfo)
        {
            // Warning level...
            warningLevelOption warningLevel = Utils.call(() => (compilerTool.WarningLevel));

            switch (warningLevel)
            {
            case warningLevelOption.warningLevel_0:
                configurationInfo.addCompilerFlag("-w");
                break;

            case warningLevelOption.warningLevel_4:
                configurationInfo.addCompilerFlag("-Wall");
                break;
            }

            // Warnings as errors...
            bool warningsAsErrors = Utils.call(() => (compilerTool.WarnAsError));

            if (warningsAsErrors == true)
            {
                configurationInfo.addCompilerFlag("-Werror");
            }

            // Optimization...
            optimizeOption optimization = Utils.call(() => (compilerTool.Optimization));

            switch (optimization)
            {
            case optimizeOption.optimizeDisabled:
                configurationInfo.addCompilerFlag("-O0");
                break;

            case optimizeOption.optimizeMinSpace:
                configurationInfo.addCompilerFlag("-Os");
                break;

            case optimizeOption.optimizeMaxSpeed:
                configurationInfo.addCompilerFlag("-O2");
                break;

            case optimizeOption.optimizeFull:
                configurationInfo.addCompilerFlag("-O3");
                break;
            }

            // Treat wchar_t as Built-in Type
            bool treatWChar_tAsBuiltInType = Utils.call(() => (compilerTool.TreatWChar_tAsBuiltInType));

            if (!treatWChar_tAsBuiltInType)
            {
                configurationInfo.addCompilerFlag("-fshort-wchar");
            }
        }