From 94c6677bd55aac274c1196bfb885c86fc850b475 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Mon, 25 Sep 2023 11:22:54 +0200 Subject: [PATCH] Made the SYCL build work on Windows with CMake >=3.27. Putting version numbers in the DLL names had to be disabled completely, as the logic around DLL_NAME_WITH_SOVERSION seems to be set on putting version numbers into the SYCL shared library DLL names otherwise. :-/ While at it, I noticed that modern CMake versions no longer need the hack of adding "/link" to the linking commands, so the code now looks for a pre-existing "/link" or "-link" argument, and only modifies the linking commands if necessary. --- .../Platform/Windows-IntelLLVM-SYCL.cmake | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmake/sycl/Platform/Windows-IntelLLVM-SYCL.cmake b/cmake/sycl/Platform/Windows-IntelLLVM-SYCL.cmake index b7c1aa3b..cfe67d84 100644 --- a/cmake/sycl/Platform/Windows-IntelLLVM-SYCL.cmake +++ b/cmake/sycl/Platform/Windows-IntelLLVM-SYCL.cmake @@ -10,6 +10,15 @@ include( Platform/Windows-IntelLLVM ) # Set up the variables specifying the command line arguments of the compiler. __windows_compiler_intel( SYCL ) +# With CMake 3.27 by default CMake would try to add version information into +# the DLL file names. Confusing the linking process. +# +# I tried to disable this using the DLL_NAME_WITH_SOVERSION property, the thing +# that was introduced in CMake 3.27, but for some reason that did not work. :-/ +# So when SYCL code is being used on Windows, I disable "versioned SONAMEs" +# completely. For all languages and targets. +set( CMAKE_PLATFORM_NO_VERSIONED_SONAME TRUE ) + # Tweak the compiler command, to let the compiler explicitly know that it is # receiving C++ source code with the provided .sycl file(s). string( REPLACE "" "/Tp " CMAKE_SYCL_COMPILE_OBJECT @@ -31,10 +40,15 @@ foreach( linker_command "CMAKE_SYCL_CREATE_SHARED_LIBRARY" # Prefix the linker-specific arguments with "/link", to let DPC++ know # that these are to be given to the linker. "/out" just happens to be the - # first linker argument on the command line. (With CMake 3.21.) So this part - # may need to be tweaked in the future. - string( REPLACE "/out" "/link /out" - ${linker_command} "${${linker_command}}" ) + # first linker argument on the command line. (With CMake 3.21.) + # + # Later CMake versions fixed this out of the box, so this is only needed + # if "/link" is missing from the commands. + if( ( NOT "${${linker_command}}" MATCHES "/link" ) AND + ( NOT "${${linker_command}}" MATCHES "-link" ) ) + string( REPLACE "/out" "/link /out" + ${linker_command} "${${linker_command}}" ) + endif() endforeach()