cmake/Source/cmOutputConverter.h

136 lines
4.4 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. */
2015-11-17 17:22:37 +01:00
#ifndef cmOutputConverter_h
#define cmOutputConverter_h
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
#include "cmStateSnapshot.h"
class cmState;
class cmStateDirectory;
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
2016-07-09 11:21:54 +02:00
enum OutputFormat
{
SHELL,
WATCOMQUOTE,
RESPONSE
};
2015-11-17 17:22:37 +01:00
std::string ConvertToOutputFormat(const std::string& source,
OutputFormat output) const;
std::string ConvertDirectorySeparatorsForShell(
2016-07-09 11:21:54 +02:00
const std::string& source) const;
2015-11-17 17:22:37 +01:00
///! 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);
/**
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
2017-04-14 19:02:05 +02:00
Shell_Flag_IsUnix = (1 << 8)
};
2015-11-17 17:22:37 +01:00
2016-07-09 11:21:54 +02:00
std::string EscapeForShell(const std::string& str, bool makeVars = false,
bool forEcho = false,
bool useWatcomQuote = false) const;
2015-11-17 17:22:37 +01:00
static std::string EscapeForCMake(const std::string& str);
/** Compute an escaped version of the given argument for use in a
windows shell. */
static std::string EscapeWindowsShellArgument(const char* arg,
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
};
2015-11-17 17:22:37 +01:00
static FortranFormat GetFortranFormat(const char* value);
2017-04-14 19:02:05 +02:00
static bool ContainedInDirectory(std::string const& local_path,
std::string const& remote_path,
2017-07-20 19:35:53 +02:00
cmStateDirectory const& directory);
2015-11-17 17:22:37 +01:00
2016-10-30 18:24:19 +01:00
/**
* Convert the given remote path to a relative path with respect to
* the given local path. Both paths 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 ConvertToRelativePath(std::string const& local_path,
std::string const& remote_path) const;
/**
* Convert the given remote path to a relative path with respect to
* the given local path. Both paths must use forward slashes and not
* already be escaped or quoted.
*/
static std::string ForceToRelativePath(std::string const& local_path,
std::string const& remote_path);
2015-11-17 17:22:37 +01:00
private:
cmState* GetState() const;
static int Shell__CharIsWhitespace(char c);
static int Shell__CharNeedsQuotesOnUnix(char c);
static int Shell__CharNeedsQuotesOnWindows(char c);
2017-04-14 19:02:05 +02:00
static int Shell__CharNeedsQuotes(char c, int flags);
2015-11-17 17:22:37 +01:00
static int Shell__CharIsMakeVariableName(char c);
static const char* Shell__SkipMakeVariables(const char* c);
2017-04-14 19:02:05 +02:00
static int Shell__ArgumentNeedsQuotes(const char* in, int flags);
static std::string Shell__GetArgument(const char* in, int flags);
2015-11-17 17:22:37 +01:00
private:
2017-04-14 19:02:05 +02:00
cmStateSnapshot StateSnapshot;
2015-11-17 17:22:37 +01:00
bool LinkScriptShell;
};
#endif