Skip to content

Commit

Permalink
Custom build rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-shepherd committed Feb 14, 2012
1 parent 3694fbf commit f7209ce
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 27 deletions.
9 changes: 6 additions & 3 deletions MakeItSo/MakefileBuilder_Project_CPP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,13 @@ private void createCustomBuildRuleTarget(ProjectConfigurationInfo_CPP configurat

// We find the path to the executable for the rule...
string executablePath = Path.Combine(configuration.ParentProjectInfo.RootFolderAbsolute, ruleInfo.RelativePathToExecutable);
string executableFolder = Path.GetDirectoryName(executablePath);

// 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.)
ProjectInfo.ProjectTypeEnum projectType = m_projectInfo.ParentSolution.isOutputObject(executablePath);


//string commandLine = m_relativePathToExecutable;
//foreach (string parameter in m_parameters)
Expand Down Expand Up @@ -621,15 +622,17 @@ private void createCleanTarget()
/// </summary>
private string getIntermediateFolder(ProjectConfigurationInfo_CPP configuration)
{
return Utils.addPrefixToFolderPath(configuration.IntermediateFolder, "gcc");
string prefix = MakeItSoConfig.Instance.getProjectConfig(m_projectInfo.Name).CPPFolderPrefix;
return Utils.addPrefixToFolderPath(configuration.IntermediateFolder, prefix);
}

/// <summary>
/// Returns the folder to use for intermediate files.
/// </summary>
private string getOutputFolder(ProjectConfigurationInfo_CPP configuration)
{
return Utils.addPrefixToFolderPath(configuration.OutputFolder, "gcc");
string prefix = MakeItSoConfig.Instance.getProjectConfig(m_projectInfo.Name).CPPFolderPrefix;
return Utils.addPrefixToFolderPath(configuration.OutputFolder, prefix);
}

#endregion
Expand Down
51 changes: 51 additions & 0 deletions MakeItSoLib/MakeItSoConfig_Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ public bool ConvertStaticLibraryToSharedObjects
get { return m_convertStaticLibraryToSharedObjects; }
}

/// <summary>
/// Gets the prefix to use for output folders for C++ projects.
/// </summary>
public string CPPFolderPrefix
{
get { return m_cppFolderPrefix; }
}

/// <summary>
/// Gets the prefix to use for output folders for C# projects.
/// </summary>
public string CSharpFolderPrefix
{
get { return m_csharpFolderPrefix; }
}

/// <summary>
/// Parses the config file to read config for this project.
/// </summary>
Expand All @@ -150,13 +166,42 @@ public void parseConfig(XmlNode configNode)
parseConfig_PreprocessorDefinitions(configNode);
parseConfig_CompilerFlags(configNode);
parseConfig_Compilers(configNode);
parseConfig_FolderPrefixes(configNode);
parseConfig_Misc(configNode);
}

#endregion

#region Private functions

/// <summary>
/// Parses the prefixes to use for
/// </summary>
private void parseConfig_FolderPrefixes(XmlNode configNode)
{
// C++ folder prefix...
XmlNode cppPrefixNode = configNode.SelectSingleNode("CPPFolderPrefix");
if (cppPrefixNode != null)
{
XmlAttribute prefixAttribute = cppPrefixNode.Attributes["prefix"];
if (prefixAttribute != null)
{
m_cppFolderPrefix = prefixAttribute.Value;
}
}

// C# folder prefix...
XmlNode csharpPrefixNode = configNode.SelectSingleNode("CSharpFolderPrefix");
if (csharpPrefixNode != null)
{
XmlAttribute prefixAttribute = csharpPrefixNode.Attributes["prefix"];
if (prefixAttribute != null)
{
m_csharpFolderPrefix = prefixAttribute.Value;
}
}
}

/// <summary>
/// Parses the config for miscellaneous settings.
/// </summary>
Expand Down Expand Up @@ -410,6 +455,12 @@ private void addIncludePathToRemove(string includePath)
// for this project...
private bool m_convertStaticLibraryToSharedObjects = false;

// The prefix we add to output folders for C++ projects...
private string m_cppFolderPrefix = "gcc";

// The prefix we add to output folders for C# projects...
private string m_csharpFolderPrefix = "mono";

#endregion
}
}
6 changes: 3 additions & 3 deletions MakeItSoLib/ProjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public enum ProjectTypeEnum
#region Abstract methods

/// <summary>
/// Returns true if the (absolute) folder passed in is an output
/// folder for any of the configurations in this project.
/// Returns the type of executable, if the executable passed in
/// is an output of the project.
/// </summary>
public abstract bool isOutputFolder(string absoluteFolderPath);
public abstract ProjectInfo.ProjectTypeEnum isOutputObject(string absoluteExecutablePath);

#endregion

Expand Down
23 changes: 16 additions & 7 deletions MakeItSoLib/ProjectInfo_CPP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void setupImplicitLinking()
ProjectConfigurationInfo_CPP configuration = getConfigurationInfos().Find((cfg) => (cfg.Name == info.ConfigurationName));

// We add the collection of object files to the configuration...
string intermediateFolderAbsolute = Utils.addPrefixToFolderPath(info.IntermediateFolderAbsolute, "gcc");
string prefix = MakeItSoConfig.Instance.getProjectConfig(Name).CPPFolderPrefix;
string intermediateFolderAbsolute = Utils.addPrefixToFolderPath(info.IntermediateFolderAbsolute, prefix);
foreach (string objectFile in info.ObjectFileNames)
{
string absolutePath = intermediateFolderAbsolute + "/" + objectFile;
Expand Down Expand Up @@ -180,19 +181,27 @@ public void addCustomBuildRuleInfo(CustomBuildRuleInfo_CPP ruleInfo, string conf
}

/// <summary>
/// Returns true if the (absolute) folder passed in is an output
/// folder for any of the configurations in this project.
/// Returns the type of executable, if the executable passed in
/// is an output of the project.
/// </summary>
public override bool isOutputFolder(string absoluteFolderPath)
public override ProjectInfo.ProjectTypeEnum isOutputObject(string absoluteExecutablePath)
{
// We are only interested in executable projects...
if(m_projectType != ProjectTypeEnum.CPP_EXECUTABLE)
{
return ProjectTypeEnum.INVALID;
}

// We check each configuration...
foreach (ProjectConfigurationInfo_CPP configurationInfo in m_configurationInfos)
{
if (Utils.isSamePath(configurationInfo.OutputFolderAbsolute, absoluteFolderPath) == true)
string configurationOutput = String.Format("{0}/{1}.exe", configurationInfo.OutputFolder, Name);
if (Utils.isSamePath(configurationOutput, absoluteExecutablePath) == true)
{
return true;
return ProjectTypeEnum.CPP_EXECUTABLE;
}
}
return false;
return ProjectTypeEnum.INVALID;
}

#endregion
Expand Down
20 changes: 14 additions & 6 deletions MakeItSoLib/ProjectInfo_CSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,27 @@ public void addFileToCopyToOutputFolder(FileInfo fileInfo)
}

/// <summary>
/// Returns true if the (absolute) folder passed in is an output
/// folder for any of the configurations in this project.
/// Returns the type of executable, if the executable passed in
/// is an output of the project.
/// </summary>
public override bool isOutputFolder(string absoluteFolderPath)
public override ProjectInfo.ProjectTypeEnum isOutputObject(string absoluteExecutablePath)
{
// We are only interested in executable projects...
if (m_projectType != ProjectTypeEnum.CSHARP_EXECUTABLE)
{
return ProjectTypeEnum.INVALID;
}

// We check each configuration...
foreach (ProjectConfigurationInfo_CSharp configurationInfo in m_configurationInfos)
{
if (Utils.isSamePath(configurationInfo.OutputFolderAbsolute, absoluteFolderPath) == true)
string configurationOutput = String.Format("{0}/{1}.exe", configurationInfo.OutputFolder, Name);
if (Utils.isSamePath(configurationOutput, absoluteExecutablePath) == true)
{
return true;
return ProjectTypeEnum.CSHARP_EXECUTABLE;
}
}
return false;
return ProjectTypeEnum.INVALID;
}

#endregion
Expand Down
14 changes: 8 additions & 6 deletions MakeItSoLib/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,21 @@ public void setupReferences()
}

/// <summary>
/// Returns true if the (absolute) folder passed in is an output
/// folder for any of the projects in the solution.
/// Checks if the (absolute path to) the executable passed in is an
/// output object for any of the projects in the solution.
/// Returns the type of executable if it is, or INVALID if it is not.
/// </summary>
public bool isOutputFolder(string absoluteFolderPath)
public ProjectInfo.ProjectTypeEnum isOutputObject(string absoluteExecutablePath)
{
foreach (ProjectInfo projectInfo in m_projectInfos.Values)
{
if (projectInfo.isOutputFolder(absoluteFolderPath) == true)
ProjectInfo.ProjectTypeEnum result = projectInfo.isOutputObject(absoluteExecutablePath);
if (result != ProjectInfo.ProjectTypeEnum.INVALID)
{
return true;
return result;
}
}
return false;
return ProjectInfo.ProjectTypeEnum.INVALID;
}

#endregion
Expand Down
6 changes: 4 additions & 2 deletions MakeItSoLib/SolutionParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ private void updateLibraryPaths(ProjectConfigurationInfo_CPP configuration)
{
MakeItSoConfig_Project projectSettings = MakeItSoConfig.Instance.getProjectConfig(configuration.ParentProjectInfo.Name);

string projectRootFolder = configuration.ParentProjectInfo.RootFolderAbsolute;
ProjectInfo projectInfo = configuration.ParentProjectInfo;
string projectRootFolder = projectInfo.RootFolderAbsolute;

// We check if any library paths should be removed...
List<string> libraryPaths = new List<string>(configuration.getLibraryPaths());
Expand All @@ -146,7 +147,8 @@ private void updateLibraryPaths(ProjectConfigurationInfo_CPP configuration)
string fullPath = Path.Combine(projectRootFolder, libraryPath);
if (projectSettings.libraryPathShouldBeRemoved(fullPath) == false)
{
string gccPath = Utils.addPrefixToFolderPath(libraryPath, "gcc");
string prefix = MakeItSoConfig.Instance.getProjectConfig(projectInfo.Name).CPPFolderPrefix;
string gccPath = Utils.addPrefixToFolderPath(libraryPath, prefix);
configuration.addLibraryPath(gccPath);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<MakeItSo>

<!-- Settings that apply to all projects in the solution -->
<AllProjects>
<CPPFolderPrefix prefix="cppPrefix" />
</AllProjects>

</MakeItSo>
Loading

0 comments on commit f7209ce

Please sign in to comment.