ENH: Handle missing unsetenv and add check for environ
This commit is contained in:
parent
ca8d1bc99b
commit
b20cb78049
|
@ -23,6 +23,23 @@ INCLUDE_DIRECTORIES(
|
|||
|
||||
# let cmake know it is supposed to use it
|
||||
ADD_DEFINITIONS(-DCMAKE_BUILD_WITH_CMAKE)
|
||||
INCLUDE(CheckSymbolExists)
|
||||
CHECK_SYMBOL_EXISTS(unsetenv "stdlib.h" HAVE_UNSETENV)
|
||||
INCLUDE("${CMAKE_ROOT}/Modules/CheckCXXSourceCompiles.cmake")
|
||||
CHECK_CXX_SOURCE_COMPILES(
|
||||
"int main(int argc, char* argv[]) { return sizeof(environ); }"
|
||||
HAVE_ENVIRON_WITHOUT_SIGNATURE)
|
||||
IF(NOT HAVE_ENVIRON_WITHOUT_SIGNATURE)
|
||||
CHECK_CXX_SOURCE_COMPILES(
|
||||
"
|
||||
#ifdef _WIN32
|
||||
extern __declspec( dllimport ) char** environ;
|
||||
#else
|
||||
extern char** environ;
|
||||
#endif
|
||||
int main(int argc, char* argv[]) { return sizeof(environ); }"
|
||||
HAVE_ENVIRON_WITH_SIGNATURE)
|
||||
ENDIF(NOT HAVE_ENVIRON_WITHOUT_SIGNATURE)
|
||||
|
||||
OPTION(CMAKE_REGENERATE_YACCLEX
|
||||
"Regenerate YACC and LEXX files" OFF)
|
||||
|
|
|
@ -56,7 +56,14 @@
|
|||
# pragma set woff 1375 /* base class destructor not virtual */
|
||||
#endif
|
||||
|
||||
extern char** environ; // For GetEnvironmentVariables
|
||||
#if !defined(HAVE_ENVIRON_WITHOUT_SIGNATURE)
|
||||
// For GetEnvironmentVariables
|
||||
# if defined(_WIN32)
|
||||
extern __declspec( dllimport ) char** environ;
|
||||
# else
|
||||
extern char** environ;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
bool cmSystemTools::s_RunCommandHideConsole = false;
|
||||
bool cmSystemTools::s_DisableRunCommandOutput = false;
|
||||
|
@ -1280,9 +1287,17 @@ bool cmSystemTools::PutEnv(const char* value)
|
|||
return ret == 0;
|
||||
}
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
bool cmSystemTools::UnsetEnv(const char* value)
|
||||
{
|
||||
return false;
|
||||
#if !defined(HAVE_UNSETENV)
|
||||
std::string var = value;
|
||||
var += "=";
|
||||
return cmSystemTools::PutEnv(var.c_str());
|
||||
#else
|
||||
unsetenv(value);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
|
||||
|
@ -1295,6 +1310,7 @@ std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
|
|||
}
|
||||
return env;
|
||||
}
|
||||
#endif
|
||||
|
||||
void cmSystemTools::EnableVSConsoleOutput()
|
||||
{
|
||||
|
|
|
@ -295,11 +295,13 @@ public:
|
|||
of the form var=value */
|
||||
static bool PutEnv(const char* value);
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
/** Remove an environment variable */
|
||||
static bool UnsetEnv(const char* value);
|
||||
|
||||
/** Get the list of all environment variables */
|
||||
static std::vector<std::string> GetEnvironmentVariables();
|
||||
#endif
|
||||
|
||||
/** Setup the environment to enable VS 8 IDE output. */
|
||||
static void EnableVSConsoleOutput();
|
||||
|
|
|
@ -831,6 +831,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
// Command to create a symbolic link. Fails on platforms not
|
||||
// supporting them.
|
||||
else if (args[1] == "environment" )
|
||||
|
@ -843,6 +844,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Remove file
|
||||
else if (args[1] == "remove" && args.size() > 2)
|
||||
|
|
Loading…
Reference in New Issue