diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 998843f..19f9fd3 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -24,43 +24,6 @@ #include //---------------------------------------------------------------------------- -#if defined(CMAKE_BUILD_WITH_CMAKE) -#include "cmXMLParser.h" - -// parse the xml file storing the installed version of Xcode on -// the machine -class cmXcodeVersionParser : public cmXMLParser -{ -public: - cmXcodeVersionParser(): Version("1.5") {} - void StartElement(const char* , const char** ) - { - this->Data = ""; - } - void EndElement(const char* name) - { - if(strcmp(name, "key") == 0) - { - this->Key = this->Data; - } - else if(strcmp(name, "string") == 0) - { - if(this->Key == "CFBundleShortVersionString") - { - this->Version = this->Data; - } - } - } - void CharacterDataHandler(const char* data, int length) - { - this->Data.append(data, length); - } - std::string Version; - std::string Key; - std::string Data; -}; -#endif - // Builds either an object list or a space-separated string from the // given inputs. class cmGlobalXCodeGenerator::BuildObjectListOrString @@ -135,20 +98,34 @@ cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(std::string const& version) cmGlobalGenerator* cmGlobalXCodeGenerator::New() { #if defined(CMAKE_BUILD_WITH_CMAKE) - cmXcodeVersionParser parser; - if (cmSystemTools::FileExists( - "/Applications/Xcode.app/Contents/version.plist")) - { - parser.ParseFile - ("/Applications/Xcode.app/Contents/version.plist"); - } - else - { - parser.ParseFile - ("/Developer/Applications/Xcode.app/Contents/version.plist"); - } + std::string developerFolderPath; + if (!cmSystemTools::RunSingleCommand("/usr/bin/xcode-select -print-path", &developerFolderPath, NULL, NULL, cmSystemTools::OUTPUT_NONE)) { + cmSystemTools::Error("Unable to determine the path to the Developer folder (using xcode-select)."); + return NULL; + } + if (developerFolderPath[developerFolderPath.length() - 1] == '\n') { + developerFolderPath.erase(developerFolderPath.length() - 1, 1); + } + std::string xcodebuildPath = developerFolderPath + "/usr/bin/xcodebuild"; + std::string xcodebuildVersionString; + std::vector xcodebuildCommand; + xcodebuildCommand.push_back(xcodebuildPath); + xcodebuildCommand.push_back("-version"); + if (!cmSystemTools::RunSingleCommand(xcodebuildCommand, &xcodebuildVersionString, NULL, NULL, cmSystemTools::OUTPUT_NONE)) { + cmSystemTools::Error(("Unable to get the version of xcodebuild (" + xcodebuildPath + ").").c_str()); + return NULL; + } + size_t lineReturnPosition = xcodebuildVersionString.find_first_of("\n\r"); + if (std::string::npos == lineReturnPosition) { + lineReturnPosition = xcodebuildVersionString.length(); + } + size_t lastSpacePosition = xcodebuildVersionString.find_last_of(" \t", lineReturnPosition); + if (std::string::npos == lastSpacePosition) { + lastSpacePosition = 0; + } + std::string xcodebuildVersion = xcodebuildVersionString.substr(lastSpacePosition + 1, lineReturnPosition - lastSpacePosition - 1); cmsys::auto_ptr - gg(new cmGlobalXCodeGenerator(parser.Version)); + gg(new cmGlobalXCodeGenerator(xcodebuildVersion)); if (gg->XcodeVersion == 20) { cmSystemTools::Message("Xcode 2.0 not really supported by cmake, "