From c294a115f2a44b60eb6343324e15933ef8a4593d Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Fri, 19 Dec 2014 12:31:22 -0700 Subject: [PATCH] Mach-O: Use Mach-O parser to extract install names instead of otool. This has much better performance than calling "otool" or "xcrun -r otool" to extract install names for rpath support. Fixes bug #15178. --- Source/cmSystemTools.cxx | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index c83dc2a8f..1c8c38788 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -63,6 +63,10 @@ # include "cmELF.h" #endif +#if defined(CMAKE_USE_MACH_PARSER) +# include "cmMachO.h" +#endif + class cmSystemToolsFileTime { public: @@ -2357,31 +2361,17 @@ bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath, bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath, std::string& soname) { - std::vector cmds; - cmds.push_back("otool"); - cmds.push_back("-D"); - cmds.push_back(fullPath); - - std::string output; - if(!RunSingleCommand(cmds, &output, 0, 0, OUTPUT_NONE)) +#if defined(CMAKE_USE_MACH_PARSER) + cmMachO macho(fullPath.c_str()); + if(macho) { - cmds.insert(cmds.begin(), "-r"); - cmds.insert(cmds.begin(), "xcrun"); - if(!RunSingleCommand(cmds, &output, 0, 0, OUTPUT_NONE)) - { - return false; - } + return macho.GetInstallName(soname); } +#else + (void)fullPath; + (void)soname; +#endif - std::vector strs = cmSystemTools::tokenize(output, "\n"); - // otool returns extra lines reporting multiple install names - // in case the binary is multi-arch and none of the architectures - // is native (e.g. i386;ppc on x86_64) - if(strs.size() >= 2) - { - soname = strs[1]; - return true; - } return false; }