Skip to content

Commit 18727b3

Browse files
Ensure Cython files are built with security flags like before
1 parent 771af53 commit 18727b3

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

dpctl/CMakeLists.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,68 @@ find_package(PythonExtensions REQUIRED)
33
find_package(NumPy REQUIRED)
44
find_package(Cython REQUIRED)
55

6+
if(WIN32)
7+
string(CONCAT WARNING_FLAGS
8+
"-Wall "
9+
"-Wextra "
10+
"-Winit-self "
11+
"-Wunused-function "
12+
"-Wuninitialized "
13+
"-Wmissing-declarations "
14+
)
15+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox ${WARNING_FLAGS}")
16+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox ${WARNING_FLAGS}")
17+
set(CMAKE_C_FLAGS_DEBUG
18+
"${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
19+
)
20+
set(CMAKE_CXX_FLAGS_DEBUG
21+
"${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
22+
)
23+
set(DPCTL_LDFLAGS "/NXCompat /DynamicBase")
24+
elseif(UNIX)
25+
string(CONCAT WARNING_FLAGS
26+
"-Wall "
27+
"-Wextra "
28+
"-Winit-self "
29+
"-Wunused-function "
30+
"-Wuninitialized "
31+
"-Wmissing-declarations "
32+
"-fdiagnostics-color=auto "
33+
"-Wno-deprecated-declarations "
34+
)
35+
string(CONCAT SDL_FLAGS
36+
"-fstack-protector "
37+
"-fstack-protector-all "
38+
"-fpic "
39+
"-fPIC "
40+
"-D_FORTIFY_SOURCE=2 "
41+
"-Wformat "
42+
"-Wformat-security "
43+
"-fno-strict-overflow "
44+
"-fno-delete-null-pointer-checks "
45+
)
46+
string(CONCAT CFLAGS
47+
"${WARNING_FLAGS}"
48+
"${SDL_FLAGS}"
49+
)
50+
string(CONCAT CXXFLAGS
51+
"${WARNING_FLAGS}"
52+
"${SDL_FLAGS}"
53+
"-fsycl "
54+
)
55+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 ${CFLAGS}")
56+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 ${CXXFLAGS}")
57+
set(CMAKE_C_FLAGS_DEBUG
58+
"${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG"
59+
)
60+
set(CMAKE_CXX_FLAGS_DEBUG
61+
"${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG"
62+
)
63+
set(DPCTL_LDFLAGS "-z,noexecstack,-z,relro,-z,now")
64+
else()
65+
message(FATAL_ERROR "Unsupported system.")
66+
endif()
67+
668
# at build time create include/ directory and copy header files over
769
set(DPCTL_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
870
add_custom_target(_build_time_create_dpctl_include ALL
@@ -21,6 +83,7 @@ function(build_dpctl_ext _trgt _src _dest)
2183
target_include_directories(${_trgt} PRIVATE ${NumPy_INCLUDE_DIR} ${DPCTL_INCLUDE_DIR})
2284
add_dependencies(${_trgt} _build_time_create_dpctl_include)
2385
target_link_libraries(${_trgt} DPCTLSyclInterface)
86+
target_link_options(${_trgt} PRIVATE "LINKER:${DPCTL_LDFLAGS}")
2487
python_extension_module(${_trgt})
2588
get_filename_component(_name_wle ${_generated_src} NAME_WLE)
2689
get_filename_component(_generated_src_dir ${_generated_src} DIRECTORY)

0 commit comments

Comments
 (0)