1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

cmWorkingDirectory: add class for changing the workdir

This commit is contained in:
Ben Boeckel
2017-03-01 13:40:22 -05:00
committed by Brad King
parent 89891bcb9e
commit 047a5e4d66
4 changed files with 52 additions and 0 deletions

View File

@@ -381,6 +381,8 @@ set(SRCS
cmVariableWatch.h
cmVersion.cxx
cmVersion.h
cmWorkingDirectory.cxx
cmWorkingDirectory.h
cmXMLParser.cxx
cmXMLParser.h
cmXMLSafe.cxx

View File

@@ -0,0 +1,24 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmWorkingDirectory.h"
#include "cmSystemTools.h"
cmWorkingDirectory::cmWorkingDirectory(std::string const& newdir)
{
this->OldDir = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(newdir);
}
cmWorkingDirectory::~cmWorkingDirectory()
{
this->Pop();
}
void cmWorkingDirectory::Pop()
{
if (!this->OldDir.empty()) {
cmSystemTools::ChangeDirectory(this->OldDir);
this->OldDir.clear();
}
}

View File

@@ -0,0 +1,25 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmWorkingDirectory_h
#define cmWorkingDirectory_h
#include <cmConfigure.h> // IWYU pragma: keep
#include <string>
/** \class cmWorkingDirectory
* \brief An RAII class to manipulate the working directory.
*/
class cmWorkingDirectory
{
public:
cmWorkingDirectory(std::string const& newdir);
~cmWorkingDirectory();
void Pop();
private:
std::string OldDir;
};
#endif

View File

@@ -404,6 +404,7 @@ CMAKE_CXX_SOURCES="\
cmUnsetCommand \
cmVersion \
cmWhileCommand \
cmWorkingDirectory \
cmake \
cmakemain \
cmcmd \