Skip to content

Commit

Permalink
chore: More reliable definition of C standard in CMakeLists (#605)
Browse files Browse the repository at this point in the history
Some local update on my local machine resulted in nanoarrow not
compiling because clang gave a warning for the C11 extensions in the
flatcc generated code. I believe this was because the C standard had
already been set to C99 at the beginning of the file, whereas the check
to update it to C11 only happened after this had already been set.
  • Loading branch information
paleolimbot authored Sep 11, 2024
1 parent 75ef830 commit 567748d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
message(STATUS "Building using CMake version: ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.14)

if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()

set(NANOARROW_VERSION "0.6.0-SNAPSHOT")
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" NANOARROW_BASE_VERSION
"${NANOARROW_VERSION}")
Expand Down Expand Up @@ -59,6 +54,18 @@ option(NANOARROW_CODE_COVERAGE "Enable coverage reporting" OFF)
option(NANOARROW_ARROW_STATIC
"Use a statically-linked Arrow C++ build when linking tests" OFF)

if(NOT DEFINED CMAKE_C_STANDARD)
if(NANOARROW_IPC)
# flatcc requires C11 for alignas() and static_assert() in flatcc_generated.h
# It may be possible to use C99 mode to build the runtime and/or generated header
# should this cause problems for users.
set(CMAKE_C_STANDARD 11)
else()
set(CMAKE_C_STANDARD 99)
endif()
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()

if(NANOARROW_NAMESPACE)
set(NANOARROW_NAMESPACE_DEFINE "#define NANOARROW_NAMESPACE ${NANOARROW_NAMESPACE}")
else()
Expand Down Expand Up @@ -150,14 +157,6 @@ target_include_directories(nanoarrow
install(FILES ${NANOARROW_INSTALL_HEADERS} DESTINATION include/nanoarrow)

if(NANOARROW_IPC)
# flatcc requires C11 for alignas() and static_assert() in flatcc_generated.h
# It may be possible to use C99 mode to build the runtime and/or generated header
# should this cause problems for users.
if(NOT DEFINED CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
endif()

# Add the flatcc (runtime) dependency
set(FLATCC_RTONLY
ON
Expand Down

0 comments on commit 567748d

Please sign in to comment.