diff options
author | Gregor Jasny <gjasny@googlemail.com> | 2017-10-11 18:58:35 (GMT) |
---|---|---|
committer | Gregor Jasny <gjasny@googlemail.com> | 2017-10-13 19:28:34 (GMT) |
commit | 5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46 (patch) | |
tree | 310730d01dd0a79a268c2ce6982ab49fe8b3e171 /Source/cmakemain.cxx | |
parent | d0b6c2da8b7fda317e11c66a4b133d4a88eaeef6 (diff) | |
download | CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.zip CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.tar.gz CMake-5de37a4a6474fa569e2ac28d5e9c164b6e7d2f46.tar.bz2 |
cmake: Add --open option for IDE generators
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r-- | Source/cmakemain.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index a1dfc3e..59b908a 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -66,6 +66,7 @@ static const char* cmDocumentationOptions[][2] = { { "-E", "CMake command mode." }, { "-L[A][H]", "List non-advanced cached variables." }, { "--build <dir>", "Build a CMake-generated project binary tree." }, + { "--open <dir>", "Open generated project in the associated application." }, { "-N", "View mode only." }, { "-P <file>", "Process script mode." }, { "--find-package", "Run in pkg-config like mode." }, @@ -100,6 +101,7 @@ static int do_command(int ac, char const* const* av) int do_cmake(int ac, char const* const* av); static int do_build(int ac, char const* const* av); +static int do_open(int ac, char const* const* av); static cmMakefile* cmakemainGetMakefile(void* clientdata) { @@ -186,6 +188,9 @@ int main(int ac, char const* const* av) if (strcmp(av[1], "--build") == 0) { return do_build(ac, av); } + if (strcmp(av[1], "--open") == 0) { + return do_open(ac, av); + } if (strcmp(av[1], "-E") == 0) { return do_command(ac, av); } @@ -423,3 +428,41 @@ static int do_build(int ac, char const* const* av) return cm.Build(dir, target, config, nativeOptions, clean); #endif } + +static int do_open(int ac, char const* const* av) +{ +#ifndef CMAKE_BUILD_WITH_CMAKE + std::cerr << "This cmake does not support --open\n"; + return -1; +#else + std::string dir; + + enum Doing + { + DoingNone, + DoingDir, + }; + Doing doing = DoingDir; + for (int i = 2; i < ac; ++i) { + switch (doing) { + case DoingDir: + dir = cmSystemTools::CollapseFullPath(av[i]); + doing = DoingNone; + break; + default: + std::cerr << "Unknown argument " << av[i] << std::endl; + dir.clear(); + break; + } + } + if (dir.empty()) { + std::cerr << "Usage: cmake --open <dir>\n"; + return 1; + } + + cmake cm(cmake::RoleInternal); + cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm); + cm.SetProgressCallback(cmakemainProgressCallback, &cm); + return cm.Open(dir, false) ? 0 : 1; +#endif +} |