Skip to content
Snippets Groups Projects
Commit 047a5e4d authored by Ben Boeckel's avatar Ben Boeckel Committed by Brad King
Browse files

cmWorkingDirectory: add class for changing the workdir

parent 89891bcb
No related branches found
No related tags found
No related merge requests found
......@@ -381,6 +381,8 @@ set(SRCS
cmVariableWatch.h
cmVersion.cxx
cmVersion.h
cmWorkingDirectory.cxx
cmWorkingDirectory.h
cmXMLParser.cxx
cmXMLParser.h
cmXMLSafe.cxx
......
/* 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();
}
}
/* 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
......@@ -404,6 +404,7 @@ CMAKE_CXX_SOURCES="\
cmUnsetCommand \
cmVersion \
cmWhileCommand \
cmWorkingDirectory \
cmake \
cmakemain \
cmcmd \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment