[llvm] [SYCL] Add libsycl, a SYCL RT library implementation project (PR #144372)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 06:26:36 PDT 2025
================
@@ -0,0 +1,111 @@
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes/cmake/Modules")
+include(WarningFlags)
+
+function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
+ if (NOT LLVM_ENABLE_PIC)
+ message( FATAL_ERROR "Position-Independent Code generation is required for libsycl shared library" )
+ endif()
+ # Add an optional argument so we can get the library name to
+ # link with for Windows Debug version
+ cmake_parse_arguments(ARG "" "IMPLIB_NAME" "COMPILE_OPTIONS;SOURCES" ${ARGN})
+
+ add_library(${LIB_OBJ_NAME} OBJECT ${ARG_SOURCES})
+
+ # Common compilation step setup
+ target_compile_definitions(${LIB_OBJ_NAME} PRIVATE $<$<BOOL:${MSVC}>:_LIBSYCL_BUILD_SYCL_DLL>)
+ cxx_add_warning_flags(${LIB_OBJ_NAME} ${LIBSYCL_ENABLE_WERROR} ${LIBSYCL_ENABLE_PEDANTIC})
+
+ target_include_directories(
+ ${LIB_OBJ_NAME}
+ PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${LIBSYCL_BUILD_INCLUDE_DIR}
+ )
+
+ add_library(${LIB_NAME} SHARED
+ $<TARGET_OBJECTS:${LIB_OBJ_NAME}>)
+
+ add_dependencies(${LIB_OBJ_NAME}
+ sycl-headers
+ )
+
+ set_target_properties(${LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX)
+
+ if (WIN32)
+ target_link_libraries(${LIB_NAME} PRIVATE shlwapi)
+ if (ARG_IMPLIB_NAME)
+ add_custom_command(
+ TARGET ${LIB_NAME} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy
+ ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${LIB_NAME}.lib ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${ARG_IMPLIB_NAME}.lib
+ COMMENT "Creating version-agnostic copy of the import library.")
+ install(
+ FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${ARG_IMPLIB_NAME}.lib
+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT libsycl)
+ endif()
+ endif()
+
+ if (MSVC)
----------------
KseniyaTikhomirova wrote:
updated in https://github.com/llvm/llvm-project/pull/144372/commits/6e473009602cdf0ce5cb2fb2f4fe27acc60125d2
Basically MSVC & WIN32 are not completely equal. MSVC & WIN32 provide same values for LLVM/Clang &
Microsoft Visual C/C++ Compiler. But MSVC is 0 for GCC (available as MinGW).
In intel/llvm there was PR that introduces the difference in usage of WIn32 and MSVC (mentioned in the previous reply). Although we don't test and don't guarantee it to work.
So I eliminated that difference in this PR and added protection against untested and unsupported usage. This decision can be revisited later.
One more note, I replaced WIN32 check with "CMAKE_SYSTEM_NAME STREQUAL Windows" check due to "soft" deprecation of WIN32: https://discourse.cmake.org/t/platform-id-vs-win32-vs-cmake-system-name/1226
https://github.com/llvm/llvm-project/pull/144372
More information about the llvm-commits
mailing list