mirror of
https://github.com/reactos/CMake.git
synced 2024-12-11 05:14:00 +00:00
Merge topic 'improve-get_filename_component-names'
7d1590e
get_filename_component: Add DIRECTORY option (#14091)ec1ba9b
get_filename_component: Add explicit unit tests
This commit is contained in:
commit
7a198773f3
@ -58,7 +58,7 @@ bool cmGetFilenameComponentCommand
|
||||
}
|
||||
std::string storeArgs;
|
||||
std::string programArgs;
|
||||
if (args[2] == "PATH")
|
||||
if (args[2] == "DIRECTORY" || args[2] == "PATH")
|
||||
{
|
||||
result = cmSystemTools::GetFilenamePath(filename);
|
||||
}
|
||||
|
@ -64,12 +64,13 @@ public:
|
||||
return
|
||||
" get_filename_component(<VAR> <FileName> <COMP> [CACHE])\n"
|
||||
"Set <VAR> to a component of <FileName>, where <COMP> is one of:\n"
|
||||
" PATH = Directory without file name\n"
|
||||
" DIRECTORY = Directory without file name\n"
|
||||
" NAME = File name without directory\n"
|
||||
" EXT = File name longest extension (.b.c from d/a.b.c)\n"
|
||||
" NAME_WE = File name without directory or longest extension\n"
|
||||
" ABSOLUTE = Full path to file\n"
|
||||
" REALPATH = Full path to existing file with symlinks resolved\n"
|
||||
" PATH = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)\n"
|
||||
"Paths are returned with forward slashes and have no trailing slahes. "
|
||||
"The longest file extension is always considered. "
|
||||
"If the optional CACHE argument is specified, the result variable is "
|
||||
|
@ -634,86 +634,6 @@ int main()
|
||||
cmPassed("WHILE command is working");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
|
||||
#ifndef FILENAME_VAR_PATH_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_PATH_NAME is not defined.");
|
||||
#else
|
||||
if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) ||
|
||||
(strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0))
|
||||
{
|
||||
cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_EXT
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_EXT is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_NAME_WE
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME_WE is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PATH_VAR_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"PATH_VAR_NAME is not defined.");
|
||||
#else
|
||||
if((strcmp(PATH_VAR_NAME, "Complex") == 0) ||
|
||||
(strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0))
|
||||
{
|
||||
cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"PATH_VAR_NAME == ", PATH_VAR_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test LOAD_CACHE
|
||||
|
||||
|
@ -182,17 +182,3 @@ set(FOREACH_CONCAT "")
|
||||
foreach (INDEX a;b;c;d;e;f;g)
|
||||
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
||||
endforeach()
|
||||
|
||||
#
|
||||
# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
#
|
||||
find_file(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR})
|
||||
|
||||
get_filename_component(FILENAME_VAR_PATH ${FILENAME_VAR} PATH)
|
||||
get_filename_component(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME)
|
||||
get_filename_component(FILENAME_VAR_NAME ${FILENAME_VAR} NAME)
|
||||
get_filename_component(FILENAME_VAR_EXT ${FILENAME_VAR} EXT)
|
||||
get_filename_component(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE)
|
||||
|
||||
find_path(PATH_VAR "cmTestConfigure.h.in" ${Complex_SOURCE_DIR})
|
||||
get_filename_component(PATH_VAR_NAME ${PATH_VAR} NAME)
|
||||
|
@ -15,15 +15,6 @@
|
||||
// Test WHILE
|
||||
#define WHILE_VALUE ${while_var}
|
||||
|
||||
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
|
||||
#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}"
|
||||
#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}"
|
||||
#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}"
|
||||
#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}"
|
||||
|
||||
#define PATH_VAR_NAME "${PATH_VAR_NAME}"
|
||||
|
||||
// Test LOAD_CACHE
|
||||
|
||||
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
||||
|
@ -634,86 +634,6 @@ int main()
|
||||
cmPassed("WHILE command is working");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
|
||||
#ifndef FILENAME_VAR_PATH_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_PATH_NAME is not defined.");
|
||||
#else
|
||||
if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) ||
|
||||
(strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0))
|
||||
{
|
||||
cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_EXT
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_EXT is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef FILENAME_VAR_NAME_WE
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME_WE is not defined.");
|
||||
#else
|
||||
if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef PATH_VAR_NAME
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"PATH_VAR_NAME is not defined.");
|
||||
#else
|
||||
if((strcmp(PATH_VAR_NAME, "Complex") == 0) ||
|
||||
(strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0))
|
||||
{
|
||||
cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
|
||||
"PATH_VAR_NAME == ", PATH_VAR_NAME);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Test LOAD_CACHE
|
||||
|
||||
|
@ -182,17 +182,3 @@ set(FOREACH_CONCAT "")
|
||||
foreach (INDEX a;b;c;d;e;f;g)
|
||||
set(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}")
|
||||
endforeach()
|
||||
|
||||
#
|
||||
# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
#
|
||||
find_file(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR})
|
||||
|
||||
get_filename_component(FILENAME_VAR_PATH ${FILENAME_VAR} PATH)
|
||||
get_filename_component(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME)
|
||||
get_filename_component(FILENAME_VAR_NAME ${FILENAME_VAR} NAME)
|
||||
get_filename_component(FILENAME_VAR_EXT ${FILENAME_VAR} EXT)
|
||||
get_filename_component(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE)
|
||||
|
||||
find_path(PATH_VAR "cmTestConfigure.h.in" ${Complex_SOURCE_DIR})
|
||||
get_filename_component(PATH_VAR_NAME ${PATH_VAR} NAME)
|
||||
|
@ -15,15 +15,6 @@
|
||||
// Test WHILE
|
||||
#define WHILE_VALUE ${while_var}
|
||||
|
||||
// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
|
||||
|
||||
#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}"
|
||||
#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}"
|
||||
#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}"
|
||||
#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}"
|
||||
|
||||
#define PATH_VAR_NAME "${PATH_VAR_NAME}"
|
||||
|
||||
// Test LOAD_CACHE
|
||||
|
||||
#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}"
|
||||
|
@ -71,6 +71,7 @@ add_RunCMake_test(CompatibleInterface)
|
||||
add_RunCMake_test(add_dependencies)
|
||||
add_RunCMake_test(build_command)
|
||||
add_RunCMake_test(find_package)
|
||||
add_RunCMake_test(get_filename_component)
|
||||
add_RunCMake_test(include)
|
||||
add_RunCMake_test(include_directories)
|
||||
add_RunCMake_test(list)
|
||||
|
3
Tests/RunCMake/get_filename_component/CMakeLists.txt
Normal file
3
Tests/RunCMake/get_filename_component/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
33
Tests/RunCMake/get_filename_component/KnownComponents.cmake
Normal file
33
Tests/RunCMake/get_filename_component/KnownComponents.cmake
Normal file
@ -0,0 +1,33 @@
|
||||
macro(check desc actual expect)
|
||||
if(NOT "x${actual}" STREQUAL "x${expect}")
|
||||
message(SEND_ERROR "${desc}: got \"${actual}\", not \"${expect}\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(filename "/path/to/filename.ext.in")
|
||||
set(expect_DIRECTORY "/path/to")
|
||||
set(expect_NAME "filename.ext.in")
|
||||
set(expect_EXT ".ext.in")
|
||||
set(expect_NAME_WE "filename")
|
||||
set(expect_PATH "/path/to")
|
||||
foreach(c DIRECTORY NAME EXT NAME_WE PATH)
|
||||
get_filename_component(actual_${c} "${filename}" ${c})
|
||||
check("${c}" "${actual_${c}}" "${expect_${c}}")
|
||||
endforeach()
|
||||
|
||||
get_filename_component(test_slashes "c:\\path\\to\\filename.ext.in" DIRECTORY)
|
||||
check("DIRECTORY from backslashes" "${test_slashes}" "c:/path/to")
|
||||
|
||||
get_filename_component(test_winroot "c:\\filename.ext.in" DIRECTORY)
|
||||
check("DIRECTORY in windows root" "${test_winroot}" "c:/")
|
||||
|
||||
get_filename_component(test_absolute "/path/to/a/../filename.ext.in" ABSOLUTE)
|
||||
check("ABSOLUTE" "${test_absolute}" "/path/to/filename.ext.in")
|
||||
|
||||
get_filename_component(test_cache "/path/to/filename.ext.in" DIRECTORY CACHE)
|
||||
check("CACHE 1" "${test_cache}" "/path/to")
|
||||
get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE)
|
||||
check("CACHE 2" "${test_cache}" "/path/to")
|
||||
unset(test_cache CACHE)
|
||||
get_filename_component(test_cache "/path/to/other/filename.ext.in" DIRECTORY CACHE)
|
||||
check("CACHE 3" "${test_cache}" "/path/to/other")
|
4
Tests/RunCMake/get_filename_component/RunCMakeTest.cmake
Normal file
4
Tests/RunCMake/get_filename_component/RunCMakeTest.cmake
Normal file
@ -0,0 +1,4 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(KnownComponents)
|
||||
run_cmake(UnknownComponent)
|
@ -0,0 +1 @@
|
||||
1
|
@ -0,0 +1,4 @@
|
||||
CMake Error at UnknownComponent.cmake:1 \(get_filename_component\):
|
||||
get_filename_component unknown component BOGUS
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
@ -0,0 +1 @@
|
||||
get_filename_component(var "/path/to/filename.ext.in" BOGUS)
|
Loading…
Reference in New Issue
Block a user