CMake/Source/cmOutputConverter.h

150 lines
5.2 KiB
C
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmOutputConverter_h
#define cmOutputConverter_h
#include <cmConfigure.h> // IWYU pragma: keep
#include "cmState.h"
#include <string>
#include <vector>
class cmOutputConverter
{
public:
cmOutputConverter(cmState::Snapshot snapshot);
enum OutputFormat
{
SHELL,
WATCOMQUOTE,
RESPONSE
};
std::string ConvertToOutputFormat(const std::string& source,
2015-06-14 21:27:37 +03:00
OutputFormat output) const;
std::string ConvertDirectorySeparatorsForShell(
const std::string& source) const;
///! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const std::string& remote,
2015-06-14 21:27:37 +03:00
OutputFormat format = SHELL) const;
void SetLinkScriptShell(bool linkScriptShell);
/**
* Flags to pass to Shell_GetArgumentForWindows or
* Shell_GetArgumentForUnix. 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)
};
/**
* Transform the given command line argument for use in a Windows or
* Unix shell. Returns a pointer to the end of the command line
* argument in the provided output buffer. Flags may be passed to
* modify the generated quoting and escape sequences to work under
* alternative environments.
*/
static std::string Shell_GetArgumentForWindows(const char* in, int flags);
static std::string Shell_GetArgumentForUnix(const char* in, int flags);
std::string EscapeForShell(const std::string& str, bool makeVars = false,
bool forEcho = false,
bool useWatcomQuote = false) const;
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
{
FortranFormatNone,
FortranFormatFixed,
FortranFormatFree
};
static FortranFormat GetFortranFormat(const char* value);
/**
* Convert the given remote path to a relative path with respect to
* the given local path. The local path must be given in component
* form (see SystemTools::SplitPath) without a trailing slash. The
* remote path must use forward slashes and not already be escaped
* or quoted.
*/
std::string ConvertToRelativePath(const std::vector<std::string>& local,
const std::string& in_remote,
2015-06-14 21:27:37 +03:00
bool force = false) 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.
* 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);
private:
cmState* GetState() const;
static int Shell__CharIsWhitespace(char c);
static int Shell__CharNeedsQuotesOnUnix(char c);
static int Shell__CharNeedsQuotesOnWindows(char c);
static int Shell__CharNeedsQuotes(char c, int isUnix, int flags);
static int Shell__CharIsMakeVariableName(char c);
static const char* Shell__SkipMakeVariables(const char* c);
static int Shell__ArgumentNeedsQuotes(const char* in, int isUnix, int flags);
static std::string Shell__GetArgument(const char* in, int isUnix, int flags);
private:
cmState::Snapshot StateSnapshot;
bool LinkScriptShell;
};
#endif