Skip to content

Commit f4f6359

Browse files
authored
build: scope warnings-as-error to project targets, not FetchContent subprojects (#819)
## What Fixes #246. `-Werror` (via a global `CMAKE_COMPILE_WARNING_AS_ERROR`) leaked into FetchContent-built dependencies, so a warning in a third-party subproject (e.g. Arrow) could fail the whole build. As noted on the issue, the global flag does not reliably isolate subprojects. ## How - Removed the global `CMAKE_COMPILE_WARNING_AS_ERROR ON`. - Set `COMPILE_WARNING_AS_ERROR ON` as a per-target property on Iceberg's own shared/static libraries, so the project stays strict. - Set `BUILD_WARNING_LEVEL PRODUCTION` for Arrow to suppress its independent `-Werror` injection. - Kept a defensive guard in `prepare_fetchcontent()` for the case where `-DCMAKE_COMPILE_WARNING_AS_ERROR=ON` is passed on the command line. ## Verified Iceberg targets still compile with `-Werror`; FetchContent subprojects do not. Build + tests green (18/18). --- This contribution was authored with assistance from Claude Opus 4.8, in line with the Iceberg guidelines for AI-assisted contributions (https://iceberg.apache.org/contribute/#guidelines-for-ai-assisted-contributions). All changes were reviewed and tested by the author.
1 parent 5d31dee commit f4f6359

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ set(CMAKE_CXX_STANDARD 23)
3737
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3838
set(CMAKE_CXX_EXTENSIONS OFF)
3939
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
40-
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
41-
4240
option(ICEBERG_BUILD_STATIC "Build static library" ON)
4341
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
4442
option(ICEBERG_BUILD_TESTS "Build tests" ON)

cmake_modules/IcebergBuildUtils.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function(add_iceberg_lib LIB_NAME)
113113

114114
if(BUILD_SHARED)
115115
add_library(${LIB_NAME}_shared SHARED)
116+
set_target_properties(${LIB_NAME}_shared PROPERTIES COMPILE_WARNING_AS_ERROR ON)
116117

117118
if(LIB_DEPS)
118119
target_sources(${LIB_NAME}_shared PRIVATE ${LIB_DEPS})
@@ -172,6 +173,7 @@ function(add_iceberg_lib LIB_NAME)
172173

173174
if(BUILD_STATIC)
174175
add_library(${LIB_NAME}_static STATIC)
176+
set_target_properties(${LIB_NAME}_static PROPERTIES COMPILE_WARNING_AS_ERROR ON)
175177

176178
if(LIB_DEPS)
177179
target_sources(${LIB_NAME}_static PRIVATE ${LIB_DEPS})

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ endmacro()
151151
function(resolve_arrow_dependency)
152152
prepare_fetchcontent()
153153

154+
# Prevent Arrow from injecting -Werror into CMAKE_CXX_FLAGS_DEBUG via
155+
# arrow_add_werror_if_debug(). PRODUCTION level only adds standard warnings.
156+
set(BUILD_WARNING_LEVEL PRODUCTION)
157+
154158
set(ARROW_BUILD_SHARED OFF)
155159
set(ARROW_BUILD_STATIC ON)
156160
# Work around undefined symbol: arrow::ipc::ReadSchema(arrow::io::InputStream*, arrow::ipc::DictionaryMemo*)

src/iceberg/test/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
set(CMAKE_COMPILE_WARNING_AS_ERROR FALSE)
19-
2018
set(INSTALL_GTEST
2119
OFF
2220
CACHE BOOL "" FORCE)

0 commit comments

Comments
 (0)