Skip to content

Commit 8eab027

Browse files
committed
Pulled shared/duplicate compiler flags into separate cmake file
1 parent b4a5589 commit 8eab027

3 files changed

Lines changed: 18 additions & 20 deletions

File tree

common/cmake/clang.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ IF (WIN32)
1717
ELSE()
1818
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /GS-") # do not protect against return address overrides
1919
ENDIF()
20+
21+
# Stack protector override for specific files
2022
MACRO(DISABLE_STACK_PROTECTOR_FOR_FILE file)
2123
IF (EMBREE_STACK_PROTECTOR)
2224
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "/GS-")

common/cmake/compiler_base.cmake

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,16 @@ MACRO(APPLY_COMMON_COMPILER_FLAGS)
5050
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2") # perform extra security checks for some standard library calls
5151
ENDMACRO()
5252

53-
# Stack protector configuration
53+
# Stack protector configuration (Unix-only)
5454
MACRO(CONFIGURE_STACK_PROTECTOR)
55-
IF (EMBREE_STACK_PROTECTOR)
56-
IF (WIN32 AND SYCL_ONEAPI_ICX)
57-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS") # protects against return address overrides
58-
ELSEIF (NOT WIN32)
59-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") # protects against return address overrides
60-
ELSEIF (WIN32)
61-
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /GS") # protects against return address overrides
62-
ENDIF()
63-
ELSEIF (WIN32)
64-
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} /GS-") # do not protect against return address overrides
55+
IF (EMBREE_STACK_PROTECTOR AND NOT WIN32)
56+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") # protects against return address overrides
6557
ENDIF()
6658
ENDMACRO()
6759

6860
MACRO(DISABLE_STACK_PROTECTOR_FOR_FILE file)
69-
IF (EMBREE_STACK_PROTECTOR)
70-
IF (SYCL_ONEAPI_ICX AND WIN32)
71-
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "/GS-")
72-
ELSEIF (NOT WIN32)
73-
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
74-
ELSEIF (WIN32)
75-
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "/GS-")
76-
ENDIF()
61+
IF (EMBREE_STACK_PROTECTOR AND NOT WIN32)
62+
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "-fno-stack-protector")
7763
ENDIF()
7864
ENDMACRO()
7965

common/cmake/dpcpp.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,17 @@ IF(SYCL_ONEAPI_ICX)
179179
ENDIF()
180180
ENDIF()
181181

182-
CONFIGURE_STACK_PROTECTOR()
182+
# Stack protector configuration (Windows ICX-specific handling)
183+
IF (WIN32 AND SYCL_ONEAPI_ICX)
184+
IF (EMBREE_STACK_PROTECTOR)
185+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS") # protects against return address overrides
186+
ELSE()
187+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS-") # do not protect against return address overrides
188+
ENDIF()
189+
ELSE()
190+
# Use shared stack protector macro for Unix and other platforms
191+
CONFIGURE_STACK_PROTECTOR()
192+
ENDIF()
183193

184194
IF (SYCL_ONEAPI_ICX AND WIN32)
185195
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise") # makes dpcpp compiler compatible with clang++

0 commit comments

Comments
 (0)