Commit 0ec60a40 authored by Brad King's avatar Brad King
Browse files

Merge branch 'source_group-tree' into release-3.16

Merge-request: !3979
parents 408a3a7d 3c0ca5a9
...@@ -78,10 +78,18 @@ std::vector<std::string> prepareFilesPathsForTree( ...@@ -78,10 +78,18 @@ std::vector<std::string> prepareFilesPathsForTree(
for (auto const& filePath : filesPaths) { for (auto const& filePath : filesPaths) {
std::string fullPath = std::string fullPath =
cmSystemTools::CollapseFullPath(filePath, currentSourceDir); cmSystemTools::CollapseFullPath(filePath, currentSourceDir);
// If provided file path is actually not a file, silently ignore it. // If provided file path is actually not a directory, silently ignore it.
if (cmSystemTools::FileExists(fullPath, /*isFile=*/true)) { if (cmSystemTools::FileIsDirectory(fullPath)) {
prepared.emplace_back(std::move(fullPath)); continue;
} }
// Handle directory that doesn't exist yet.
if (!fullPath.empty() &&
(fullPath.back() == '/' || fullPath.back() == '\\')) {
continue;
}
prepared.emplace_back(std::move(fullPath));
} }
return prepared; return prepared;
......
...@@ -13,6 +13,7 @@ include(${RunCMake_TEST_SOURCE_DIR}/SourceGroupHelpers.cmake) ...@@ -13,6 +13,7 @@ include(${RunCMake_TEST_SOURCE_DIR}/SourceGroupHelpers.cmake)
set(SOURCE_GROUPS_TO_FIND set(SOURCE_GROUPS_TO_FIND
"Dir" "Dir"
"Dir\\DirNested" "Dir\\DirNested"
"Generated"
"SourcesPrefix" "SourcesPrefix"
"SourcesPrefix\\PrefixedNested" "SourcesPrefix\\PrefixedNested"
) )
......
set(CMAKE_CONFIGURATION_TYPES Debug) set(CMAKE_CONFIGURATION_TYPES Debug)
# Test regular tree grouping.
set(SRC_FILES set(SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Dir/foo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Dir/foo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Dir/DirNested/foo_nested.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Dir/DirNested/foo_nested.cpp
) )
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SRC_FILES})
# Test files that are not present at configuration time.
set(GENERATED_SRC_FILES
${CMAKE_CURRENT_BINARY_DIR}/Generated/generated.cpp
)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Generated)
if(WIN32)
add_custom_command(OUTPUT ${GENERATED_SRC_FILES}
COMMAND echo. 2>${CMAKE_CURRENT_BINARY_DIR}\\Generated\\generated.cpp
)
else()
add_custom_command(OUTPUT ${GENERATED_SRC_FILES}
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/Generated/generated.cpp
)
endif()
source_group(TREE ${CMAKE_CURRENT_BINARY_DIR} FILES ${GENERATED_SRC_FILES})
# Test prefixed tree grouping.
set(PREFIXED_SRC_FILES set(PREFIXED_SRC_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Prefixed/bar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Prefixed/bar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Prefixed/PrefixedNested/bar_nested.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Prefixed/PrefixedNested/bar_nested.cpp
) )
add_custom_target(SourceGroupTree SOURCES ${SRC_FILES} ${PREFIXED_SRC_FILES}) add_custom_target(SourceGroupTree
SOURCES
${SRC_FILES}
${GENERATED_SRC_FILES}
${PREFIXED_SRC_FILES}
)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SRC_FILES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Prefixed PREFIX SourcesPrefix FILES ${PREFIXED_SRC_FILES}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Prefixed PREFIX SourcesPrefix FILES ${PREFIXED_SRC_FILES})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment