2015-04-12 14:15:51 +03:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#ifndef cmOutputConverter_h
|
|
|
|
#define cmOutputConverter_h
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <cmConfigure.h> // IWYU pragma: keep
|
2016-09-01 21:05:48 +03:00
|
|
|
|
2015-04-12 14:15:51 +03:00
|
|
|
#include "cmState.h"
|
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-04-12 14:15:51 +03:00
|
|
|
class cmOutputConverter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cmOutputConverter(cmState::Snapshot snapshot);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert something to something else. This is a centralized conversion
|
|
|
|
* routine used by the generators to handle relative paths and the like.
|
|
|
|
* The flags determine what is actually done.
|
|
|
|
*
|
|
|
|
* relative: treat the argument as a directory and convert it to make it
|
|
|
|
* relative or full or unchanged. If relative (HOME, START etc) then that
|
|
|
|
* specifies what it should be relative to.
|
|
|
|
*
|
|
|
|
* output: make the result suitable for output to a...
|
|
|
|
*
|
|
|
|
* optional: should any relative path operation be controlled by the rel
|
|
|
|
* path setting
|
|
|
|
*/
|
2016-05-16 17:34:04 +03:00
|
|
|
enum RelativeRoot
|
|
|
|
{
|
|
|
|
HOME,
|
|
|
|
START,
|
|
|
|
HOME_OUTPUT,
|
|
|
|
START_OUTPUT
|
|
|
|
};
|
|
|
|
enum OutputFormat
|
|
|
|
{
|
|
|
|
MAKERULE,
|
|
|
|
SHELL,
|
|
|
|
WATCOMQUOTE,
|
|
|
|
RESPONSE
|
|
|
|
};
|
2015-04-12 14:15:51 +03:00
|
|
|
std::string ConvertToOutputFormat(const std::string& source,
|
2015-06-14 21:27:37 +03:00
|
|
|
OutputFormat output) const;
|
2015-04-12 14:15:51 +03:00
|
|
|
std::string Convert(const std::string& remote, RelativeRoot local,
|
2016-08-27 14:44:57 +03:00
|
|
|
OutputFormat output) const;
|
2016-08-27 14:44:56 +03:00
|
|
|
std::string ConvertToRelativePath(const std::string& remote,
|
|
|
|
RelativeRoot local) const;
|
2015-09-24 13:33:01 +03:00
|
|
|
std::string ConvertDirectorySeparatorsForShell(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& source) const;
|
2015-04-12 14:15:51 +03:00
|
|
|
|
|
|
|
///! 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;
|
2015-04-12 14:15:51 +03:00
|
|
|
|
|
|
|
void SetLinkScriptShell(bool linkScriptShell);
|
|
|
|
|
2015-07-07 22:06:44 +03:00
|
|
|
/**
|
|
|
|
* 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. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_Make = (1 << 0),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** The target shell is in a VS project file. Do not use with
|
|
|
|
Shell_Flag_Make. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_VSIDE = (1 << 1),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** In a windows shell the argument is being passed to "echo". */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_EchoWindows = (1 << 2),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** The target shell is in a Watcom WMake makefile. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_WatcomWMake = (1 << 3),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** The target shell is in a MinGW Make makefile. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_MinGWMake = (1 << 4),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** The target shell is in a NMake makefile. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_NMake = (1 << 5),
|
2015-07-07 22:06:44 +03: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-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_AllowMakeVariables = (1 << 6),
|
2015-07-07 22:06:44 +03:00
|
|
|
|
|
|
|
/** The target shell quoting uses extra single Quotes for Watcom tools. */
|
2016-05-16 17:34:04 +03:00
|
|
|
Shell_Flag_WatcomQuote = (1 << 7)
|
2015-07-07 22:06:44 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-06-16 00:41:46 +03:00
|
|
|
static std::string Shell_GetArgumentForWindows(const char* in, int flags);
|
|
|
|
static std::string Shell_GetArgumentForUnix(const char* in, int flags);
|
2015-07-07 22:06:44 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string EscapeForShell(const std::string& str, bool makeVars = false,
|
|
|
|
bool forEcho = false,
|
|
|
|
bool useWatcomQuote = false) const;
|
2015-04-12 14:15:51 +03:00
|
|
|
|
|
|
|
static std::string EscapeForCMake(const std::string& str);
|
|
|
|
|
2015-07-07 21:31:46 +03:00
|
|
|
/** Compute an escaped version of the given argument for use in a
|
|
|
|
windows shell. */
|
|
|
|
static std::string EscapeWindowsShellArgument(const char* arg,
|
|
|
|
int shell_flags);
|
|
|
|
|
2015-04-12 14:15:51 +03:00
|
|
|
enum FortranFormat
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
2015-04-12 14:15:51 +03:00
|
|
|
FortranFormatNone,
|
|
|
|
FortranFormatFixed,
|
|
|
|
FortranFormatFree
|
2016-05-16 17:34:04 +03:00
|
|
|
};
|
2015-04-12 14:15:51 +03:00
|
|
|
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;
|
2015-04-12 14:15:51 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
cmState* GetState() const;
|
|
|
|
|
2015-07-07 22:06:44 +03:00
|
|
|
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);
|
2016-05-16 17:34:04 +03:00
|
|
|
static int Shell__ArgumentNeedsQuotes(const char* in, int isUnix, int flags);
|
2016-06-16 00:41:46 +03:00
|
|
|
static std::string Shell__GetArgument(const char* in, int isUnix, int flags);
|
2015-07-07 22:06:44 +03:00
|
|
|
|
2015-04-12 14:15:51 +03:00
|
|
|
private:
|
|
|
|
cmState::Snapshot StateSnapshot;
|
|
|
|
|
|
|
|
bool LinkScriptShell;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|