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
This commit is contained in:
Micah Snyder 2025-02-13 20:07:46 -05:00 committed by Valerie Snyder
parent fb541aed64
commit 134b4e7f3c
No known key found for this signature in database
GPG key ID: DCBE519BFAF4C517
5 changed files with 12 additions and 0 deletions

View file

@ -47,6 +47,8 @@ if(WIN32)
UNRESOLVED_DEPENDENCIES_VAR _u_deps
DIRECTORIES
$<TARGET_FILE_DIR:Curses::curses>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
)
foreach(_file ${_r_deps})
string(TOLOWER ${_file} _file_lower)

View file

@ -57,6 +57,8 @@ if(WIN32)
DIRECTORIES
$<TARGET_FILE_DIR:CURL::libcurl>
$<TARGET_FILE_DIR:JSONC::jsonc>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
)
foreach(_file ${_r_deps})
string(TOLOWER ${_file} _file_lower)

View file

@ -586,6 +586,8 @@ if(ENABLE_SHARED_LIB)
$<TARGET_FILE_DIR:PCRE2::pcre2>
$<TARGET_FILE_DIR:LibXml2::LibXml2>
$<TARGET_FILE_DIR:JSONC::jsonc>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
)
foreach(_file ${_r_deps})
string(TOLOWER ${_file} _file_lower)

View file

@ -76,6 +76,8 @@ if(ENABLE_SHARED_LIB)
$<TARGET_FILE_DIR:CURL::libcurl>
$<TARGET_FILE_DIR:OpenSSL::SSL>
$<TARGET_FILE_DIR:OpenSSL::Crypto>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
)
foreach(_file ${_r_deps})
string(TOLOWER ${_file} _file_lower)

View file

@ -467,6 +467,8 @@ if(WIN32)
$<TARGET_FILE_DIR:LibXml2::LibXml2>
$<TARGET_FILE_DIR:CURL::libcurl>
$<TARGET_FILE_DIR:JSONC::jsonc>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
CONFLICTING_DEPENDENCIES_PREFIX CTEST_CONFLICTING_DEPENDENCIES
)
foreach(_file ${_r_deps})
@ -522,6 +524,8 @@ if(WIN32)
$<TARGET_FILE_DIR:PCRE2::pcre2>
$<TARGET_FILE_DIR:LibXml2::LibXml2>
$<TARGET_FILE_DIR:JSONC::jsonc>
POST_EXCLUDE_REGEXES
"[cC]:[\\/][wW][iI][nN][dD][oO][wW][sS]"
CONFLICTING_DEPENDENCIES_PREFIX CTEST_CONFLICTING_DEPENDENCIES
)
foreach(_file ${_r_deps})