ENH: Added support for using backslash-style escaping in CMakeLists.txt file arguments. This allows double quotes to be used in arguments.

This commit is contained in:
Brad King 2001-07-17 09:54:05 -04:00
parent e169953e92
commit c5381e8588
9 changed files with 82 additions and 37 deletions

View File

@ -1,2 +1,2 @@
# just install the modules
INSTALL_FILES(/share/CMake/Modules .*\.cmake$)
INSTALL_FILES(/share/CMake/Modules .*\\.cmake$)

View File

@ -7,5 +7,5 @@ FIND_PATH(DART_ROOT README.INSTALL
${PROJECT_SOURCE_DIR}/Dart
/usr/share/Dart
"C:/Program Files/Dart"
[HKEY_LOCAL_MACHINE\SOFTWARE\Dart\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Dart\\InstallPath]
)

View File

@ -10,14 +10,14 @@
FIND_LIBRARY(JAVA_AWT_LIBRARY jawt
PATHS /usr/lib /usr/local/lib
"[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.3;JavaHome]/lib"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
)
# add in the include path
FIND_PATH(JAVA_INCLUDE_PATH jni.h
/usr/include
/usr/local/include
"[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.3;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
)
FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h
@ -26,5 +26,3 @@ FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h
)
FIND_PATH(JAVE_AWT_INCLUDE_PATH jawt.h ${JAVA_INCLUDE_PATH} )

View File

@ -13,8 +13,8 @@ FIND_LIBRARY(PYTHON_DEBUG_LIBRARY
PATHS
/usr/lib
/usr/local/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath]/libs/Debug
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.0\InstallPath]/libs/Debug
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs/Debug
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs/Debug
)
FIND_LIBRARY(PYTHON_LIBRARY
@ -24,8 +24,8 @@ FIND_LIBRARY(PYTHON_LIBRARY
/usr/lib/python2.1/config
/usr/lib/python2.0/config
/usr/local/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath]/libs
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.0\InstallPath]/libs
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs
)
FIND_PATH(PYTHON_INCLUDE_PATH Python.h
@ -33,7 +33,7 @@ FIND_PATH(PYTHON_INCLUDE_PATH Python.h
/usr/include/python2.1
/usr/include/python2.0
/usr/local/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.0\InstallPath]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/include
)

View File

@ -30,10 +30,10 @@ FIND_LIBRARY(TCL_LIBRARY
/usr/lib
/usr/local/lib
"C:/Program Files/Tcl/lib"
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.3;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.2;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.0;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib
"${TCL_TCLSH_PATH}/../lib"
"${TK_WISH_PATH}/../lib"
)
@ -44,10 +44,10 @@ FIND_LIBRARY(TK_LIBRARY
/usr/lib
/usr/local/lib
"C:/Program Files/Tcl/lib"
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.3;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.2;Root]/lib
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.0;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/lib
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/lib
"${TCL_TCLSH_PATH}/../lib"
"${TK_WISH_PATH}/../lib"
)
@ -56,10 +56,10 @@ FIND_PATH(TCL_INCLUDE_PATH tcl.h
/usr/include
/usr/local/include
"C:/Program Files/Tcl/include"
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.3;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.2;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.0;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include
"${TCL_TCLSH_PATH}/../include"
"${TK_WISH_PATH}/../include"
)
@ -68,10 +68,10 @@ FIND_PATH(TK_INCLUDE_PATH tk.h
/usr/include
/usr/local/include
"C:/Program Files/Tcl/include"
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.3;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.2;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.0;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include
"${TCL_TCLSH_PATH}/../include"
"${TK_WISH_PATH}/../include"
)
@ -80,10 +80,10 @@ FIND_PATH(TK_INTERNAL_PATH tkWinInt.h
/usr/include
/usr/local/include
"C:/Program Files/Tcl/include"
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.4;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.3;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.2;Root]/include
[HKEY_LOCAL_MACHINE\SOFTWARE\Scriptics\Tcl\8.0;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.4;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.3;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.2;Root]/include
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Scriptics\\Tcl\\8.0;Root]/include
"${TCL_TCLSH_PATH}/../include"
"${TK_WISH_PATH}/../include"
)

View File

@ -524,9 +524,9 @@ void cmSystemTools::GetArguments(std::string& line,
std::vector<std::string>& arguments)
{
// Match a normal argument (not quoted, no spaces).
cmRegularExpression normalArgument("[\t ]*([^\" \t]+)[\t ]*");
cmRegularExpression normalArgument("[ \t]*(([^ \t\\]|[\\].)+)[ \t]*");
// Match a quoted argument (surrounded by double quotes, spaces allowed).
cmRegularExpression quotedArgument("[\t ]*(\"[^\"]*\")[\t ]*");
cmRegularExpression quotedArgument("[ \t]*(\"([^\"\\]|[\\].)*\")[ \t]*");
bool done = false;
while(!done)
@ -539,6 +539,7 @@ void cmSystemTools::GetArguments(std::string& line,
if(foundQuoted && foundNormal)
{
// Both matches were found. Take the earlier one.
// Favor double-quoted version if there is a tie.
if(normalArgument.start(1) < quotedArgument.start(1))
{
arg = normalArgument.match(1);
@ -570,12 +571,51 @@ void cmSystemTools::GetArguments(std::string& line,
}
if(!done)
{
arguments.push_back(arg);
arguments.push_back(cmSystemTools::RemoveEscapes(arg.c_str()));
line = line.substr(endpos, line.length() - endpos);
}
}
}
std::string cmSystemTools::RemoveEscapes(const char* s)
{
std::string result = "";
for(const char* ch = s; *ch; ++ch)
{
if(*ch == '\\')
{
++ch;
switch (*ch)
{
case '\\': result.insert(result.end(), '\\'); break;
case '"': result.insert(result.end(), '"'); break;
case ' ': result.insert(result.end(), ' '); break;
case 't': result.insert(result.end(), '\t'); break;
case 'n': result.insert(result.end(), '\n'); break;
case 'r': result.insert(result.end(), '\r'); break;
case '0': result.insert(result.end(), '\0'); break;
case '\0':
{
cmSystemTools::Error("Trailing backslash in argument:\n", s);
return result;
}
default:
{
std::string chStr(1, *ch);
cmSystemTools::Error("Invalid escape sequence \\", chStr.c_str(),
"\nin argument ", s);
}
}
}
else
{
result.insert(result.end(), *ch);
}
}
return result;
}
void cmSystemTools::Error(const char* m1, const char* m2,
const char* m3, const char* m4)
{

View File

@ -132,6 +132,13 @@ public:
*/
static void GetArguments(std::string& line,
std::vector<std::string>& arguments);
/**
* Given a string, replace any escape sequences with the corresponding
* characters.
*/
static std::string RemoveEscapes(const char*);
/**
* Add the paths from the environment variable PATH to the

2
Templates/configure vendored
View File

@ -2449,7 +2449,7 @@ fi
CMAKE_SHLIB_LD_LIBS=""
CMAKE_SHLIB_SUFFIX=".so"
CMAKE_DL_LIBS=""
CMAKE_SHLIB_BUILD_FLAGS='-shared -Wl,-expect_unresolved,\*'
CMAKE_SHLIB_BUILD_FLAGS='-shared -Wl,-expect_unresolved,\\*'
CMAKE_SHLIB_LINK_FLAGS=''
CMAKE_SHLIB_RUNTIME_FLAG="-Wl,-rpath,"
CMAKE_SHLIB_RUNTIME_SEP=":"

View File

@ -263,7 +263,7 @@ case $system in
CMAKE_SHLIB_LD_LIBS=""
CMAKE_SHLIB_SUFFIX=".so"
CMAKE_DL_LIBS=""
CMAKE_SHLIB_BUILD_FLAGS='-shared -Wl,-expect_unresolved,\*'
CMAKE_SHLIB_BUILD_FLAGS='-shared -Wl,-expect_unresolved,\\*'
CMAKE_SHLIB_LINK_FLAGS=''
CMAKE_SHLIB_RUNTIME_FLAG="-Wl,-rpath,"
CMAKE_SHLIB_RUNTIME_SEP=":"