Xcode Generator: Custom Project Name
Hi there.
I'd like to bring a small feature: custom name for a Xcode project.
Here is my motivation: on my machine I have few copies of LLVM, for each of them I have separate Xcode project.
The problem appears when I switch between different Xcode projects, or when I want to open another project: there is almost no way to determine which copy I'm working with. The only way to differentiate things now is to remember the target I worked with in each project.
But it's so annoying, error-prone, and counter-productive so I'd like CMake to generate me a project with a different, custom name.
i.e.:
cmake -G Xcode ~/Projects/LLVM/src
cmake -G Xcode -DCMAKE_XCODE_PROJECT_NAME=Mull ~/Projects/Mull/src
cmake -G Xcode -DCMAKE_XCODE_PROJECT_NAME=IRTests ~/Projects/Mull/Lab/src
where the commands will spit out xcode projects as the following: LLVM.xcodeproj
, Mull.xcodeproj
, IRTests.xcodeproj
.
So far I looked into cmGlobalXCodeGenerator
and found that this change can be done easily (see the patch below).
Now I have several questions:
- Can such a feature be accepted into upstream?
- What is the recommended way to write tests for this feature?
- What else needs to be done to make this work besides the change below?
I will also appreciate any reference to more detailed contributing guidelines, if there are any.
P.S. the patch:
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 736aa91..4fea196 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -3264,9 +3264,16 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
if (!this->CreateXCodeObjects(root, generators)) {
return;
}
+
+ const char *customProjectName = this->CurrentMakefile->GetDefinition("CMAKE_XCODE_PROJECT_NAME");
+ std::string projectName = root->GetProjectName();
+ if (customProjectName) {
+ projectName = std::string(customProjectName);
+ }
+
std::string xcodeDir = root->GetCurrentBinaryDirectory();
xcodeDir += "/";
- xcodeDir += root->GetProjectName();
+ xcodeDir += projectName;
xcodeDir += ".xcode";
if (this->XcodeVersion > 20) {
xcodeDir += "proj";