allow flags to be in the CC and CXX environment variables

This commit is contained in:
Bill Hoffman 2002-11-19 18:17:17 -05:00
parent 939035ad91
commit 5a75e03037
7 changed files with 101 additions and 17 deletions

View File

@ -8,12 +8,11 @@
IF(NOT CMAKE_C_COMPILER) IF(NOT CMAKE_C_COMPILER)
# if the user has specified CC via the environment, then use that without checking # if the user has specified CC via the environment, then use that without checking
IF($ENV{CC} MATCHES ".+") IF($ENV{CC} MATCHES ".+")
SET(CMAKE_C_COMPILER_INIT $ENV{CC}) GET_FILENAME_COMPONENT(CMAKE_C_COMPILER_INIT $ENV{CC} PROGRAM PROGRAM_ARGS CMAKE_C_FLAGS_ENV_INIT)
# make sure we can find it IF(EXISTS ${CMAKE_C_COMPILER_INIT})
FIND_PROGRAM(CMAKE_C_COMPILER_FULLPATH NAMES $ENV{CC}) ELSE(EXISTS ${CMAKE_C_COMPILER_INIT})
IF(NOT CMAKE_C_COMPILER_FULLPATH) MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.")
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(EXISTS ${CMAKE_C_COMPILER_INIT})
ENDIF(NOT CMAKE_C_COMPILER_FULLPATH)
ELSE($ENV{CC} MATCHES ".+") ELSE($ENV{CC} MATCHES ".+")
# if not in the envionment then search for the compiler in the path # 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 ) SET(CMAKE_C_COMPILER_LIST ${CMAKE_GENERATOR_CC} gcc cc cl bcc )

View File

@ -8,12 +8,11 @@
IF(NOT CMAKE_CXX_COMPILER) IF(NOT CMAKE_CXX_COMPILER)
# if the user has specified CC via the environment, then use that without checking # if the user has specified CC via the environment, then use that without checking
IF($ENV{CXX} MATCHES ".+") IF($ENV{CXX} MATCHES ".+")
SET(CMAKE_CXX_COMPILER_INIT $ENV{CXX}) GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT)
# make sure we can find it IF(EXISTS ${CMAKE_CXX_COMPILER_INIT})
FIND_PROGRAM(CMAKE_CXX_COMPILER_FULLPATH NAMES $ENV{CXX}) ELSE(EXISTS ${CMAKE_CXX_COMPILER_INIT})
IF(NOT CMAKE_CXX_COMPILER_FULLPATH) MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.")
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(EXISTS ${CMAKE_CXX_COMPILER_INIT})
ENDIF(NOT CMAKE_CXX_COMPILER_FULLPATH)
ELSE($ENV{CXX} MATCHES ".+") ELSE($ENV{CXX} MATCHES ".+")
# if not in the envionment then search for the compiler in the path # 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 ) SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_GENERATOR_CXX} c++ g++ CC aCC cl bcc )

View File

@ -158,7 +158,7 @@ SET (CMAKE_INSTALL_PREFIX /usr/local CACHE PATH
# on the initial values computed in the platform/*.cmake files # on the initial values computed in the platform/*.cmake files
# use _INIT variables so that this only happens the first time # use _INIT variables so that this only happens the first time
# and you can set these flags in the cmake cache # 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.") "Flags used by the compiler during all build types.")
SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING SET (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING
"Flags used by the compiler during debug builds.") "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).") "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 SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
"Flags used by the compiler during Release with Debug Info builds.") "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.") "Flags for C compiler.")
SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
"Flags used by the compiler during debug builds.") "Flags used by the compiler during debug builds.")

View File

@ -39,7 +39,8 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
std::string result; std::string result;
std::string filename = args[1]; std::string filename = args[1];
std::string storeArgs;
std::string programArgs;
if (args[2] == "PATH") if (args[2] == "PATH")
{ {
result = cmSystemTools::GetFilenamePath(filename); result = cmSystemTools::GetFilenamePath(filename);
@ -48,6 +49,21 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
{ {
result = cmSystemTools::GetFilenameName(filename); 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") else if (args[2] == "EXT")
{ {
result = cmSystemTools::GetFilenameExtension(filename); result = cmSystemTools::GetFilenameExtension(filename);
@ -65,6 +81,14 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
if(args.size() == 4 && args[3] == "CACHE") 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(), m_Makefile->AddCacheDefinition(args[0].c_str(),
result.c_str(), result.c_str(),
"", "",
@ -73,6 +97,10 @@ bool cmGetFilenameComponentCommand::InitialPass(std::vector<std::string> const&
} }
else 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()); m_Makefile->AddDefinition(args[0].c_str(), result.c_str());
} }

View File

@ -67,14 +67,18 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return 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 " "Set VarName to be the path (PATH), file name (NAME), file "
"extension (EXT) or file name without extension (NAME_WE) of FileName.\n" "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 " "Note that the path is converted to Unix slashes format and has no "
"trailing slashes. The longest file extension is always considered.\n" "trailing slashes. The longest file extension is always considered.\n"
"Warning: as a utility command, the resulting value is not put in the " "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 " "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); cmTypeMacro(cmGetFilenameComponentCommand, cmCommand);

View File

@ -2423,3 +2423,52 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
#endif // __APPLE__ #endif // __APPLE__
return cmSystemTools::UNKNOWN_FILE_FORMAT; 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 = "";
}

View File

@ -267,9 +267,14 @@ public:
///! return path of a full filename (no trailing slashes). ///! return path of a full filename (no trailing slashes).
static std::string GetFilenamePath(const std::string&); static std::string GetFilenamePath(const std::string&);
///! return file name of a full filename (i.e. file name without path). ///! return file name of a full filename (i.e. file name without path).
static std::string GetFilenameName(const std::string&); 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). ///! return file extension of a full filename (dot included).
static std::string GetFilenameExtension(const std::string&); static std::string GetFilenameExtension(const std::string&);