diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2002-11-19 23:17:17 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2002-11-19 23:17:17 (GMT) |
commit | 5a75e03037b946abe56563fa1b568496f309ef5d (patch) | |
tree | 23f08815b01fea1e7216fac52a293ed347f73ad2 /Source | |
parent | 939035ad91aff5de5a1b514176cd2765a1b9a728 (diff) | |
download | CMake-5a75e03037b946abe56563fa1b568496f309ef5d.zip CMake-5a75e03037b946abe56563fa1b568496f309ef5d.tar.gz CMake-5a75e03037b946abe56563fa1b568496f309ef5d.tar.bz2 |
allow flags to be in the CC and CXX environment variables
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGetFilenameComponentCommand.cxx | 30 | ||||
-rw-r--r-- | Source/cmGetFilenameComponentCommand.h | 8 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 49 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 5 |
4 files changed, 89 insertions, 3 deletions
diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx index 55bd6a4..f277627 100644 --- a/Source/cmGetFilenameComponentCommand.cxx +++ b/Source/cmGetFilenameComponentCommand.cxx @@ -39,7 +39,8 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const& std::string result; std::string filename = args[1]; - + std::string storeArgs; + std::string programArgs; if (args[2] == "PATH") { result = cmSystemTools::GetFilenamePath(filename); @@ -48,6 +49,21 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const& { result = cmSystemTools::GetFilenameName(filename); } + else if (args[2] == "PROGRAM") + { + for(int i=2; i < args.size(); ++i) + { + if(args[i] == "PROGRAM_ARGS") + { + i++; + if(i < args.size()) + { + storeArgs = args[i]; + } + } + } + cmSystemTools::SplitProgramFromArgs(filename.c_str(), result, programArgs); + } else if (args[2] == "EXT") { result = cmSystemTools::GetFilenameExtension(filename); @@ -65,6 +81,14 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const& if(args.size() == 4 && args[3] == "CACHE") { + if(programArgs.size() && storeArgs.size()) + { + m_Makefile->AddCacheDefinition(storeArgs.c_str(), + programArgs.c_str(), + "", + args[2] == "PATH" ? cmCacheManager::FILEPATH + : cmCacheManager::STRING); + } m_Makefile->AddCacheDefinition(args[0].c_str(), result.c_str(), "", @@ -73,6 +97,10 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const& } else { + if(programArgs.size() && storeArgs.size()) + { + m_Makefile->AddDefinition(storeArgs.c_str(), programArgs.c_str()); + } m_Makefile->AddDefinition(args[0].c_str(), result.c_str()); } diff --git a/Source/cmGetFilenameComponentCommand.h b/Source/cmGetFilenameComponentCommand.h index 0b62bdd..c9d45bd 100644 --- a/Source/cmGetFilenameComponentCommand.h +++ b/Source/cmGetFilenameComponentCommand.h @@ -67,14 +67,18 @@ public: virtual const char* GetFullDocumentation() { return - "GET_FILENAME_COMPONENT(VarName FileName PATH|NAME|EXT|NAME_WE [CACHE])\n" + "GET_FILENAME_COMPONENT(VarName FileName PATH|NAME|EXT|NAME_WE|PROGRAM [PROGRAM_ARGS ArgVarName] [CACHE])\n" "Set VarName to be the path (PATH), file name (NAME), file " "extension (EXT) or file name without extension (NAME_WE) of FileName.\n" "Note that the path is converted to Unix slashes format and has no " "trailing slashes. The longest file extension is always considered.\n" "Warning: as a utility command, the resulting value is not put in the " "cache but in the definition list, unless you add the optional CACHE " - "parameter."; + "parameter." + "For PROGRAM, the program in FileName will be found in the path or if it is " + "a full path. If PROGRAM_ARGS is present with PROGRAM, then the arguments " + "are split from the program. This is used to separate a program from its " + "arguments."; } cmTypeMacro(cmGetFilenameComponentCommand, cmCommand); diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b6d6375..3ea396c 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2423,3 +2423,52 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext) #endif // __APPLE__ return cmSystemTools::UNKNOWN_FILE_FORMAT; } + + +void cmSystemTools::SplitProgramFromArgs(const char* path, + std::string& program, std::string& args) +{ + if(cmSystemTools::FileExists(path)) + { + program = path; + args = ""; + return; + } + std::vector<std::string> e; + std::string findProg = cmSystemTools::FindProgram(path, e); + if(findProg.size()) + { + program = findProg; + args = ""; + return; + } + std::string dir = path; + std::string::size_type spacePos = dir.rfind(' '); + if(spacePos == std::string::npos) + { + program = ""; + args = ""; + return; + } + while(spacePos != std::string::npos) + { + std::string tryProg = dir.substr(0, spacePos); + if(cmSystemTools::FileExists(tryProg.c_str())) + { + program = tryProg; + args = dir.substr(spacePos, dir.size()-spacePos); + return; + } + findProg = cmSystemTools::FindProgram(tryProg.c_str(), e); + if(findProg.size()) + { + program = findProg; + args = dir.substr(spacePos, dir.size()-spacePos); + return; + } + spacePos = dir.rfind(' ', spacePos--); + } + program = ""; + args = ""; +} + diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 8d915ca..9234283 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -266,10 +266,15 @@ public: ///! return path of a full filename (no trailing slashes). static std::string GetFilenamePath(const std::string&); + ///! return file name of a full filename (i.e. file name without path). static std::string GetFilenameName(const std::string&); + ///! Split a program from its arguments and handle spaces in the paths. + static void SplitProgramFromArgs(const char* path, + std::string& program, std::string& args); + ///! return file extension of a full filename (dot included). static std::string GetFilenameExtension(const std::string&); |