|
| 1 | +cmake_minimum_required(VERSION 3.2) |
| 2 | + |
| 3 | +project(sycl-solution) |
| 4 | +# Requirements |
| 5 | +set(CMAKE_CXX_STANDARD 11) |
| 6 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 7 | +set(CMAKE_CXX_EXTENSIONS OFF) |
| 8 | + |
| 9 | +if(MSVC) |
| 10 | + set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 11 | +endif() |
| 12 | + |
| 13 | +# Get clang's version |
| 14 | +include(VersionFromVCS) |
| 15 | +set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") |
| 16 | + |
| 17 | +# If CLANG_VERSION_* is specified, use it, if not use LLVM_VERSION_*. |
| 18 | +if(NOT DEFINED CLANG_VERSION_MAJOR) |
| 19 | + set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) |
| 20 | +endif() |
| 21 | +if(NOT DEFINED CLANG_VERSION_MINOR) |
| 22 | + set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR}) |
| 23 | +endif() |
| 24 | +if(NOT DEFINED CLANG_VERSION_PATCHLEVEL) |
| 25 | + set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) |
| 26 | +endif() |
| 27 | +# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX. |
| 28 | +set(CLANG_VERSION "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}") |
| 29 | + |
| 30 | +set ( LLVM_INST_INC_DIRECTORY "lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include" ) |
| 31 | + |
| 32 | +find_package(OpenCL REQUIRED) |
| 33 | + |
| 34 | +include_directories(${OpenCL_INCLUDE_DIRS}) |
| 35 | +link_libraries(OpenCL) |
| 36 | + |
| 37 | +# Copy SYCL headers |
| 38 | +set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include/CL) |
| 39 | +set(dst_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include/CL) |
| 40 | +add_custom_target(sycl-headers ALL |
| 41 | +COMMAND ${CMAKE_COMMAND} -E copy_directory ${sycl_inc_dir} ${dst_dir} |
| 42 | +COMMENT "Copying SYCL headers ...") |
| 43 | + |
| 44 | +# Main library |
| 45 | + |
| 46 | +set(sourceRootPath "${CMAKE_CURRENT_SOURCE_DIR}/source") |
| 47 | +set(includeRootPath "${CMAKE_CURRENT_SOURCE_DIR}/include") |
| 48 | + |
| 49 | +set(SYCLLibrary sycl) |
| 50 | + |
| 51 | +#To-Do: |
| 52 | +#1. Figure out why CMP0057 has to be set. Should have been taken care of earlier in the build |
| 53 | +#2. Use AddLLVM to modify the build and access config options |
| 54 | +#cmake_policy(SET CMP0057 NEW) |
| 55 | +#include(AddLLVM) |
| 56 | +set(LLVM_BUILD_LIBRARY_DIRS "${LLVM_BINARY_DIR}/lib/") |
| 57 | + |
| 58 | +set(SYCL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 59 | +set(SYCL_TESTS_BINARY_DIR ${SYCL_BINARY_DIR}/test) |
| 60 | + |
| 61 | +set(CLANG_IN_BUILD "${LLVM_BINARY_DIR}/bin/clang") |
| 62 | + |
| 63 | +set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin/") |
| 64 | + |
| 65 | +set(SYCL_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include/") |
| 66 | +set(OPENCL_INCLUDE "${OpenCL_INCLUDE_DIRS}") |
| 67 | + |
| 68 | +add_library("${SYCLLibrary}" SHARED |
| 69 | + "${includeRootPath}/CL/sycl.hpp" |
| 70 | + "${sourceRootPath}/detail/common.cpp" |
| 71 | + "${sourceRootPath}/detail/device_info.cpp" |
| 72 | + "${sourceRootPath}/detail/event_impl.cpp" |
| 73 | + "${sourceRootPath}/detail/force_device.cpp" |
| 74 | + "${sourceRootPath}/detail/helpers.cpp" |
| 75 | + "${sourceRootPath}/detail/kernel_impl.cpp" |
| 76 | + "${sourceRootPath}/detail/kernel_info.cpp" |
| 77 | + "${sourceRootPath}/detail/platform_host.cpp" |
| 78 | + "${sourceRootPath}/detail/platform_opencl.cpp" |
| 79 | + "${sourceRootPath}/detail/platform_info.cpp" |
| 80 | + "${sourceRootPath}/detail/program_impl.cpp" |
| 81 | + "${sourceRootPath}/detail/program_manager/program_manager.cpp" |
| 82 | + "${sourceRootPath}/detail/queue_impl.cpp" |
| 83 | + "${sourceRootPath}/detail/scheduler/commands.cpp" |
| 84 | + "${sourceRootPath}/detail/scheduler/printers.cpp" |
| 85 | + "${sourceRootPath}/detail/scheduler/scheduler.cpp" |
| 86 | + "${sourceRootPath}/context.cpp" |
| 87 | + "${sourceRootPath}/device.cpp" |
| 88 | + "${sourceRootPath}/device_selector.cpp" |
| 89 | + "${sourceRootPath}/event.cpp" |
| 90 | + "${sourceRootPath}/exception.cpp" |
| 91 | + "${sourceRootPath}/kernel.cpp" |
| 92 | + "${sourceRootPath}/platform.cpp" |
| 93 | + "${sourceRootPath}/queue.cpp" |
| 94 | + "${sourceRootPath}/spirv_ops.cpp" |
| 95 | +) |
| 96 | + |
| 97 | +include_directories("${SYCLLibrary}" "${includeRootPath}") |
| 98 | + |
| 99 | +target_link_libraries("${SYCLLibrary}" "${OpenCL_LIBRARIES}") |
| 100 | +set_target_properties("${SYCLLibrary}" PROPERTIES LINKER_LANGUAGE CXX) |
| 101 | + |
| 102 | +# Workaround for bug in GCC version 5. |
| 103 | +# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899 |
| 104 | +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND |
| 105 | + CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 AND |
| 106 | + CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) |
| 107 | + target_link_libraries("${SYCLLibrary}" gcc_s gcc) |
| 108 | +endif() |
| 109 | + |
| 110 | +install(TARGETS "${SYCLLibrary}" DESTINATION "lib" COMPONENT ${SYCLLibrary}) |
| 111 | +install(DIRECTORY "${includeRootPath}/." DESTINATION "${LLVM_INST_INC_DIRECTORY}" COMPONENT sycl_headers) |
| 112 | + |
| 113 | +add_subdirectory( test ) |
| 114 | +add_subdirectory( tools ) |
| 115 | + |
| 116 | +set(manifest_list) |
| 117 | +set( DEPLOY_LIST |
| 118 | + sycl |
| 119 | + ocl_lib |
| 120 | + ocl_headers |
| 121 | + sycl_headers |
| 122 | + clang |
| 123 | + clang-offload-wrapper |
| 124 | + clang-offload-bundler |
| 125 | + llc |
| 126 | + llvm-as |
| 127 | + llvm-dis |
| 128 | + llvm-spirv |
| 129 | + llvm-link |
| 130 | + opt |
| 131 | +) |
| 132 | + |
| 133 | +foreach( comp ${DEPLOY_LIST} ) |
| 134 | + |
| 135 | + message( STATUS "Adding component ${comp} to deploy") |
| 136 | + |
| 137 | + set (manifest ${CMAKE_CURRENT_BINARY_DIR}/install_manifest_${comp}.txt) |
| 138 | + add_custom_command(OUTPUT ${manifest} |
| 139 | + COMMAND "${CMAKE_COMMAND}" |
| 140 | + "-DCMAKE_INSTALL_COMPONENT=${comp}" |
| 141 | + -P "${CMAKE_BINARY_DIR}/cmake_install.cmake" |
| 142 | + COMMENT "Deploying component ${comp}" |
| 143 | + USES_TERMINAL) |
| 144 | + list(APPEND manifest_list ${manifest}) |
| 145 | +endforeach( comp ) |
| 146 | + |
| 147 | +add_custom_target(deploy DEPENDS ${manifest_list}) |
0 commit comments