diff options
-rw-r--r-- | Modules/CMakeDetermineCCompiler.cmake | 11 | ||||
-rw-r--r-- | Modules/CMakeDetermineCXXCompiler.cmake | 11 | ||||
-rw-r--r-- | Modules/CMakeSystemSpecificInformation.cmake | 4 | ||||
-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 |
7 files changed, 101 insertions, 17 deletions
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 5d48546..72a2a03 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -8,12 +8,11 @@ IF(NOT CMAKE_C_COMPILER) # if the user has specified CC via the environment, then use that without checking IF($ENV{CC} MATCHES ".+") - SET(CMAKE_C_COMPILER_INIT $ENV{CC}) - # make sure we can find it - FIND_PROGRAM(CMAKE_C_COMPILER_FULLPATH NAMES $ENV{CC}) - IF(NOT CMAKE_C_COMPILER_FULLPATH) - MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}, make sure CC does not have flags in it, use CFLAGS instead.") - ENDIF(NOT CMAKE_C_COMPILER_FULLPATH) + GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT) + IF(EXISTS ${CMAKE_C_COMPILER_INIT}) + ELSE(EXISTS ${CMAKE_C_COMPILER_INIT}) + MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.") + ENDIF(EXISTS ${CMAKE_C_COMPILER_INIT}) ELSE($ENV{CC} MATCHES ".+") # if not in the envionment then search for the compiler in the path SET(CMAKE_C_COMPILER_LIST ${CMAKE_GENERATOR_CC} gcc cc cl bcc ) diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 24ba288..101786a 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -8,12 +8,11 @@ IF(NOT CMAKE_CXX_COMPILER) # if the user has specified CC via the environment, then use that without checking IF($ENV{CXX} MATCHES ".+") - SET(CMAKE_CXX_COMPILER_INIT $ENV{CXX}) - # make sure we can find it - FIND_PROGRAM(CMAKE_CXX_COMPILER_FULLPATH NAMES $ENV{CXX}) - IF(NOT CMAKE_CXX_COMPILER_FULLPATH) - MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}, make sure CXX does not have flags in it, use CXXFLAGS instead.") - ENDIF(NOT CMAKE_CXX_COMPILER_FULLPATH) + GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT) + IF(EXISTS ${CMAKE_CXX_COMPILER_INIT}) + ELSE(EXISTS ${CMAKE_CXX_COMPILER_INIT}) + MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.") + ENDIF(EXISTS ${CMAKE_CXX_COMPILER_INIT}) ELSE($ENV{CXX} MATCHES ".+") # if not in the envionment then search for the compiler in the path SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_GENERATOR_CXX} c++ g++ CC aCC cl bcc ) diff --git a/Modules/CMakeSystemSpecificInformation.cmake b/Modules/CMakeSystemSpecificInformation.cmake index a6ef2e2..5b70da6 100644 --- a/Modules/CMakeSystemSpecificInformation.cmake +++ b/Modules/CMakeSystemSpecificInformation.cmake @@ -158,7 +158,7 @@ SET (CMAKE_INSTALL_PREFIX /usr/local CACHE PATH # on the initial values computed in the platform/*.cmake files # use _INIT variables so that this only happens the first time # and you can set these flags in the cmake cache -SET (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING +SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_ENV_INIT} $ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}" CACHE STRING "Flags used by the compiler during all build types.") SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING "Flags used by the compiler during debug builds.") @@ -168,7 +168,7 @@ SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).") SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING "Flags used by the compiler during Release with Debug Info builds.") -SET (CMAKE_C_FLAGS " $ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}" CACHE STRING +SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_ENV_INIT} $ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}" CACHE STRING "Flags for C compiler.") SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING "Flags used by the compiler during debug builds.") 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&); |