forked from codeplaysoftware/syclacademy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
122 lines (102 loc) · 3.98 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#[[
SYCL Academy (c)
SYCL Academy is licensed under a Creative Commons Attribution-ShareAlike 4.0
International License.
You should have received a copy of the license along with this work. If not,
see <http://creativecommons.org/licenses/by-sa/4.0/>.
Invoking CMake from the command line example usage:
cmake .. "-GUnix Makefiles" -DSYCL_ACADEMY_USE_DPCPP=ON
-DSYCL_ACADEMY_ENABLE_SOLUTIONS=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
]]
# Minimum version required by
# /opt/intel/oneapi/compiler/latest/linux/IntelSYCL/ReadMeSYCL.txt
if(WIN32)
cmake_minimum_required(VERSION 3.23...3.27)
else()
cmake_minimum_required(VERSION 3.20...3.27)
endif()
project (SYCLAcademy)
# CMake input options
option(SYCL_ACADEMY_USE_DPCPP "Configure to compile with Intel DPC++" OFF)
option(SYCL_ACADEMY_USE_ADAPTIVECPP "Configure to compile with AdaptiveCpp" OFF)
option(SYCL_ACADEMY_ENABLE_SOLUTIONS "Include solution source files in the project" OFF)
# Variables
set(SYCL_ACADEMY_INSTALL_ROOT CACHE STRING "NOT-FOUND")
set(SYCL_IMPLEMENTATIONS_USED 0)
if(SYCL_ACADEMY_USE_DPCPP)
math(EXPR SYCL_IMPLEMENTATIONS_USED ${SYCL_IMPLEMENTATIONS_USED}+1)
endif()
if(SYCL_ACADEMY_USE_ADAPTIVECPP)
math(EXPR SYCL_IMPLEMENTATIONS_USED ${SYCL_IMPLEMENTATIONS_USED}+1)
endif()
if (${SYCL_IMPLEMENTATIONS_USED} EQUAL 0)
message(FATAL_ERROR "No SYCL implementation specified, please set one of the following "
"SYCL_ACADEMY_USE_ADAPTIVECPP or SYCL_ACADEMY_USE_DPCPP to ON.")
endif()
if (${SYCL_IMPLEMENTATIONS_USED} GREATER 1)
message(FATAL_ERROR "Multiple SYCL implementations specified, please set only one of the following "
"set one of SYCL_ACADEMY_USE_ADAPTIVECPP or SYCL_ACADEMY_USE_DPCPP to ON. ")
endif()
# Common setup
find_package(Threads REQUIRED)
add_subdirectory(Utilities)
# DPC++ setup
if (SYCL_ACADEMY_USE_DPCPP)
if (DEFINED SYCL_TRIPLE)
list(APPEND CMAKE_CXX_FLAGS "-fsycl-targets=${SYCL_TRIPLE}")
endif()
if (DEFINED SYCL_ARCH)
if (${SYCL_TRIPLE} MATCHES spir64_gen)
list(APPEND CMAKE_CXX_FLAGS "-Xs" "\"-device ${SYCL_ARCH}\"")
else()
list(APPEND CMAKE_CXX_FLAGS "-Xsycl-target-backend" "--offload-arch=${SYCL_ARCH}")
endif()
endif()
if (DEFINED ROCM_DIR)
list(APPEND CMAKE_CXX_FLAGS "--rocm-path=${ROCM_DIR}")
endif()
if (DEFINED CUDA_DIR)
list(APPEND CMAKE_CXX_FLAGS "--cuda-path=${CUDA_DIR}")
endif()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if (${CMAKE_CXX_COMPILER} MATCHES icpx)
# For DPCPP module to work, find_package to work, use the options
# -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx on the command line.
find_package(IntelSYCL REQUIRED)
else()
# Open source clang++ doesn't have IntelSYCL cmake module
function(add_sycl_to_target)
set(options)
set(one_value_args TARGET)
set(multi_value_args SOURCES)
cmake_parse_arguments(SYCL
""
"${one_value_args}"
"${multi_value_args}"
${ARGN})
target_compile_options(${SYCL_TARGET} PRIVATE "-fsycl")
target_link_options(${SYCL_TARGET} PRIVATE "-fsycl")
target_link_libraries(${SYCL_TARGET} PUBLIC "libsycl.so")
endfunction()
endif()
endif()
# AdaptiveCpp setup
if (SYCL_ACADEMY_USE_ADAPTIVECPP)
if (NOT SYCL_ACADEMY_INSTALL_ROOT)
message(FATAL_ERROR "SYCL implementation root not provided, please specify "
"the path to the root of the chosen SYCL implementation using "
"SYCL_ACADEMY_INSTALL_ROOT=<path/to/install/root>.")
endif()
set(AdaptiveCpp_DIR ${SYCL_ACADEMY_INSTALL_ROOT}/lib/cmake/AdaptiveCpp)
find_package(AdaptiveCpp CONFIG REQUIRED PATHS)
endif()
# Exercises
enable_testing()
add_subdirectory(External/Catch2)
add_subdirectory(Code_Exercises)
# Create the Image directory
# Set source and destination paths
set(SOURCE_DIR "${CMAKE_SOURCE_DIR}/Code_Exercises/Images/")
set(DESTINATION_DIR "${CMAKE_BINARY_DIR}/Code_Exercises/Images/")
# Copy all files from source to destination using file(COPY ...)
file(COPY ${SOURCE_DIR} DESTINATION ${DESTINATION_DIR})