Skip to content
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libsycl/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
17 changes: 17 additions & 0 deletions libsycl/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Checks: >
-*,
clang-analyzer-*,
clang-diagnostic-*,
cppcoreguidelines-*,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-pro-type-union-access,
google-*,
-google-build-using-namespace,
-google-explicit-constructor,
-google-runtime-references,
misc-*,
-misc-macro-parentheses,
-misc-unused-parameters
123 changes: 123 additions & 0 deletions libsycl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#===============================================================================
# Setup Project
#===============================================================================
cmake_minimum_required(VERSION 3.20.0)

set(LLVM_SUBPROJECT_TITLE "libsycl")

set(LIBSYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBSYCL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)

#===============================================================================
# Setup CMake Options
#===============================================================================

option(LIBSYCL_ENABLE_WERROR "Treat all warnings as errors in the libsycl project" OFF)

#===============================================================================
# Configure System
#===============================================================================

set(LIBSYCL_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING
"Path where libsycl headers should be installed.")

set(LIBSYCL_SHARED_OUTPUT_NAME "sycl" CACHE STRING "Output name for the shared libsycl runtime library.")

if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
set(LIBSYCL_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
if(LIBSYCL_LIBDIR_SUBDIR)
string(APPEND LIBSYCL_TARGET_SUBDIR /${LIBSYCL_LIBDIR_SUBDIR})
endif()
set(LIBSYCL_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBSYCL_TARGET_SUBDIR})
set(LIBSYCL_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBSYCL_TARGET_SUBDIR} CACHE STRING
"Path where built libsycl libraries should be installed.")
unset(LIBSYCL_TARGET_SUBDIR)
else()
if(LLVM_LIBRARY_OUTPUT_INTDIR)
set(LIBSYCL_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
else()
set(LIBSYCL_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBSYCL_LIBDIR_SUFFIX})
endif()
set(LIBSYCL_INSTALL_LIBRARY_DIR lib${LIBSYCL_LIBDIR_SUFFIX} CACHE STRING
"Path where built libsycl libraries should be installed.")
endif()

set(LIBSYCL_INCLUDE_DIR ${LIBSYCL_SOURCE_DIR}/include)
set(LIBSYCL_BUILD_INCLUDE_DIR ${LLVM_BINARY_DIR}/include)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})

# The change in LIBSYCL_MAJOR_VERSION must be accompanied with the same update in
# clang/lib/Driver/CMakeLists.txt.
set(LIBSYCL_MAJOR_VERSION 0)
set(LIBSYCL_MINOR_VERSION 1)
set(LIBSYCL_PATCH_VERSION 0)
set(LIBSYCL_VERSION_STRING "${LIBSYCL_MAJOR_VERSION}.${LIBSYCL_MINOR_VERSION}.${LIBSYCL_PATCH_VERSION}")
set(LIBSYCL_ABI_NAMESPACE "V${LIBSYCL_MAJOR_VERSION}" CACHE STRING
"The inline ABI namespace used by libsycl. It defaults to Vn where `n` is the current ABI version.")

#===============================================================================
# Setup Compiler Flags
#===============================================================================

# Starting CMake 3.26 this property as ON by default. With 3.20+ we still need to set it.
if(MSVC)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for restricting the USE_FOLDERS property to MSVC? Other projects that set this property (llvm, runtimes, compier-rt) don't (some conditionally set it based on a "standalone" build mode).

Copy link
Collaborator

@KseniyaTikhomirova KseniyaTikhomirova Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this option is widely used for a proper project view in VS IDE. it seems to have not much sense to enable it for linux.
BTW even llvm CMakeLists.txt states that they do it specifically for VS (but still unconditionally).
https://github.com/sergey-semenov/llvm-project/blob/main/llvm/CMakeLists.txt#L378


https://cmake.org/cmake/help/latest/prop_gbl/USE_FOLDERS.html
"Not all CMake generators support recording folder details for targets. The Xcode and Visual Studio generators are examples of generators that do. Similarly, not all IDEs support presenting targets using folder hierarchies, even if the CMake generator used provides the necessary information."
https://devblogs.microsoft.com/cppblog/cmake-support-in-visual-studio-targets-view-single-file-compilation-and-cache-generation-settings/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I do agree that this line is a little strange since this option is important for generator and IDE. Why do we have condition with compiler check? I will remove this condition, it should be fine to set it unconditionally.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks. I agree Linux users likely wouldn't benefit from this setting, but Apple Xcode users presumably would.

This seems like one of those settings that should be more centrally managed in LLVM, but addressing that would be far out of scope for this PR.


# Enable all warnings by default
if (MSVC)
append("/W4" CMAKE_CXX_FLAGS)
else ()
append("-Wall -Wextra" CMAKE_CXX_FLAGS)
endif()

if(LIBSYCL_ENABLE_WERROR)
if(MSVC)
append("/WX" CMAKE_CXX_FLAGS)
else()
append("-Werror" CMAKE_CXX_FLAGS)
endif()
endif()

# This is a workaround to detect changes (add or modify) in subtree which
# are not detected by copy_directory command.
file(GLOB_RECURSE HEADERS_IN_SYCL_DIR CONFIGURE_DEPENDS "${LIBSYCL_INCLUDE_DIR}/sycl/*")

string(REPLACE "${LIBSYCL_INCLUDE_DIR}" "${LIBSYCL_BUILD_INCLUDE_DIR}"
OUT_HEADERS_IN_SYCL_DIR "${HEADERS_IN_SYCL_DIR}")

# Copy SYCL headers from sources to build directory
add_custom_target(sycl-headers
DEPENDS ${OUT_HEADERS_IN_SYCL_DIR})

configure_file("${LIBSYCL_SOURCE_DIR}/src/version.hpp.in" "${LIBSYCL_INCLUDE_DIR}/sycl/version.hpp")

add_custom_command(
OUTPUT ${OUT_HEADERS_IN_SYCL_DIR}
DEPENDS ${HEADERS_IN_SYCL_DIR}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBSYCL_INCLUDE_DIR}/sycl ${LIBSYCL_BUILD_INCLUDE_DIR}/sycl
COMMENT "Copying SYCL headers...")

install(DIRECTORY "${LIBSYCL_INCLUDE_DIR}/sycl" DESTINATION ${LIBSYCL_INSTALL_INCLUDE_DIR} COMPONENT sycl-headers)

if (WIN32)
set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME}${LIBSYCL_MAJOR_VERSION})
if (MSVC)
list(APPEND LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME}${LIBSYCL_MAJOR_VERSION}d)
endif()
else()
set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})
endif()

add_subdirectory(src)

add_custom_target(libsycl-runtime-libraries
DEPENDS ${LIBSYCL_RT_LIBS}
)
Loading