1
1
cmake_minimum_required (VERSION 3.10 FATAL_ERROR )
2
- project ("dpctl C API - A C wrapper for a subset of SYCL" )
3
2
3
+ # Load our CMake modules to search for DPCPP and Level Zero
4
+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/modules/" )
5
+ find_package (Git REQUIRED )
6
+ include (GetProjectVersion )
7
+ # the get_version function is defined in the GetProjectVersion module and
8
+ # defines: VERSION, SEMVER, MAJOR, MINOR, PATCH. These variables are populated
9
+ # by parsing the output of git describe.
10
+ get_version ()
11
+ project (
12
+ "libDPCTLSYCLInterface"
13
+ DESCRIPTION "A C API for a subset of SYCL"
14
+ )
15
+
16
+ option (DPCTL_CUSTOM_DPCPP_INSTALL_DIR
17
+ "Use a custom version of DPCPP installed at the provided location."
18
+ OFF
19
+ )
4
20
# Option to turn on support for creating Level Zero interoperability programs
5
21
# from a SPIR-V binary file.
6
22
option (DPCTL_ENABLE_LO_PROGRAM_CREATION
@@ -23,40 +39,82 @@ option(DPCTL_BUILD_CAPI_TESTS
23
39
OFF
24
40
)
25
41
26
- # Load our CMake modules to search for DPCPP and Level Zero
27
- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/modules/" )
28
- find_package (DPCPP 2021.2.0 REQUIRED )
42
+ # Minimum version requirement only when oneAPI dpcpp is used.
43
+ if (DPCTL_CUSTOM_DPCPP_INSTALL_DIR )
44
+ find_package (IntelSycl REQUIRED )
45
+ else ()
46
+ find_package (IntelSycl 2021.2.0 REQUIRED )
47
+ endif ()
29
48
30
49
if (DPCTL_ENABLE_LO_PROGRAM_CREATION )
31
50
set (DPCTL_ENABLE_LO_PROGRAM_CREATION 1 )
32
- find_package (LevelZero REQUIRED )
51
+ include (GetLevelZeroHeaders )
52
+ get_level_zero_headers ()
33
53
endif ()
34
54
35
- configure_file (${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h.in
36
- ${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h )
55
+ configure_file (
56
+ ${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h.in
57
+ ${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h
58
+ )
59
+
60
+ # Set the C++ standard to C++17
61
+ set (CMAKE_CXX_STANDARD 17 )
37
62
38
63
if (WIN32 )
39
- set (CMAKE_CXX_COMPILER :PATH "${DPCPP_ROOT} /bin/dpcpp" )
40
- set (CMAKE_C_COMPILER :PATH "${DPCPP_ROOT} /bin/clang-cl" )
41
- set (CMAKE_LINKER:PATH "${DPCPP_ROOT} /bin/lld-link" )
42
- message (STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER} )
43
- message (STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER} )
44
- message (STATUS "Resetting Linker to: " ${CMAKE_LINKER} )
45
- set (WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations" )
64
+ string (CONCAT WARNING_FLAGS
65
+ "-Wall "
66
+ "-Wextra "
67
+ "-Winit-self "
68
+ "-Wunused-function "
69
+ "-Wuninitialized "
70
+ "-Wmissing-declarations "
71
+ )
46
72
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} " )
47
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17" )
48
- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" )
49
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17" )
73
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} " )
74
+ set (CMAKE_C_FLAGS_DEBUG
75
+ "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
76
+ )
77
+ set (CMAKE_CXX_FLAGS_DEBUG
78
+ "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
79
+ )
50
80
elseif (UNIX )
51
- set (CMAKE_CXX_COMPILER :PATH "${DPCPP_ROOT} /bin/dpcpp" )
52
- set (CMAKE_C_COMPILER :PATH "${DPCPP_ROOT} /bin/clang" )
53
- set (CMAKE_LINKER:PATH "${DPCPP_ROOT} /bin/lld" )
54
- set (SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks" )
55
- set (WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto" )
56
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} " )
57
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl" )
58
- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" )
59
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl" )
81
+ string (CONCAT WARNING_FLAGS
82
+ "-Wall "
83
+ "-Wextra "
84
+ "-Winit-self "
85
+ "-Wunused-function "
86
+ "-Wuninitialized "
87
+ "-Wmissing-declarations "
88
+ "-fdiagnostics-color=auto "
89
+ )
90
+ string (CONCAT SDL_FLAGS
91
+ "-fstack-protector "
92
+ "-fstack-protector-all "
93
+ "-fpic "
94
+ "-fPIC "
95
+ "-D_FORTIFY_SOURCE=2 "
96
+ "-Wformat "
97
+ "-Wformat-security "
98
+ "-fno-strict-overflow "
99
+ "-fno-delete-null-pointer-checks "
100
+ )
101
+ string (CONCAT CFLAGS
102
+ "${WARNING_FLAGS} "
103
+ "${SDL_FLAGS} "
104
+ )
105
+ string (CONCAT CXXFLAGS
106
+ "${WARNING_FLAGS} "
107
+ "${SDL_FLAGS} "
108
+ "-fsycl "
109
+ )
110
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS} " )
111
+ set (CMAKE_CXX_FLAGS "${CXXFLAGS} " )
112
+ set (CMAKE_C_FLAGS_DEBUG
113
+ "${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG"
114
+ )
115
+ set (CMAKE_CXX_FLAGS_DEBUG
116
+ "${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG"
117
+ )
60
118
else ()
61
119
message (FATAL_ERROR "Unsupported system." )
62
120
endif ()
@@ -85,31 +143,30 @@ target_include_directories(DPCTLSyclInterface
85
143
PRIVATE
86
144
${CMAKE_SOURCE_DIR} /include/
87
145
${CMAKE_SOURCE_DIR} /helper/include/
88
- ${DPCPP_SYCL_INCLUDE_DIR }
146
+ ${IntelSycl_SYCL_INCLUDE_DIR }
89
147
)
90
148
91
149
target_link_libraries (DPCTLSyclInterface
92
- PRIVATE ${DPCPP_SYCL_LIBRARY }
93
- PRIVATE ${DPCPP_OPENCL_LIBRARY }
150
+ PRIVATE ${IntelSycl_SYCL_LIBRARY }
151
+ PRIVATE ${IntelSycl_OPENCL_LIBRARY }
94
152
)
95
153
96
154
if (DPCTL_ENABLE_LO_PROGRAM_CREATION )
97
- if (UNIX )
98
- target_include_directories (DPCTLSyclInterface
99
- PRIVATE
100
- ${LEVEL_ZERO_INCLUDE_DIR}
101
- )
102
- else ()
103
- message (WARNING
104
- "DPCTL support Level Zero program creation not supported "
105
- "on this system."
106
- )
107
- endif ()
155
+ target_include_directories (DPCTLSyclInterface
156
+ PRIVATE
157
+ ${LEVEL_ZERO_INCLUDE_DIR}
158
+ )
108
159
endif ()
109
160
110
- install (
111
- TARGETS DPCTLSyclInterface
112
- LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} /lib/
161
+ # NOTE: Till we hit 1.0.0 we will keep using the MINOR version to set the API
162
+ # version of the library.
163
+ set_target_properties (DPCTLSyclInterface PROPERTIES VERSION ${VERSION_MINOR} )
164
+ set_target_properties (DPCTLSyclInterface PROPERTIES SOVERSION 1 )
165
+
166
+ install (TARGETS
167
+ DPCTLSyclInterface
168
+ LIBRARY
169
+ DESTINATION ${CMAKE_INSTALL_PREFIX} /lib/
113
170
)
114
171
115
172
# Install all headers
@@ -132,16 +189,14 @@ endforeach()
132
189
133
190
# Enable code coverage related settings
134
191
if (DPCTL_GENERATE_COVERAGE )
135
- # check if llvm-cov and lcov are available
192
+ # check if lcov is available
136
193
find_package (Lcov REQUIRED )
137
- # These flags are set inside FindDPCPP
138
- if (NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND} ))
139
- message (FATAL_ERROR
140
- "llvm-cov and llvm-profdata are needed to generate coverage."
141
- )
142
- endif ()
194
+ # check if llvm-cov version 11 is available
195
+ find_package (LLVMCov 11 REQUIRED )
196
+ # check if llvm-profdata is available
197
+ find_package (LLVMProfdata REQUIRED )
143
198
# Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
144
- # coverage reports
199
+ # coverage reports.
145
200
set (DPCTL_BUILD_CAPI_TESTS "ON" )
146
201
if (DPCTL_COVERAGE_REPORT_OUTPUT_DIR )
147
202
set (COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR} )
0 commit comments