summaryrefslogtreecommitdiff
path: root/Source/cmXCOFF.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-01-29 13:25:51 -0500
committerBrad King <brad.king@kitware.com>2021-02-03 12:26:58 -0500
commit56fc4a325f08465b725b08b3975cd51bdd2305c8 (patch)
treee92abaf4dd695b618db00ef568225a97a407f077 /Source/cmXCOFF.h
parentddaaee907dc617f6a763de37c368e50cd23a8a53 (diff)
downloadcmake-56fc4a325f08465b725b08b3975cd51bdd2305c8.tar.gz
cmXCOFF: Add helper to parse and edit the XCOFF binary format
Diffstat (limited to 'Source/cmXCOFF.h')
-rw-r--r--Source/cmXCOFF.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/Source/cmXCOFF.h b/Source/cmXCOFF.h
new file mode 100644
index 0000000000..16cda9daf0
--- /dev/null
+++ b/Source/cmXCOFF.h
@@ -0,0 +1,65 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ file Copyright.txt or https://cmake.org/licensing for details. */
+#pragma once
+
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include <iosfwd>
+#include <memory>
+#include <string>
+
+#include <cm/optional>
+#include <cm/string_view>
+
+#if !defined(CMake_USE_XCOFF_PARSER)
+# error "This file may be included only if CMake_USE_XCOFF_PARSER is enabled."
+#endif
+
+class cmXCOFFInternal;
+
+/** \class cmXCOFF
+ * \brief XCOFF parser.
+ */
+class cmXCOFF
+{
+public:
+ enum class Mode
+ {
+ ReadOnly,
+ ReadWrite
+ };
+
+ /** Construct with the name of the XCOFF input file to parse. */
+ cmXCOFF(const char* fname, Mode = Mode::ReadOnly);
+
+ /** Destruct. */
+ ~cmXCOFF();
+
+ cmXCOFF(cmXCOFF&&);
+ cmXCOFF(cmXCOFF const&) = delete;
+ cmXCOFF& operator=(cmXCOFF&&);
+ cmXCOFF& operator=(cmXCOFF const&) = delete;
+
+ /** Get the error message if any. */
+ std::string const& GetErrorMessage() const { return this->ErrorMessage; }
+
+ /** Boolean conversion. True if the XCOFF file is valid. */
+ explicit operator bool() const { return this->Valid(); }
+
+ /** Get the LIBPATH (RPATH) parsed from the file, if any. */
+ cm::optional<cm::string_view> GetLibPath() const;
+
+ /** Set the LIBPATH (RPATH).
+ Works only if cmXCOFF was constructed with Mode::ReadWrite. */
+ bool SetLibPath(cm::string_view libPath);
+
+ /** Remove the LIBPATH (RPATH).
+ Works only if cmXCOFF was constructed with Mode::ReadWrite. */
+ bool RemoveLibPath();
+
+private:
+ friend class cmXCOFFInternal;
+ bool Valid() const;
+ std::unique_ptr<cmXCOFFInternal> Internal;
+ std::string ErrorMessage;
+};