cmake/Source/cmOutputConverter.h

155 lines
5.0 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2015-11-17 17:22:37 +01:00
2017-07-20 19:35:53 +02:00
#include "cmConfigure.h" // IWYU pragma: keep
2015-11-17 17:22:37 +01:00
2016-10-30 18:24:19 +01:00
#include <string>
2017-04-14 19:02:05 +02:00
2020-02-01 23:06:01 +01:00
#include <cm/string_view>
2017-04-14 19:02:05 +02:00
#include "cmStateSnapshot.h"
class cmState;
2016-10-30 18:24:19 +01:00
2015-11-17 17:22:37 +01:00
class cmOutputConverter
{
public:
2017-07-20 19:35:53 +02:00
cmOutputConverter(cmStateSnapshot const& snapshot);
2015-11-17 17:22:37 +01:00
2021-09-14 00:13:48 +02:00
/**
* Convert the given remote path to a relative path with respect to
* one of our common work directories. The path must use forward
* slashes and not already be escaped or quoted.
* The conversion is skipped if the paths are not both in the source
* or both in the binary tree.
*/
std::string MaybeRelativeToTopBinDir(std::string const& path) const;
std::string MaybeRelativeToCurBinDir(std::string const& path) const;
std::string const& GetRelativePathTopSource() const;
std::string const& GetRelativePathTopBinary() const;
void SetRelativePathTopSource(std::string const& top);
void SetRelativePathTopBinary(std::string const& top);
2016-07-09 11:21:54 +02:00
enum OutputFormat
{
SHELL,
WATCOMQUOTE,
2020-08-30 11:54:41 +02:00
NINJAMULTI,
2016-07-09 11:21:54 +02:00
RESPONSE
};
2020-02-01 23:06:01 +01:00
std::string ConvertToOutputFormat(cm::string_view source,
2015-11-17 17:22:37 +01:00
OutputFormat output) const;
2020-02-01 23:06:01 +01:00
std::string ConvertDirectorySeparatorsForShell(cm::string_view source) const;
2015-11-17 17:22:37 +01:00
2019-11-11 23:01:05 +01:00
//! for existing files convert to output path and short path if spaces
2015-11-17 17:22:37 +01:00
std::string ConvertToOutputForExisting(const std::string& remote,
OutputFormat format = SHELL) const;
void SetLinkScriptShell(bool linkScriptShell);
/**
2017-04-14 19:02:05 +02:00
* Flags to pass to Shell_GetArgument. These modify the generated
2015-11-17 17:22:37 +01:00
* quoting and escape sequences to work under alternative
* environments.
*/
enum Shell_Flag_e
{
/** The target shell is in a makefile. */
2016-07-09 11:21:54 +02:00
Shell_Flag_Make = (1 << 0),
2015-11-17 17:22:37 +01:00
/** The target shell is in a VS project file. Do not use with
Shell_Flag_Make. */
2016-07-09 11:21:54 +02:00
Shell_Flag_VSIDE = (1 << 1),
2015-11-17 17:22:37 +01:00
/** In a windows shell the argument is being passed to "echo". */
2016-07-09 11:21:54 +02:00
Shell_Flag_EchoWindows = (1 << 2),
2015-11-17 17:22:37 +01:00
/** The target shell is in a Watcom WMake makefile. */
2016-07-09 11:21:54 +02:00
Shell_Flag_WatcomWMake = (1 << 3),
2015-11-17 17:22:37 +01:00
/** The target shell is in a MinGW Make makefile. */
2016-07-09 11:21:54 +02:00
Shell_Flag_MinGWMake = (1 << 4),
2015-11-17 17:22:37 +01:00
/** The target shell is in a NMake makefile. */
2016-07-09 11:21:54 +02:00
Shell_Flag_NMake = (1 << 5),
2015-11-17 17:22:37 +01:00
/** 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. */
2016-07-09 11:21:54 +02:00
Shell_Flag_AllowMakeVariables = (1 << 6),
2015-11-17 17:22:37 +01:00
/** The target shell quoting uses extra single Quotes for Watcom tools. */
2017-04-14 19:02:05 +02:00
Shell_Flag_WatcomQuote = (1 << 7),
2015-11-17 17:22:37 +01:00
2020-08-30 11:54:41 +02:00
Shell_Flag_IsUnix = (1 << 8),
Shell_Flag_UnescapeNinjaConfiguration = (1 << 9),
2022-03-29 21:10:50 +02:00
Shell_Flag_IsResponse = (1 << 10)
2017-04-14 19:02:05 +02:00
};
2015-11-17 17:22:37 +01:00
2020-02-01 23:06:01 +01:00
std::string EscapeForShell(cm::string_view str, bool makeVars = false,
2020-08-30 11:54:41 +02:00
bool forEcho = false, bool useWatcomQuote = false,
2022-03-29 21:10:50 +02:00
bool unescapeNinjaConfiguration = false,
bool forResponse = false) const;
2015-11-17 17:22:37 +01:00
2022-03-29 21:10:50 +02:00
enum class WrapQuotes
{
Wrap,
NoWrap,
};
static std::string EscapeForCMake(cm::string_view str,
WrapQuotes wrapQuotes = WrapQuotes::Wrap);
2015-11-17 17:22:37 +01:00
/** Compute an escaped version of the given argument for use in a
windows shell. */
2020-02-01 23:06:01 +01:00
static std::string EscapeWindowsShellArgument(cm::string_view arg,
2015-11-17 17:22:37 +01:00
int shell_flags);
enum FortranFormat
2016-07-09 11:21:54 +02:00
{
2015-11-17 17:22:37 +01:00
FortranFormatNone,
FortranFormatFixed,
FortranFormatFree
2016-07-09 11:21:54 +02:00
};
2020-02-01 23:06:01 +01:00
static FortranFormat GetFortranFormat(cm::string_view value);
2020-08-30 11:54:41 +02:00
enum class FortranPreprocess
{
Unset,
NotNeeded,
Needed
};
static FortranPreprocess GetFortranPreprocess(cm::string_view value);
2015-11-17 17:22:37 +01:00
2021-09-14 00:13:48 +02:00
protected:
cmStateSnapshot StateSnapshot;
2015-11-17 17:22:37 +01:00
private:
cmState* GetState() const;
2021-09-14 00:13:48 +02:00
static bool Shell_CharNeedsQuotes(char c, int flags);
static cm::string_view::iterator Shell_SkipMakeVariables(
2020-02-01 23:06:01 +01:00
cm::string_view::iterator begin, cm::string_view::iterator end);
2021-09-14 00:13:48 +02:00
static bool Shell_ArgumentNeedsQuotes(cm::string_view in, int flags);
static std::string Shell_GetArgument(cm::string_view in, int flags);
2015-11-17 17:22:37 +01:00
bool LinkScriptShell;
2021-09-14 00:13:48 +02:00
// The top-most directories for relative path conversion. Both the
// source and destination location of a relative path conversion
// must be underneath one of these directories (both under source or
// both under binary) in order for the relative path to be evaluated
// safely by the build tools.
std::string RelativePathTopSource;
std::string RelativePathTopBinary;
void ComputeRelativePathTopSource();
void ComputeRelativePathTopBinary();
std::string MaybeRelativeTo(std::string const& local_path,
std::string const& remote_path) const;
};