[llvm] [SYCL] Add libsycl, a SYCL RT library implementation project (PR #144372)
Tom Honermann via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 11 09:07:21 PDT 2025
================
@@ -0,0 +1,94 @@
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes/cmake/Modules")
+include(WarningFlags)
+
+function(add_sycl_rt_library LIB_TARGET_NAME LIB_OBJ_NAME LIB_OUTPUT_NAME)
+ if (NOT LLVM_ENABLE_PIC)
+ message( FATAL_ERROR "Position-Independent Code generation is required for libsycl shared library" )
+ endif()
+
+ cmake_parse_arguments(ARG "" "" "COMPILE_OPTIONS;SOURCES" ${ARGN})
+
+ add_library(${LIB_OBJ_NAME} OBJECT ${ARG_SOURCES})
+
+ # Common compilation step setup
+ target_compile_definitions(${LIB_OBJ_NAME} PRIVATE
+ $<$<STREQUAL:${CMAKE_SYSTEM_NAME},Windows>:_LIBSYCL_BUILDING_LIBRARY>)
+ 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_TARGET_NAME} SHARED
+ $<TARGET_OBJECTS:${LIB_OBJ_NAME}>)
+
+ add_dependencies(${LIB_OBJ_NAME}
+ sycl-headers
+ )
+
+ set_target_properties(${LIB_TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX)
+
+ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
+ # Install stripped PDB
+ set(PDB_FILENAME "${LIB_TARGET_NAME}$<$<CONFIG:Debug>:d>")
+ check_linker_flag(CXX "LINKER:/PDBSTRIPPED:${PDB_FILENAME}.stripped.pdb"
+ LINKER_SUPPORTS_PDBSTRIPPED)
+ if(LINKER_SUPPORTS_PDBSTRIPPED)
+ target_link_options(${LIB_TARGET_NAME}
+ PRIVATE "LINKER:/PDBSTRIPPED:${PDB_FILENAME}.stripped.pdb")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PDB_FILENAME}.stripped.pdb"
+ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+ RENAME "${PDB_FILENAME}.pdb"
+ COMPONENT ${LIB_TARGET_NAME}
+ OPTIONAL)
+ endif()
+
+ target_compile_options(${LIB_OBJ_NAME} PUBLIC /EHsc)
+ else()
+ target_compile_options(${LIB_OBJ_NAME} PUBLIC
+ -fvisibility=hidden -fvisibility-inlines-hidden)
+
+ if (UNIX AND NOT APPLE)
+ set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
+ target_link_libraries(
+ ${LIB_TARGET_NAME} PRIVATE "-Wl,--version-script=${linker_script}")
+ set_target_properties(${LIB_TARGET_NAME} PROPERTIES LINK_DEPENDS ${linker_script})
+ endif()
+ endif()
+
+ find_package(Threads REQUIRED)
+
+ target_link_libraries(${LIB_TARGET_NAME}
+ PRIVATE
+ ${CMAKE_DL_LIBS}
+ ${CMAKE_THREAD_LIBS_INIT}
+ )
+
+ set_target_properties(${LIB_TARGET_NAME} PROPERTIES
+ VERSION ${LIBSYCL_VERSION_STRING}
+ SOVERSION ${LIBSYCL_VERSION_STRING})
+ set_target_properties(${LIB_TARGET_NAME} PROPERTIES OUTPUT_NAME ${LIB_OUTPUT_NAME})
+endfunction(add_sycl_rt_library)
+
+set(LIBSYCL_SOURCES
+ "platform.cpp"
+)
+
+set(LIB_NAME "sycl")
+set(LIB_OUTPUT_NAME "${LIB_NAME}")
+if (CMAKE_SYSTEM_NAME STREQUAL Windows)
+ if (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_MSVC_RUNTIME_LIBRARY STREQUAL MultiThreadedDebugDLL)
----------------
tahonermann wrote:
Thanks, I forgot that the DLL variants are always multi-threaded.
Hmm, CMake doesn't seem to acknowledge the existence of the single-threaded static CRT library (other than to disable automatically linking with it for at least some targets; https://github.com/Kitware/CMake/blob/master/Modules/Platform/Windows-MSVC.cmake#L203-L205).
The intent is that the "d" suffix is appended if, and only if, the target is linked with a debug version of the MSVC CRT, correct? I had a different understanding of the intent in earlier comments which is why my last suggestion limited appending the "d" suffix to debug builds.
You previously stated:
> MultiThreadedDebugDLL is the only option that is supported for sycl in Debug mode.
If the intent is that debug builds of libsycl are always required to link with the (multi-threaded) debug (DLL) variant of the MSVC CRT, then I think a change is warranted to assert that. However, inline with my previous statement about the intent being that "d" is only appended when linking with a debug MSVC CRT variant, then debug builds of libsycl may link with the (multi-threaded) release (DLL) variant of the MSVC CRT. In that case, the code is fine as is.
I still have a slight preference for just checking for a match of "Debug" since I think that best expresses the intent and is consistent with libc++, but I acknowledge that it doesn't change the result. So, your choice how you want to handle this.
https://github.com/llvm/llvm-project/pull/144372
More information about the llvm-commits
mailing list