summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-05-19 13:44:19 (GMT)
committerBrad King <brad.king@kitware.com>2015-05-21 12:59:31 (GMT)
commit438ce4a0fb92b7288a46e17524418522468eb0a2 (patch)
tree0b6f2a33c9bfcb7a580d90859534035c2581c79d /Source
parent41477d5c0705baa33878c16e979283088efe2c4a (diff)
downloadCMake-438ce4a0fb92b7288a46e17524418522468eb0a2.zip
CMake-438ce4a0fb92b7288a46e17524418522468eb0a2.tar.gz
CMake-438ce4a0fb92b7288a46e17524418522468eb0a2.tar.bz2
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.
Diffstat (limited to 'Source')
-rw-r--r--Source/QtDialog/CMakeSetup.cxx67
1 files changed, 67 insertions, 0 deletions
diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx
index cf1729c..167f37c 100644
--- a/Source/QtDialog/CMakeSetup.cxx
+++ b/Source/QtDialog/CMakeSetup.cxx
@@ -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