InstallRequiredSystemLibraries fails to detect clang on Windows

Clang on Windows (not clang on MinGW) uses the same MSVC libraries as MSVC itself. However, when I included InstallRequiredSystemLibraries, the necessary msvc DLLs were not properly installed.

Looking into InstallRequiredSystemLibraries.cmake, the code for msvc dlls is hidden behind an if(MSVC) condition which is false set when using clang because MSVC variable is not set.

For reference, this is the code I’m using to install my application on Windows. It works with MSVC and does not work with clang.

include(InstallRequiredSystemLibraries)
install(TARGETS application)
install(IMPORTED_RUNTIME_ARTIFACTS application RUNTIME_DEPENDENCY_SET application_RUNTIME_DEPENDENCY_SET)
set(system32_regex "^$ENV{SystemRoot}\\system32")
string(REPLACE "\\" "[\\/\\\\]" system32_regex "${system32_regex}")
install(RUNTIME_DEPENDENCY_SET application_RUNTIME_DEPENDENCY_SET
	PRE_EXCLUDE_REGEXES "api-ms-.*"
	POST_EXCLUDE_REGEXES "${system32_regex}"
)

Can someone more experienced than me confirm if this is a CMake bug or not? Is there any workaround for this (besides switching to MSVC compiler)?

1 Like