From d71a7cc19d6e03f89581efdaa8d63db216184d40 Mon Sep 17 00:00:00 2001 From: Jens Carl Date: Thu, 6 May 2021 12:45:56 -0700 Subject: install(FILES): Allow installation of symlinks to directory Allow symbolic links to a directory to be installed via install(FILES ...). Fixes: #22159 --- Source/cmInstallCommand.cxx | 3 ++- Tests/RunCMake/install/FILES-directory-result.txt | 1 + Tests/RunCMake/install/FILES-directory-stderr.txt | 1 + Tests/RunCMake/install/FILES-directory.cmake | 7 +++++++ Tests/RunCMake/install/FILES-symlink-to-directory.cmake | 9 +++++++++ Tests/RunCMake/install/RunCMakeTest.cmake | 4 ++++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/install/FILES-directory-result.txt create mode 100644 Tests/RunCMake/install/FILES-directory-stderr.txt create mode 100644 Tests/RunCMake/install/FILES-directory.cmake create mode 100644 Tests/RunCMake/install/FILES-symlink-to-directory.cmake diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 7788db3..8a34f91 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -1482,7 +1482,8 @@ bool Helper::MakeFilesFullPath(const char* modeName, } // Make sure the file is not a directory. - if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) { + if (gpos == std::string::npos && !cmSystemTools::FileIsSymlink(file) && + cmSystemTools::FileIsDirectory(file)) { this->SetError( cmStrCat(modeName, " given directory \"", relFile, "\" to install.")); return false; diff --git a/Tests/RunCMake/install/FILES-directory-result.txt b/Tests/RunCMake/install/FILES-directory-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/install/FILES-directory-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/install/FILES-directory-stderr.txt b/Tests/RunCMake/install/FILES-directory-stderr.txt new file mode 100644 index 0000000..4699037 --- /dev/null +++ b/Tests/RunCMake/install/FILES-directory-stderr.txt @@ -0,0 +1 @@ +install FILES given directory diff --git a/Tests/RunCMake/install/FILES-directory.cmake b/Tests/RunCMake/install/FILES-directory.cmake new file mode 100644 index 0000000..1199cf7 --- /dev/null +++ b/Tests/RunCMake/install/FILES-directory.cmake @@ -0,0 +1,7 @@ +set(dst "${CMAKE_CURRENT_BINARY_DIR}/dst") +set(src "${CMAKE_CURRENT_BINARY_DIR}/src") + +file(MAKE_DIRECTORY "${dst}") +file(MAKE_DIRECTORY "${src}") + +install(FILES "${src}" DESTINATION "${dst}") diff --git a/Tests/RunCMake/install/FILES-symlink-to-directory.cmake b/Tests/RunCMake/install/FILES-symlink-to-directory.cmake new file mode 100644 index 0000000..ed76470 --- /dev/null +++ b/Tests/RunCMake/install/FILES-symlink-to-directory.cmake @@ -0,0 +1,9 @@ +set(dst "${CMAKE_CURRENT_BINARY_DIR}/dst") +set(src "${CMAKE_CURRENT_BINARY_DIR}/src") +set(lnk "${CMAKE_CURRENT_BINARY_DIR}/lnk") + +file(MAKE_DIRECTORY "${dst}") +file(MAKE_DIRECTORY "${src}") +file(CREATE_LINK "${src}" "${lnk}" SYMBOLIC) + +install(FILES "${lnk}" DESTINATION "${dst}") diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index efd03df..6fb72fc 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -93,6 +93,10 @@ run_cmake(TARGETS-NAMELINK_COMPONENT-bad-all) run_cmake(TARGETS-NAMELINK_COMPONENT-bad-exc) run_cmake(FILES-DESTINATION-TYPE) run_cmake(DIRECTORY-DESTINATION-TYPE) +run_cmake(FILES-directory) +if(NOT WIN32) + run_cmake(FILES-symlink-to-directory) +endif() set(RunCMake_TEST_OPTIONS "-DCMAKE_BUILD_TYPE:STRING=Debug") run_install_test(FILES-RENAME) -- cgit v0.12