@@ -88,6 +88,16 @@ if (CMAKE_VERSION VERSION_EQUAL 3.19.1)
88
88
)
89
89
endif ()
90
90
91
+ # SYCL related compile options
92
+ string (CONCAT COMMON_COMPILE_FLAGS
93
+ "-fsycl "
94
+ "-fsycl-device-code-split=per_kernel "
95
+ "-fno-approx-func "
96
+ )
97
+ string (CONCAT COMMON_LINK_FLAGS
98
+ "-fsycl "
99
+ "-fsycl-device-code-split=per_kernel "
100
+ )
91
101
if (UNIX )
92
102
set (CMAKE_CXX_COMPILER "dpcpp" )
93
103
# add_compile_options(-fPIC)
@@ -101,7 +111,14 @@ elseif(WIN32)
101
111
# set(CMAKE_RANLIB "llvm-ranlib")
102
112
# set(CMAKE_CXX_FLAGS "/EHsc")
103
113
104
- add_compile_options (/EHsc ) # /Ox /W3 /GL /DNDEBUG /MD /EHsc
114
+ string (APPEND COMMON_COMPILER_FLAGS
115
+ "/EHsc "
116
+ # "/Ox "
117
+ # "/W3 "
118
+ # "/GL "
119
+ # "/DNDEBUG "
120
+ # "/MD "
121
+ )
105
122
else ()
106
123
message (FATAL_ERROR "Unsupported system ${CMAKE_SYSTEM} in compiler selection case" )
107
124
endif ()
@@ -110,42 +127,61 @@ endif()
110
127
set (CMAKE_CXX_STANDARD 17 )
111
128
set (CMAKE_CXX_STANDARD_REQUIRED ON )
112
129
113
- # SYCL related compile options
114
- add_compile_options (-fsycl )
115
- add_compile_options (-fsycl-device-code-split=per_kernel )
116
- add_compile_options (-fno-approx-func )
117
- add_link_options (-fsycl )
118
- add_link_options (-fsycl-device-code-split=per_kernel )
119
-
120
130
# warning flag set
121
- set (DPNP_WARNING_FLAGS "-W -Wextra -Wshadow -Wall -Wstrict-prototypes" CACHE STRING "set of warning compiler switches" )
122
- add_definitions (${DPNP_WARNING_FLAGS} )
131
+ string (CONCAT DPNP_WARNING_FLAGS
132
+ "-W "
133
+ "-Wextra "
134
+ "-Wshadow "
135
+ "-Wall "
136
+ "-Wstring-prototypes "
137
+ "-Wformat "
138
+ "-Wformat-security "
139
+ )
140
+ string (APPEND COMMON_COMPILER_FLAGS
141
+ "${DPNP_WARNING_FLAGS} "
142
+ )
123
143
124
144
# debug/release compile definitions
125
145
if (DPNP_DEBUG_ENABLE )
126
146
set (CMAKE_BUILD_TYPE "Debug" )
127
- add_compile_options (-O0 )
147
+ string (APPEND COMMON_COMPILER_FLAGS
148
+ "-O0 "
149
+ )
128
150
else ()
129
151
set (CMAKE_BUILD_TYPE "Release" )
130
- add_compile_options (-O3 )
152
+ string (APPEND COMMON_COMPILER_FLAGS
153
+ "-O3 "
154
+ )
131
155
endif ()
132
156
133
157
# -----------------------------------------------------------------------------------------------
134
158
# Auxilary building options...
135
159
# -----------------------------------------------------------------------------------------------
136
160
# sdl
137
- add_definitions (-D_FORTIFY_SOURCE=2 -Wformat -Wformat-security )
161
+ string (CONCAT DPNP_DEFS
162
+ "-D_FORTIFY_SOURCE=2 "
163
+ )
138
164
if (NOT WIN32 )
139
- add_compile_options (-fno-delete-null-pointer-checks -fstack-protector-strong -fno-strict-overflow )
140
- # add_link_options(-static-libstdc++ -static-libgcc)
141
- add_link_options (-Wl,-z,noexecstack,-z,relro,-z,now )
165
+ string (APPEND COMMON_COMPILER_FLAGS
166
+ "-fno-delete-null-pointer-checks "
167
+ "-fstack-protector-strong "
168
+ "-fno-strict-overflow "
169
+ )
170
+ string (APPEND COMMON_LINK_FLAGS
171
+ "LINKER:-z,noexecstack,-z,relro,-z,now "
172
+ )
142
173
endif ()
143
174
144
175
# disable PSTL policies due to compiler bug
145
- add_definitions (-DPSTL_USE_PARALLEL_POLICIES=0 -D_GLIBCXX_USE_TBB_PAR_BACKEND=0 )
176
+ string (APPEND DPNP_DEFS
177
+ "-DPSTL_USE_PARALLEL_POLICIES=0 "
178
+ "-D_GLIBCXX_USE_TBB_PAR_BACKEND=0 "
179
+ )
146
180
147
181
# disable PSTL predefined policies objects (global queues, prevent fail on Windows)
148
- add_definitions (-DONEDPL_USE_PREDEFINED_POLICIES=0 )
182
+ string (APPEND DPNP_DEFS
183
+ "-DONEDPL_USE_PREDEFINED_POLICIES=0 "
184
+ )
149
185
150
186
# -----------------------------------------------------------------------------------------------
151
187
# Create project...
@@ -188,12 +224,20 @@ if(DPNP_STATIC_LIB_ENABLE)
188
224
add_library (dpnp_backend_c STATIC ${DPNP_SRC} )
189
225
else ()
190
226
add_library (dpnp_backend_c SHARED ${DPNP_SRC} )
191
- set ( CMAKE_POSITION_INDEPENDENT_CODE ON ) # looks like this option doesn't work
227
+ set_target_properties ( dpnp_backend_c PROPERTIES CMAKE_POSITION_INDEPENDENT_CODE ON )
192
228
endif ()
193
229
194
230
target_include_directories (dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
195
231
target_include_directories (dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /src )
196
232
233
+ string (REPLACE " " ";" COMMON_COMPILE_FLAGS_AS_LIST ${COMMON_COMPILE_FLAGS} )
234
+ target_compile_options (dpnp_backend_c PUBLIC ${COMMON_COMPILE_FLAGS_AS_LIST} )
235
+ string (REPLACE " " ";" DPNP_DEFS_AS_LIST ${DPNP_DEFS} )
236
+ target_compile_definitions (dpnp_backend_c PUBLIC ${DPNP_DEFS_AS_LIST} )
237
+ string (REPLACE " " ";" COMMON_LINK_FLAGS_AS_LIST ${COMMON_LINK_FLAGS} )
238
+ target_link_options (dpnp_backend_c PUBLIC ${COMMON_LINK_FLAGS_AS_LIST} )
239
+
240
+
197
241
# -----------------------------------------------------------------------------------------------
198
242
# Testing logic...
199
243
# -----------------------------------------------------------------------------------------------
@@ -206,8 +250,9 @@ endif()
206
250
# -----------------------------------------------------------------------------------------------
207
251
# Math library
208
252
find_package (MathLib REQUIRED )
209
- add_definitions ( -DMKL_ILP64=1 )
253
+ target_compile_definitions ( dpnp_backend_c PUBLIC -DMKL_ILP64=1 )
210
254
target_include_directories (dpnp_backend_c PUBLIC ${MATHLIB_INCLUDE_DIR} )
255
+
211
256
link_directories (dpnp_backend_c PUBLIC ${MATHLIB_LIBRARY_DIR} ) # does not work with some cmake versions
212
257
target_link_directories (dpnp_backend_c PUBLIC ${MATHLIB_LIBRARY_DIR} ) # duplicate link_directories
213
258
@@ -260,7 +305,7 @@ if(DPNP_SYCL_QUEUE_MGR_ENABLE)
260
305
# disable stripping rpath in installation logic
261
306
set_target_properties (dpnp_backend_c PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE )
262
307
else ()
263
- add_definitions ( -DDPNP_LOCAL_QUEUE=1 )
308
+ target_compiler_definitions ( dpnp_backend_c PUBLIC -DDPNP_LOCAL_QUEUE=1 )
264
309
endif ()
265
310
266
311
# -----------------------------------------------------------------------------------------------
0 commit comments