CMake/Source/cmOutputConverter.h
Kitware Robot bdca8b01d2 Modernize: Use #pragma once in all header files
#pragma once is a widely supported compiler pragma, even though it is
not part of the C++ standard. Many of the issues keeping #pragma once
from being standardized (distributed filesystems, build farms, hard
links, etc.) do not apply to CMake - it is easy to build CMake on a
single machine. CMake also does not install any header files which can
be consumed by other projects (though cmCPluginAPI.h has been
deliberately omitted from this conversion in case anyone is still using
it.) Finally, #pragma once has been required to build CMake since at
least August 2017 (7f29bbe6 enabled server mode unconditionally, which
had been using #pragma once since September 2016 (b13d3e0d)). The fact
that we now require C++11 filters out old compilers, and it is unlikely
that there is a compiler which supports C++11 but does not support
#pragma once.
2020-09-03 09:30:21 -04:00

119 lines
3.5 KiB
C++

/* 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 <string>
#include <cm/string_view>
#include "cmStateSnapshot.h"
class cmState;
class cmOutputConverter
{
public:
cmOutputConverter(cmStateSnapshot const& snapshot);
enum OutputFormat
{
SHELL,
WATCOMQUOTE,
NINJAMULTI,
RESPONSE
};
std::string ConvertToOutputFormat(cm::string_view source,
OutputFormat output) const;
std::string ConvertDirectorySeparatorsForShell(cm::string_view source) const;
//! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const std::string& remote,
OutputFormat format = SHELL) const;
void SetLinkScriptShell(bool linkScriptShell);
/**
* Flags to pass to Shell_GetArgument. These modify the generated
* quoting and escape sequences to work under alternative
* environments.
*/
enum Shell_Flag_e
{
/** The target shell is in a makefile. */
Shell_Flag_Make = (1 << 0),
/** The target shell is in a VS project file. Do not use with
Shell_Flag_Make. */
Shell_Flag_VSIDE = (1 << 1),
/** In a windows shell the argument is being passed to "echo". */
Shell_Flag_EchoWindows = (1 << 2),
/** The target shell is in a Watcom WMake makefile. */
Shell_Flag_WatcomWMake = (1 << 3),
/** The target shell is in a MinGW Make makefile. */
Shell_Flag_MinGWMake = (1 << 4),
/** The target shell is in a NMake makefile. */
Shell_Flag_NMake = (1 << 5),
/** Make variable reference syntax $(MAKEVAR) should not be escaped
to allow a build tool to replace it. Replacement values
containing spaces, quotes, backslashes, or other
non-alphanumeric characters that have significance to some makes
or shells produce undefined behavior. */
Shell_Flag_AllowMakeVariables = (1 << 6),
/** The target shell quoting uses extra single Quotes for Watcom tools. */
Shell_Flag_WatcomQuote = (1 << 7),
Shell_Flag_IsUnix = (1 << 8),
Shell_Flag_UnescapeNinjaConfiguration = (1 << 9),
};
std::string EscapeForShell(cm::string_view str, bool makeVars = false,
bool forEcho = false, bool useWatcomQuote = false,
bool unescapeNinjaConfiguration = false) const;
static std::string EscapeForCMake(cm::string_view str);
/** Compute an escaped version of the given argument for use in a
windows shell. */
static std::string EscapeWindowsShellArgument(cm::string_view arg,
int shell_flags);
enum FortranFormat
{
FortranFormatNone,
FortranFormatFixed,
FortranFormatFree
};
static FortranFormat GetFortranFormat(cm::string_view value);
enum class FortranPreprocess
{
Unset,
NotNeeded,
Needed
};
static FortranPreprocess GetFortranPreprocess(cm::string_view value);
private:
cmState* GetState() const;
static bool Shell__CharNeedsQuotes(char c, int flags);
static cm::string_view::iterator Shell__SkipMakeVariables(
cm::string_view::iterator begin, cm::string_view::iterator end);
static bool Shell__ArgumentNeedsQuotes(cm::string_view in, int flags);
static std::string Shell__GetArgument(cm::string_view in, int flags);
private:
cmStateSnapshot StateSnapshot;
bool LinkScriptShell;
};