Commit 438ce4a0 authored by Brad King's avatar Brad King
Browse files

cmake-gui: Add --install option to add command-line tools on OS X

On OS X add an "--install[=/path/to/bin]" option (defaulting to
/usr/bin) that installs symbolic links into the given directory.
This will help OS X users make the tools available on the command
line even when they sit inside a CMake.app bundle.
parent 41477d5c
......@@ -20,6 +20,7 @@
#include "cmDocumentation.h"
#include "cmake.h"
#include "cmVersion.h"
#include "cmAlgorithms.h"
#include <cmsys/CommandLineArguments.hxx>
#include <cmsys/SystemTools.hxx>
#include <cmsys/Encoding.hxx>
......@@ -48,6 +49,10 @@ static const char * cmDocumentationOptions[][2] =
{0,0}
};
#if defined(Q_OS_MAC)
static int cmOSXInstall(std::string dir);
#endif
int main(int argc, char** argv)
{
cmsys::Encoding::CommandLineArguments encoding_args =
......@@ -77,6 +82,17 @@ int main(int argc, char** argv)
return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
}
#if defined(Q_OS_MAC)
if (argc2 == 2 && strcmp(argv2[1], "--install") == 0)
{
return cmOSXInstall("/usr/bin");
}
if (argc2 == 2 && cmHasLiteralPrefix(argv2[1], "--install="))
{
return cmOSXInstall(argv2[1]+10);
}
#endif
QApplication app(argc, argv);
#if defined(CMAKE_ENCODING_UTF8)
......@@ -177,3 +193,54 @@ int main(int argc, char** argv)
return app.exec();
}
#if defined(Q_OS_MAC)
# include <errno.h>
# include <string.h>
# include <sys/stat.h>
# include <unistd.h>
static bool cmOSXInstall(std::string const& dir, std::string const& tool)
{
if (tool.empty())
{
return true;
}
std::string link = dir + cmSystemTools::GetFilenameName(tool);
struct stat st;
if (lstat(link.c_str(), &st) == 0 && S_ISLNK(st.st_mode))
{
char buf[4096];
ssize_t s = readlink(link.c_str(), buf, sizeof(buf)-1);
if (s >= 0 && std::string(buf, s) == tool)
{
std::cerr << "Exists: '" << link << "' -> '" << tool << "'\n";
return true;
}
}
if (symlink(tool.c_str(), link.c_str()) == 0)
{
std::cerr << "Linked: '" << link << "' -> '" << tool << "'\n";
return true;
}
else
{
int err = errno;
std::cerr << "Failed: '" << link << "' -> '" << tool << "': "
<< strerror(err) << "\n";
return false;
}
}
static int cmOSXInstall(std::string dir)
{
if (!cmHasLiteralSuffix(dir, "/"))
{
dir += "/";
}
return (
cmOSXInstall(dir, cmSystemTools::GetCMakeCommand()) &&
cmOSXInstall(dir, cmSystemTools::GetCTestCommand()) &&
cmOSXInstall(dir, cmSystemTools::GetCPackCommand()) &&
cmOSXInstall(dir, cmSystemTools::GetCMakeGUICommand()) &&
cmOSXInstall(dir, cmSystemTools::GetCMakeCursesCommand())
) ? 0 : 1;
}
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment