Browse code

CMake: Fix Windows build issue w/ conflicting libraries

At install, the CMake build may fail if it detects the same library
dependency in two locations. This happened for us with the following
error:

CMake Error at libfreshclam/cmake_install.cmake:157 (file):
file Multiple conflicting paths found for libcrypto-3-x64.dll:

C:/Users/clamav_jenkins_svc.TALOS/clam_dependencies/x64/lib/libcrypto-3-x64.dll
C:/WINDOWS/system32/libcrypto-3-x64.dll
C:\WINDOWS\system32/libcrypto-3-x64.dll
Call Stack (most recent call first):
cmake_install.cmake:96 (include)

This happens when system provided DLL names match exactly with the ones
we provide. ClamAV woudld't prefer that DLL at load time, because it
looks in the EXE directory first. But it does confuse the `file()`
command used to locate build dependencies.

The fix in this commit uses a regex to exclude all libraries found under
C:\Windows

Micah Snyder authored on 2025/02/14 10:07:46
Showing 5 changed files
... ...
@@ -47,6 +47,8 @@ if(WIN32)
47 47
             UNRESOLVED_DEPENDENCIES_VAR _u_deps
48 48
             DIRECTORIES
49 49
                 $<TARGET_FILE_DIR:Curses::curses>
50
+            POST_EXCLUDE_REGEXES
51
+                "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
50 52
         )
51 53
         foreach(_file ${_r_deps})
52 54
             string(TOLOWER ${_file} _file_lower)
... ...
@@ -57,6 +57,8 @@ if(WIN32)
57 57
             DIRECTORIES
58 58
                 $<TARGET_FILE_DIR:CURL::libcurl>
59 59
                 $<TARGET_FILE_DIR:JSONC::jsonc>
60
+            POST_EXCLUDE_REGEXES
61
+                "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
60 62
         )
61 63
         foreach(_file ${_r_deps})
62 64
             string(TOLOWER ${_file} _file_lower)
... ...
@@ -586,6 +586,8 @@ if(ENABLE_SHARED_LIB)
586 586
                     $<TARGET_FILE_DIR:PCRE2::pcre2>
587 587
                     $<TARGET_FILE_DIR:LibXml2::LibXml2>
588 588
                     $<TARGET_FILE_DIR:JSONC::jsonc>
589
+                POST_EXCLUDE_REGEXES
590
+                    "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
589 591
             )
590 592
             foreach(_file ${_r_deps})
591 593
                 string(TOLOWER ${_file} _file_lower)
... ...
@@ -76,6 +76,8 @@ if(ENABLE_SHARED_LIB)
76 76
                     $<TARGET_FILE_DIR:CURL::libcurl>
77 77
                     $<TARGET_FILE_DIR:OpenSSL::SSL>
78 78
                     $<TARGET_FILE_DIR:OpenSSL::Crypto>
79
+                POST_EXCLUDE_REGEXES
80
+                   "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
79 81
             )
80 82
             foreach(_file ${_r_deps})
81 83
                 string(TOLOWER ${_file} _file_lower)
... ...
@@ -467,6 +467,8 @@ if(WIN32)
467 467
                         $<TARGET_FILE_DIR:LibXml2::LibXml2>
468 468
                         $<TARGET_FILE_DIR:CURL::libcurl>
469 469
                         $<TARGET_FILE_DIR:JSONC::jsonc>
470
+                    POST_EXCLUDE_REGEXES
471
+                        "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
470 472
                     CONFLICTING_DEPENDENCIES_PREFIX CTEST_CONFLICTING_DEPENDENCIES
471 473
                 )
472 474
                 foreach(_file ${_r_deps})
... ...
@@ -522,6 +524,8 @@ if(WIN32)
522 522
                         $<TARGET_FILE_DIR:PCRE2::pcre2>
523 523
                         $<TARGET_FILE_DIR:LibXml2::LibXml2>
524 524
                         $<TARGET_FILE_DIR:JSONC::jsonc>
525
+                    POST_EXCLUDE_REGEXES
526
+                        "[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
525 527
                     CONFLICTING_DEPENDENCIES_PREFIX CTEST_CONFLICTING_DEPENDENCIES
526 528
                 )
527 529
                 foreach(_file ${_r_deps})