diff options
author | Brad King <brad.king@kitware.com> | 2014-06-24 17:05:05 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2014-06-24 17:05:05 (GMT) |
commit | 8766f8ef4732e8dc4b2b585adddfda38ad23ea43 (patch) | |
tree | d288cc5f800a786dec2d40273edc04dbc5c5d691 /Source | |
parent | f9cfbedef6adb24f67f8de32b48ea934386a5beb (diff) | |
parent | 7abd574798f9900abfe502f3941cffaa774062b1 (diff) | |
download | CMake-8766f8ef4732e8dc4b2b585adddfda38ad23ea43.zip CMake-8766f8ef4732e8dc4b2b585adddfda38ad23ea43.tar.gz CMake-8766f8ef4732e8dc4b2b585adddfda38ad23ea43.tar.bz2 |
Merge topic 'cmake-E-env'
7abd5747 cmake: Add '-E env' command-line tool
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmcmd.cxx | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 9aee975..a0c67e0 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -61,6 +61,8 @@ void CMakeCommandUsage(const char* program) << " echo [string]... - displays arguments as text\n" << " echo_append [string]... - displays arguments as text but no new " "line\n" + << " env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...\n" + << " - run command in a modified environment\n" << " environment - display the current environment\n" << " make_directory dir - create a directory\n" << " md5sum file1 [...] - compute md5sum of files\n" @@ -190,6 +192,55 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args) return 0; } + else if (args[1] == "env" ) + { + std::vector<std::string>::const_iterator ai = args.begin() + 2; + std::vector<std::string>::const_iterator ae = args.end(); + for(; ai != ae; ++ai) + { + std::string const& a = *ai; + if(cmHasLiteralPrefix(a, "--unset=")) + { + // Unset environment variable. + cmSystemTools::UnPutEnv(a.c_str() + 8); + } + else if(!a.empty() && a[0] == '-') + { + // Environment variable and command names cannot start in '-', + // so this must be an unknown option. + std::cerr << "cmake -E env: unknown option '" << a << "'" + << std::endl; + return 1; + } + else if(a.find("=") != a.npos) + { + // Set environment variable. + cmSystemTools::PutEnv(a.c_str()); + } + else + { + // This is the beginning of the command. + break; + } + } + + if(ai == ae) + { + std::cerr << "cmake -E env: no command given" << std::endl; + return 1; + } + + // Execute command from remaining arguments. + std::vector<std::string> cmd(ai, ae); + int retval; + if(cmSystemTools::RunSingleCommand( + cmd, 0, &retval, NULL, cmSystemTools::OUTPUT_PASSTHROUGH)) + { + return retval; + } + return 1; + } + #if defined(CMAKE_BUILD_WITH_CMAKE) // Command to create a symbolic link. Fails on platforms not // supporting them. |