Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1baac0

Browse files
authored
Change -Werror handling. (#293)
* If building level_zero as a subproject, do not build with warnings as errors, leave it up to the parent project to turn these into errors if desired. * If building level_zero with CMake 3.24 or newer, use CMAKE_COMPILE_WARNING_AS_ERROR instead of explicitly setting -Werror. This permits users to turn it off with `cmake --compile-no-warning-as-error`. In both cases, being able to disable -Werror is useful when a parent project or a user wishes to turn on additional warnings that should not be turned into errors. Signed-off-by: Harald van Dijk <[email protected]>
1 parent f892d80 commit d1baac0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ if(NOT MSVC)
121121
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
122122
endif()
123123
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM)
124-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wnon-virtual-dtor")
124+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor")
125125
endif()
126126
endif()
127127

@@ -186,6 +186,18 @@ if(USE_ASAN)
186186
endif()
187187
endif()
188188

189+
# Enable -Werror only if not building as a subproject. For subprojects, leave
190+
# this up to the parent project.
191+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
192+
if(CMAKE_VERSION VERSION_LESS 3.24)
193+
if(NOT MSVC)
194+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
195+
endif()
196+
else()
197+
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
198+
endif()
199+
endif()
200+
189201
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
190202
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source/wrapper/include)
191203

0 commit comments

Comments
 (0)