From 582f72bf3bfaf16c1b147d4431d276f7d977aa5b Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 12 Jul 2022 14:55:01 +0100 Subject: [PATCH] Fix linking of generated files in cmake If generation of files is turned off, and a file is missing, when building in tree with cmake, you can end up with the generated file being turned into a symlink to itself. This will also break any future attempt at building with make. Fix this by testing if the file exists prior to attempting to link it. Signed-off-by: Paul Elliott --- CMakeLists.txt | 5 ++++- ChangeLog.d/fix_cmake_gen_files | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 ChangeLog.d/fix_cmake_gen_files diff --git a/CMakeLists.txt b/CMakeLists.txt index 2610359b9..ae224798c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,10 @@ function(link_to_source base_name) set(target "${CMAKE_CURRENT_SOURCE_DIR}/${base_name}") endif() - if (NOT EXISTS ${link}) + # Linking to non-existant file is not desirable. At best you will have a + # dangling link, but when building in tree, this can create a symbolic link + # to itself. + if (EXISTS ${target} AND NOT EXISTS ${link}) if (CMAKE_HOST_UNIX) set(command ln -s ${target} ${link}) else() diff --git a/ChangeLog.d/fix_cmake_gen_files b/ChangeLog.d/fix_cmake_gen_files new file mode 100644 index 000000000..3b2c09992 --- /dev/null +++ b/ChangeLog.d/fix_cmake_gen_files @@ -0,0 +1,3 @@ +Bugfix + * Fix an issue in releases with GEN_FILES turned off whereby missing + generated files could be turned into symlinks to themselves.