ENH: fixes for Xcode 2.2

This commit is contained in:
Bill Hoffman 2005-11-18 14:12:09 -05:00
parent c0ee3a13a5
commit 47622dde01
2 changed files with 154 additions and 131 deletions

View File

@ -1,17 +1,17 @@
/*========================================================================= /*=========================================================================
Program: CMake - Cross-Platform Makefile Generator Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$ Module: $RCSfile$
Language: C++ Language: C++
Date: $Date$ Date: $Date$
Version: $Revision$ Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information. PURPOSE. See the above copyright notices for more information.
=========================================================================*/ =========================================================================*/
#include "cmGlobalXCodeGenerator.h" #include "cmGlobalXCodeGenerator.h"
@ -93,8 +93,9 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::New()
"using Xcode 15 generator\n"); "using Xcode 15 generator\n");
return new cmGlobalXCodeGenerator; return new cmGlobalXCodeGenerator;
} }
cmGlobalXCodeGenerator* ret = new cmGlobalXCode21Generator;
return new cmGlobalXCode21Generator; ret->SetVersion(parser.m_Version);
return ret;
#else #else
std::cerr std::cerr
<< "CMake should be built with cmake to use XCode, default to Xcode 1.5\n"; << "CMake should be built with cmake to use XCode, default to Xcode 1.5\n";
@ -116,12 +117,12 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
{ {
mf->AddDefinition("CMAKE_CFG_INTDIR","$(CONFIGURATION)"); mf->AddDefinition("CMAKE_CFG_INTDIR","$(CONFIGURATION)");
mf->AddCacheDefinition( mf->AddCacheDefinition(
"CMAKE_CONFIGURATION_TYPES", "CMAKE_CONFIGURATION_TYPES",
"Debug;Release;MinSizeRel;RelWithDebInfo", "Debug;Release;MinSizeRel;RelWithDebInfo",
"Semicolon separated list of supported configuration types, " "Semicolon separated list of supported configuration types, "
"only supports Debug, Release, MinSizeRel, and RelWithDebInfo, " "only supports Debug, Release, MinSizeRel, and RelWithDebInfo, "
"anything else will be ignored.", "anything else will be ignored.",
cmCacheManager::STRING); cmCacheManager::STRING);
} }
mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc"); mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc");
mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++");
@ -131,8 +132,8 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmGlobalXCodeGenerator::GenerateBuildCommand(const char* makeProgram, std::string cmGlobalXCodeGenerator::GenerateBuildCommand(const char* makeProgram,
const char *projectName, const char *targetName, const char* config, const char *projectName, const char *targetName, const char* config,
bool ignoreErrors) bool ignoreErrors)
{ {
// Config is not used yet // Config is not used yet
(void) config; (void) config;
@ -170,7 +171,7 @@ std::string cmGlobalXCodeGenerator::GenerateBuildCommand(const char* makeProgram
} }
else else
{ {
makeCommand += " build"; makeCommand += " build";
} }
makeCommand += " -target "; makeCommand += " -target ";
if (targetName && strlen(targetName)) if (targetName && strlen(targetName))
@ -517,9 +518,6 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg,
this->CreateString(sourcecode.c_str())); this->CreateString(sourcecode.c_str()));
std::string path = std::string path =
this->ConvertToRelativeForXCode(sf->GetFullPath().c_str()); this->ConvertToRelativeForXCode(sf->GetFullPath().c_str());
// std::string file =
// cmSystemTools::RelativePath(m_CurrentMakefile->GetHomeDirectory(),
// sf->GetFullPath().c_str());
std::string dir; std::string dir;
std::string file; std::string file;
cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(), cmSystemTools::SplitProgramPath(sf->GetFullPath().c_str(),
@ -686,7 +684,7 @@ cmGlobalXCodeGenerator::CreateBuildPhase(const char* name,
cmXCodeObject* buildPhase = cmXCodeObject* buildPhase =
this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase); this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
buildPhase->AddAttribute("buildActionMask", buildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647")); this->CreateString("2147483647"));
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
buildPhase->AddAttribute("files", buildFiles); buildPhase->AddAttribute("files", buildFiles);
buildPhase->AddAttribute("name", buildPhase->AddAttribute("name",
@ -961,7 +959,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
defFlags += "-D"; defFlags += "-D";
if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL")) if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
{ {
defFlags += custom_export_name; defFlags += custom_export_name;
} }
else else
{ {
@ -998,7 +996,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
cmSystemTools::ReplaceString(defFlags, "\"", "\\\""); cmSystemTools::ReplaceString(defFlags, "\"", "\\\"");
cmSystemTools::ReplaceString(flags, "\"", "\\\""); cmSystemTools::ReplaceString(flags, "\"", "\\\"");
cmSystemTools::ReplaceString(cflags, "\"", "\\\""); cmSystemTools::ReplaceString(cflags, "\"", "\\\"");
if(m_XcodeVersion == 21) if(m_XcodeVersion > 15)
{ {
defFlags += " -DCMAKE_INTDIR=\\\\\\\"$(CONFIGURATION)\\\\\\\" "; defFlags += " -DCMAKE_INTDIR=\\\\\\\"$(CONFIGURATION)\\\\\\\" ";
} }
@ -1007,119 +1005,140 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
switch(target.GetType()) switch(target.GetType())
{ {
case cmTarget::STATIC_LIBRARY: case cmTarget::STATIC_LIBRARY:
{
if(m_LibraryOutputPath.size())
{ {
if(m_LibraryOutputPath.size()) buildSettings->AddAttribute("SYMROOT",
{ this->CreateString
buildSettings->AddAttribute("SYMROOT", (m_LibraryOutputPath.c_str()));
this->CreateString
(m_LibraryOutputPath.c_str()));
}
productName += ".a";
std::string t = "lib";
t += productName;
productName = t;
productType = "com.apple.product-type.library.static";
fileType = "archive.ar";
buildSettings->AddAttribute("LIBRARY_STYLE",
this->CreateString("STATIC"));
break;
} }
productName += ".a";
std::string t = "lib";
t += productName;
productName = t;
productType = "com.apple.product-type.library.static";
fileType = "archive.ar";
buildSettings->AddAttribute("LIBRARY_STYLE",
this->CreateString("STATIC"));
break;
}
case cmTarget::MODULE_LIBRARY: case cmTarget::MODULE_LIBRARY:
{
if(m_LibraryOutputPath.size())
{ {
if(m_LibraryOutputPath.size()) buildSettings->AddAttribute("SYMROOT",
{ this->CreateString
buildSettings->AddAttribute("SYMROOT", (m_LibraryOutputPath.c_str()));
this->CreateString }
(m_LibraryOutputPath.c_str()));
}
buildSettings->AddAttribute("EXECUTABLE_PREFIX", buildSettings->AddAttribute("EXECUTABLE_PREFIX",
this->CreateString("lib")); this->CreateString("lib"));
buildSettings->AddAttribute("EXECUTABLE_EXTENSION", buildSettings->AddAttribute("EXECUTABLE_EXTENSION",
this->CreateString("so")); this->CreateString("so"));
buildSettings->AddAttribute("LIBRARY_STYLE", buildSettings->AddAttribute("LIBRARY_STYLE",
this->CreateString("BUNDLE")); this->CreateString("BUNDLE"));
productName += ".so"; productName += ".so";
std::string t = "lib"; std::string t = "lib";
t += productName; t += productName;
productName = t; productName = t;
if(m_XcodeVersion >= 22)
{
buildSettings->AddAttribute("MACH_O_TYPE",
this->CreateString("mh_bundle"));
buildSettings->AddAttribute("GCC_DYNAMIC_NO_PIC",
this->CreateString("NO"));
buildSettings->AddAttribute("GCC_SYMBOLS_PRIVATE_EXTERN",
this->CreateString("NO"));
buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
this->CreateString("NO"));
std::string outflag = "-o \\\"$(CONFIGURATION_BUILD_DIR)/";
outflag += productName;
outflag += "\\\"";
buildSettings->AddAttribute("OTHER_LDFLAGS",
this->CreateString(outflag.c_str()));
productType = "com.apple.product-type.tool";
fileType = "compiled.mach-o.executable";
}
else
{
buildSettings->AddAttribute("OTHER_LDFLAGS", buildSettings->AddAttribute("OTHER_LDFLAGS",
this->CreateString("-bundle")); this->CreateString("-bundle"));
productType = "com.apple.product-type.library.dynamic"; productType = "com.apple.product-type.library.dynamic";
fileType = "compiled.mach-o.dylib"; fileType = "compiled.mach-o.dylib";
break;
} }
break;
}
case cmTarget::SHARED_LIBRARY: case cmTarget::SHARED_LIBRARY:
{
if(m_LibraryOutputPath.size())
{ {
if(m_LibraryOutputPath.size()) buildSettings->AddAttribute("SYMROOT",
{ this->CreateString
buildSettings->AddAttribute("SYMROOT", (m_LibraryOutputPath.c_str()));
this->CreateString
(m_LibraryOutputPath.c_str()));
}
buildSettings->AddAttribute("LIBRARY_STYLE",
this->CreateString("DYNAMIC"));
productName += ".dylib";
std::string t = "lib";
t += productName;
productName = t;
buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
this->CreateString("1"));
buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
this->CreateString("1"));
buildSettings->AddAttribute("OTHER_LDFLAGS",
this->CreateString("-dynamiclib"));
productType = "com.apple.product-type.library.dynamic";
fileType = "compiled.mach-o.dylib";
break;
} }
buildSettings->AddAttribute("LIBRARY_STYLE",
this->CreateString("DYNAMIC"));
productName += ".dylib";
std::string t = "lib";
t += productName;
productName = t;
buildSettings->AddAttribute("DYLIB_COMPATIBILITY_VERSION",
this->CreateString("1"));
buildSettings->AddAttribute("DYLIB_CURRENT_VERSION",
this->CreateString("1"));
buildSettings->AddAttribute("OTHER_LDFLAGS",
this->CreateString("-dynamiclib"));
productType = "com.apple.product-type.library.dynamic";
fileType = "compiled.mach-o.dylib";
break;
}
case cmTarget::EXECUTABLE: case cmTarget::EXECUTABLE:
{
const char* outname = target.GetProperty("OUTPUT_NAME");
std::string name;
if(outname)
{ {
const char* outname = target.GetProperty("OUTPUT_NAME"); productName = outname;
std::string name; name = outname;
if(outname) }
{ else
productName = outname; {
name = outname; name = target.GetName();
} }
else std::string symRoot;
{ if(m_ExecutableOutputPath.size())
name = target.GetName(); {
} std::string path = m_ExecutableOutputPath;
std::string symRoot;
if(m_ExecutableOutputPath.size())
{
std::string path = m_ExecutableOutputPath;
if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
{
path += name;
path += ".app/Contents/MacOS/";
}
symRoot = path;
}
fileType = "compiled.mach-o.executable";
if(target.GetPropertyAsBool("MACOSX_BUNDLE")) if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
{ {
if(symRoot.size() == 0) path += name;
{ path += ".app/Contents/MacOS/";
symRoot = name;
symRoot += ".app/Contents/MacOS/";
}
productType = "com.apple.product-type.tool";
}
else
{
productType = "com.apple.product-type.tool";
}
if(symRoot.size())
{
buildSettings->AddAttribute("SYMROOT",
this->CreateString
(symRoot.c_str()));
} }
symRoot = path;
} }
break; fileType = "compiled.mach-o.executable";
if(target.GetPropertyAsBool("MACOSX_BUNDLE"))
{
if(symRoot.size() == 0)
{
symRoot = name;
symRoot += ".app/Contents/MacOS/";
}
productType = "com.apple.product-type.tool";
}
else
{
productType = "com.apple.product-type.tool";
}
if(symRoot.size())
{
buildSettings->AddAttribute("SYMROOT",
this->CreateString
(symRoot.c_str()));
}
}
break;
case cmTarget::UTILITY: case cmTarget::UTILITY:
break; break;
@ -1199,8 +1218,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
buildSettings->AddAttribute("OTHER_CFLAGS", buildSettings->AddAttribute("OTHER_CFLAGS",
this->CreateString(flags.c_str())); this->CreateString(flags.c_str()));
} }
buildSettings->AddAttribute("OTHER_LDFLAGS", if(!buildSettings->GetObject("OTHER_LDFLAGS"))
this->CreateString("")); {
buildSettings->AddAttribute("OTHER_LDFLAGS",
this->CreateString(""));
}
buildSettings->AddAttribute("OTHER_REZFLAGS", buildSettings->AddAttribute("OTHER_REZFLAGS",
this->CreateString("")); this->CreateString(""));
buildSettings->AddAttribute("SECTORDER_FLAGS", buildSettings->AddAttribute("SECTORDER_FLAGS",
@ -1234,7 +1256,7 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
cmXCodeObject* shellBuildPhase = cmXCodeObject* shellBuildPhase =
this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase); this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
shellBuildPhase->AddAttribute("buildActionMask", shellBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647")); this->CreateString("2147483647"));
cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST); cmXCodeObject* buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
shellBuildPhase->AddAttribute("files", buildFiles); shellBuildPhase->AddAttribute("files", buildFiles);
cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST); cmXCodeObject* inputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
@ -1242,12 +1264,12 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget)
cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST); cmXCodeObject* outputPaths = this->CreateObject(cmXCodeObject::OBJECT_LIST);
shellBuildPhase->AddAttribute("outputPaths", outputPaths); shellBuildPhase->AddAttribute("outputPaths", outputPaths);
shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing", shellBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
this->CreateString("0")); this->CreateString("0"));
shellBuildPhase->AddAttribute("shellPath", shellBuildPhase->AddAttribute("shellPath",
this->CreateString("/bin/sh")); this->CreateString("/bin/sh"));
shellBuildPhase->AddAttribute("shellScript", shellBuildPhase->AddAttribute("shellScript",
this->CreateString( this->CreateString(
"# shell script goes here\nexit 0")); "# shell script goes here\nexit 0"));
cmXCodeObject* target = cmXCodeObject* target =
this->CreateObject(cmXCodeObject::PBXAggregateTarget); this->CreateObject(cmXCodeObject::PBXAggregateTarget);
target->SetComment(cmtarget.GetName()); target->SetComment(cmtarget.GetName());
@ -1523,7 +1545,7 @@ std::string cmGlobalXCodeGenerator::GetTargetFullPath(cmTarget* target)
cmXCodeObject* xtarget = this->FindXCodeTarget(target); cmXCodeObject* xtarget = this->FindXCodeTarget(target);
cmXCodeObject* bset = xtarget->GetObject("buildSettings"); cmXCodeObject* bset = xtarget->GetObject("buildSettings");
cmXCodeObject* spath = bset->GetObject("SYMROOT"); cmXCodeObject* spath = bset->GetObject("SYMROOT");
if(m_XcodeVersion == 21) if(m_XcodeVersion > 15)
{ {
libPath += "$(CONFIGURATION)/"; libPath += "$(CONFIGURATION)/";
} }
@ -1601,7 +1623,7 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
{ {
if(libDir->size() && *libDir != "/usr/lib") if(libDir->size() && *libDir != "/usr/lib")
{ {
if(m_XcodeVersion == 21) if(m_XcodeVersion > 15)
{ {
// now add the same one but append $(CONFIGURATION) to it: // now add the same one but append $(CONFIGURATION) to it:
linkDirs += " "; linkDirs += " ";
@ -1880,7 +1902,7 @@ void cmGlobalXCodeGenerator::CreateXCodeObjects(cmLocalGenerator* root,
configRelease->AddAttribute("buildSettings", buildSettings); configRelease->AddAttribute("buildSettings", buildSettings);
m_RootObject->AddAttribute("buildConfigurationList", m_RootObject->AddAttribute("buildConfigurationList",
this->CreateObjectReference(configlist)); this->CreateObjectReference(configlist));
std::vector<cmXCodeObject*> targets; std::vector<cmXCodeObject*> targets;
for(std::vector<cmLocalGenerator*>::iterator i = generators.begin(); for(std::vector<cmLocalGenerator*>::iterator i = generators.begin();

View File

@ -35,7 +35,8 @@ class cmGlobalXCodeGenerator : public cmGlobalGenerator
public: public:
cmGlobalXCodeGenerator(); cmGlobalXCodeGenerator();
static cmGlobalGenerator* New(); static cmGlobalGenerator* New();
void SetVersion(int v) { m_XcodeVersion = v;}
///! Get the name for the generator. ///! Get the name for the generator.
virtual const char* GetName() const { virtual const char* GetName() const {
return cmGlobalXCodeGenerator::GetActualName();} return cmGlobalXCodeGenerator::GetActualName();}