Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
3de70102
Commit
3de70102
authored
Oct 17, 2004
by
Andy Cedilnik
Browse files
ENH: Add method to get the relative path to source or build
parent
17619508
Changes
2
Hide whitespace changes
Inline
Side-by-side
Source/cmCTest.cxx
View file @
3de70102
...
...
@@ -2123,6 +2123,50 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfS
}
}
std
::
string
cmCTest
::
GetShortPathToFile
(
const
char
*
fname
)
{
const
std
::
string
&
sourceDir
=
GetDartConfiguration
(
"SourceDirectory"
);
const
std
::
string
&
buildDir
=
GetDartConfiguration
(
"BuildDirectory"
);
// Find relative paths to both directories
std
::
string
srcRelpath
=
cmSystemTools
::
RelativePath
(
sourceDir
.
c_str
(),
fname
);
std
::
string
bldRelpath
=
cmSystemTools
::
RelativePath
(
buildDir
.
c_str
(),
fname
);
// If any contains "." it is not parent directory
bool
inSrc
=
srcRelpath
.
find
(
".."
)
==
srcRelpath
.
npos
;
bool
inBld
=
bldRelpath
.
find
(
".."
)
==
bldRelpath
.
npos
;
// TODO: Handle files with .. in their name
std
::
string
*
res
=
0
;
if
(
inSrc
&&
inBld
)
{
// If both have relative path with no dots, pick the shorter one
if
(
srcRelpath
.
size
()
<
bldRelpath
.
size
()
)
{
res
=
&
srcRelpath
;
}
else
{
res
=
&
bldRelpath
;
}
}
else
if
(
inSrc
)
{
res
=
&
srcRelpath
;
}
else
if
(
inBld
)
{
res
=
&
bldRelpath
;
}
if
(
!
res
)
{
return
fname
;
}
cmSystemTools
::
ConvertToUnixSlashes
(
*
res
);
return
"./"
+
*
res
;
}
std
::
string
cmCTest
::
GetDartConfiguration
(
const
char
*
name
)
{
return
m_DartConfiguration
[
name
];
...
...
Source/cmCTest.h
View file @
3de70102
...
...
@@ -183,6 +183,9 @@ public:
//! Get the path to CTest
const
char
*
GetCTestExecutable
()
{
return
m_CTestSelf
.
c_str
();
}
//! Get the short path to the file. This means if the file is in binary or
//source directory, it will become /.../relative/path/to/file
std
::
string
GetShortPathToFile
(
const
char
*
fname
);
private:
// these are helper classes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment