Skip to content

Commit 4f9ed25

Browse files
Merge pull request #1164 from IntelPython/cmake-cleanup-master
Cmake cleanup master
2 parents cc098b1 + e3fff8c commit 4f9ed25

File tree

2 files changed

+67
-22
lines changed

2 files changed

+67
-22
lines changed

dpnp/backend/CMakeLists.txt

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ if (CMAKE_VERSION VERSION_EQUAL 3.19.1)
8888
)
8989
endif()
9090

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+
)
91101
if(UNIX)
92102
set(CMAKE_CXX_COMPILER "dpcpp")
93103
# add_compile_options(-fPIC)
@@ -101,7 +111,14 @@ elseif(WIN32)
101111
# set(CMAKE_RANLIB "llvm-ranlib")
102112
# set(CMAKE_CXX_FLAGS "/EHsc")
103113

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+
)
105122
else()
106123
message(FATAL_ERROR "Unsupported system ${CMAKE_SYSTEM} in compiler selection case")
107124
endif()
@@ -110,42 +127,61 @@ endif()
110127
set(CMAKE_CXX_STANDARD 17)
111128
set(CMAKE_CXX_STANDARD_REQUIRED ON)
112129

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-
120130
# 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+
)
123143

124144
# debug/release compile definitions
125145
if(DPNP_DEBUG_ENABLE)
126146
set(CMAKE_BUILD_TYPE "Debug")
127-
add_compile_options(-O0)
147+
string(APPEND COMMON_COMPILER_FLAGS
148+
"-O0 "
149+
)
128150
else()
129151
set(CMAKE_BUILD_TYPE "Release")
130-
add_compile_options(-O3)
152+
string(APPEND COMMON_COMPILER_FLAGS
153+
"-O3 "
154+
)
131155
endif()
132156

133157
# -----------------------------------------------------------------------------------------------
134158
# Auxilary building options...
135159
# -----------------------------------------------------------------------------------------------
136160
# sdl
137-
add_definitions(-D_FORTIFY_SOURCE=2 -Wformat -Wformat-security)
161+
string(CONCAT DPNP_DEFS
162+
"-D_FORTIFY_SOURCE=2 "
163+
)
138164
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+
)
142173
endif()
143174

144175
# 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+
)
146180

147181
# 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+
)
149185

150186
# -----------------------------------------------------------------------------------------------
151187
# Create project...
@@ -188,12 +224,20 @@ if(DPNP_STATIC_LIB_ENABLE)
188224
add_library(dpnp_backend_c STATIC ${DPNP_SRC})
189225
else()
190226
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)
192228
endif()
193229

194230
target_include_directories(dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
195231
target_include_directories(dpnp_backend_c PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
196232

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+
197241
# -----------------------------------------------------------------------------------------------
198242
# Testing logic...
199243
# -----------------------------------------------------------------------------------------------
@@ -206,8 +250,9 @@ endif()
206250
# -----------------------------------------------------------------------------------------------
207251
# Math library
208252
find_package(MathLib REQUIRED)
209-
add_definitions(-DMKL_ILP64=1)
253+
target_compile_definitions(dpnp_backend_c PUBLIC -DMKL_ILP64=1)
210254
target_include_directories(dpnp_backend_c PUBLIC ${MATHLIB_INCLUDE_DIR})
255+
211256
link_directories(dpnp_backend_c PUBLIC ${MATHLIB_LIBRARY_DIR}) # does not work with some cmake versions
212257
target_link_directories(dpnp_backend_c PUBLIC ${MATHLIB_LIBRARY_DIR}) # duplicate link_directories
213258

@@ -260,7 +305,7 @@ if(DPNP_SYCL_QUEUE_MGR_ENABLE)
260305
# disable stripping rpath in installation logic
261306
set_target_properties(dpnp_backend_c PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
262307
else()
263-
add_definitions(-DDPNP_LOCAL_QUEUE=1)
308+
target_compiler_definitions(dpnp_backend_c PUBLIC -DDPNP_LOCAL_QUEUE=1)
264309
endif()
265310

266311
# -----------------------------------------------------------------------------------------------

utils/command_build_clib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
# default variables (for Linux)
6363
_project_compiler = "dpcpp"
6464
_project_linker = "dpcpp"
65-
_project_cmplr_flag_sycl_devel = ["-fsycl-device-code-split=per_kernel"]
65+
_project_cmplr_flag_sycl_devel = ["-fsycl-device-code-split=per_kernel", "-fno-approx-func"]
6666
_project_cmplr_flag_sycl = ["-fsycl"]
6767
_project_cmplr_flag_stdcpp_static = [] # This brakes TBB ["-static-libstdc++", "-static-libgcc"]
6868
_project_cmplr_flag_compatibility = ["-Wl,--enable-new-dtags"]

0 commit comments

Comments
 (0)