From b55c08b6b68e35693bea1aa865b7626778bf470c Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Tue, 23 Apr 2024 18:35:10 +0200
Subject: [PATCH] AtlasCMake: improve detection of non-existent files for
 install commands

If the following matches no files, we currently print an error:
```
atlas_install_joboptions( share/*.py )
```

However, no error is printed for the following cases
```
atlas_install_joboptions( share/*.py share/*.txt)
atlas_install_joboptions( share/*.py share/foo.txt)
atlas_install_joboptions( share/foo.py share/foo.txt)
```
if at least one element in the list returns a valid file.

Improve the check by requiring that each element in the list is a
valid entry.
---
 .../modules/AtlasInstallFunctions.cmake       | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
index 6b940cd2..61442578 100644
--- a/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
+++ b/Build/AtlasCMake/modules/AtlasInstallFunctions.cmake
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 #
 # This file collects the ATLAS CMake helper functions that are used to install
 # various types of files/directories from a package.
@@ -211,15 +211,18 @@ function( atlas_install_generic )
    if( ATLAS_ALWAYS_CHECK_WILDCARDS )
       list( APPEND _extraFlags CONFIGURE_DEPENDS )
    endif()
-   file( GLOB _files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" ${_extraFlags}
-      ${ARG_UNPARSED_ARGUMENTS} )
-   unset( _extraFlags )
 
-   if( NOT _files )
-      message( SEND_ERROR "Installation of '${ARG_UNPARSED_ARGUMENTS}' "
-         "does not match any files." )
-      return()
-   endif()
+   set( _files )
+   foreach( _glob ${ARG_UNPARSED_ARGUMENTS} )
+      # Check each filename (wildcard) individually to make sure it exists (is not empty):
+      file( GLOB _result RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" ${_extraFlags} ${_glob} )
+      if( _result )
+         list( APPEND _files ${_result} )
+      else()
+         message( SEND_ERROR "Installation of '${_glob}' does not match any files." )
+      endif()
+   endforeach()
+   unset( _extraFlags )
 
    atlas_group_source_files( ${_files} )
 
-- 
GitLab