Teach Xcode generator to set XCODE_VERSION

We set the variable 'XCODE_VERSION' in the CMake language to the Xcode
version string (e.g. "3.1.2").  Platform config files may use it later.
This commit is contained in:
Brad King 2009-09-23 08:48:39 -04:00
parent b7142e9214
commit e55bbab88b
4 changed files with 27 additions and 10 deletions

View File

@ -784,6 +784,13 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
"Set to true when the target system is Windows and on cygwin.",false, "Set to true when the target system is Windows and on cygwin.",false,
"Variables That Describe the System"); "Variables That Describe the System");
cm->DefineProperty
("XCODE_VERSION", cmProperty::VARIABLE,
"Version of Xcode (Xcode generator only).",
"Under the Xcode generator, this is the version of Xcode as specified in "
"\"Xcode.app/Contents/version.plist\" (such as \"3.1.2\").",false,
"Variables That Describe the System");
cm->DefineProperty cm->DefineProperty
("CMAKE_HOST_APPLE", cmProperty::VARIABLE, ("CMAKE_HOST_APPLE", cmProperty::VARIABLE,
"True for Apple OSXoperating systems.", "True for Apple OSXoperating systems.",

View File

@ -35,6 +35,7 @@ PURPOSE. See the above copyright notices for more information.
class cmXcodeVersionParser : public cmXMLParser class cmXcodeVersionParser : public cmXMLParser
{ {
public: public:
cmXcodeVersionParser(): Version("1.5") {}
void StartElement(const char* , const char** ) void StartElement(const char* , const char** )
{ {
this->Data = ""; this->Data = "";
@ -49,7 +50,7 @@ public:
{ {
if(this->Key == "CFBundleShortVersionString") if(this->Key == "CFBundleShortVersionString")
{ {
this->Version = (int)(10.0 * atof(this->Data.c_str())); this->Version = this->Data;
} }
} }
} }
@ -57,7 +58,7 @@ public:
{ {
this->Data.append(data, length); this->Data.append(data, length);
} }
int Version; std::string Version;
std::string Key; std::string Key;
std::string Data; std::string Data;
}; };
@ -115,8 +116,15 @@ public:
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator() cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(std::string const& version)
{ {
this->VersionString = version;
// Compute an integer form of the version number.
unsigned int v[2] = {0,0};
sscanf(this->VersionString.c_str(), "%u.%u", &v[0], &v[1]);
this->XcodeVersion = 10*v[0] + v[1];
this->FindMakeProgramFile = "CMakeFindXCode.cmake"; this->FindMakeProgramFile = "CMakeFindXCode.cmake";
this->RootObject = 0; this->RootObject = 0;
this->MainGroupChildren = 0; this->MainGroupChildren = 0;
@ -124,7 +132,6 @@ cmGlobalXCodeGenerator::cmGlobalXCodeGenerator()
this->ResourcesGroupChildren = 0; this->ResourcesGroupChildren = 0;
this->CurrentMakefile = 0; this->CurrentMakefile = 0;
this->CurrentLocalGenerator = 0; this->CurrentLocalGenerator = 0;
this->XcodeVersion = 15;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -134,13 +141,14 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::New()
cmXcodeVersionParser parser; cmXcodeVersionParser parser;
parser.ParseFile parser.ParseFile
("/Developer/Applications/Xcode.app/Contents/version.plist"); ("/Developer/Applications/Xcode.app/Contents/version.plist");
cmsys::auto_ptr<cmGlobalXCodeGenerator> gg(new cmGlobalXCodeGenerator); cmsys::auto_ptr<cmGlobalXCodeGenerator>
if (parser.Version == 20) gg(new cmGlobalXCodeGenerator(parser.Version));
if (gg->XcodeVersion == 20)
{ {
cmSystemTools::Message("Xcode 2.0 not really supported by cmake, " cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "
"using Xcode 15 generator\n"); "using Xcode 15 generator\n");
gg->XcodeVersion = 15;
} }
gg->SetVersion(parser.Version);
return gg.release(); return gg.release();
#else #else
std::cerr << "CMake should be built with cmake to use XCode, " std::cerr << "CMake should be built with cmake to use XCode, "
@ -155,6 +163,7 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vector<std::string>const&
cmMakefile * mf, bool optional) cmMakefile * mf, bool optional)
{ {
mf->AddDefinition("XCODE","1"); mf->AddDefinition("XCODE","1");
mf->AddDefinition("XCODE_VERSION", this->VersionString.c_str());
if(this->XcodeVersion == 15) if(this->XcodeVersion == 15)
{ {
} }

View File

@ -33,10 +33,9 @@ class cmSourceGroup;
class cmGlobalXCodeGenerator : public cmGlobalGenerator class cmGlobalXCodeGenerator : public cmGlobalGenerator
{ {
public: public:
cmGlobalXCodeGenerator(); cmGlobalXCodeGenerator(std::string const& version);
static cmGlobalGenerator* New(); static cmGlobalGenerator* New();
void SetVersion(int v) { this->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();}
@ -193,7 +192,8 @@ protected:
virtual const char* GetInstallTargetName() { return "install"; } virtual const char* GetInstallTargetName() { return "install"; }
virtual const char* GetPackageTargetName() { return "package"; } virtual const char* GetPackageTargetName() { return "package"; }
int XcodeVersion; unsigned int XcodeVersion;
std::string VersionString;
std::vector<cmXCodeObject*> XCodeObjects; std::vector<cmXCodeObject*> XCodeObjects;
cmXCodeObject* RootObject; cmXCodeObject* RootObject;
private: private:

View File

@ -93,3 +93,4 @@ CMAKE_C_IMPLICIT_LINK_DIRECTORIES == "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}"
CMAKE_CXX_IMPLICIT_LINK_LIBRARIES == "${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}" CMAKE_CXX_IMPLICIT_LINK_LIBRARIES == "${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}"
CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES == "${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES == "${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
XCODE_VERSION == "${XCODE_VERSION}"