This is an automated email from the ASF dual-hosted git repository.

xiaokang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-graphar.git


The following commit(s) were added to refs/heads/main by this push:
     new 23c46c20 chore(c++): add cmake option `GRAPHAR_ENABLE_SANITIZER` (#818)
23c46c20 is described below

commit 23c46c2090bc59e20334d527ffaadb3f7380425e
Author: Jinye Wu <[email protected]>
AuthorDate: Sun Jan 4 10:31:44 2026 +0800

    chore(c++): add cmake option `GRAPHAR_ENABLE_SANITIZER` (#818)
    
    * add cmake option `GRAPHAR_ENABLE_SANITIZER`
    
    * update
---
 cpp/CMakeLists.txt | 17 ++++++++++++++---
 cpp/README.md      |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 2d4e477b..d3acfb58 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -49,6 +49,7 @@ option(BUILD_DOCS_ONLY "Build docs only" OFF)
 option(USE_STATIC_ARROW "Link arrow static library" OFF)
 option(GRAPHAR_BUILD_STATIC "Build GraphAr as static libraries" OFF)
 option(BUILD_ARROW_FROM_SOURCE "Build Arrow from source" OFF)
+option(GRAPHAR_ENABLE_SANITIZER "Enable address sanitizer (Debug builds only)" 
ON)
 
 if (USE_STATIC_ARROW)
     set(GRAPHAR_BUILD_STATIC ON)
@@ -115,12 +116,22 @@ elseif(UNIX)
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ORIGIN")
 endif ()
 
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g 
-fno-omit-frame-pointer -fsanitize=address")
-set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} 
-fno-omit-frame-pointer -fsanitize=address")
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g 
-fno-omit-frame-pointer")
+if (GRAPHAR_ENABLE_SANITIZER)
+  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
+  # Linker flags are required to pull in the ASan runtime.
+  set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} 
-fsanitize=address")
+  set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} 
-fsanitize=address")
+endif()
 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g")
 
 message(STATUS "[graphar] will build in type: ${CMAKE_BUILD_TYPE}")
 
+string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
+if (CMAKE_BUILD_TYPE_UPPER STREQUAL "DEBUG")
+  message(STATUS "[graphar] GRAPHAR_ENABLE_SANITIZER: 
${GRAPHAR_ENABLE_SANITIZER}")
+endif()
+
 # 
------------------------------------------------------------------------------
 # cmake configs
 # 
------------------------------------------------------------------------------
@@ -630,4 +641,4 @@ add_custom_target(graphar-clformat
 add_custom_target(graphar-cpplint
         COMMAND ${PROJECT_SOURCE_DIR}/misc/cpplint.py 
--root=${PROJECT_SOURCE_DIR}/include ${FILES_NEED_LINT}
         COMMENT "Running cpplint check."
-        VERBATIM)
\ No newline at end of file
+        VERBATIM)
diff --git a/cpp/README.md b/cpp/README.md
index dae16f56..bdc8da6b 100644
--- a/cpp/README.md
+++ b/cpp/README.md
@@ -113,6 +113,7 @@ Extra Build Options:
 
 1. `-DGRAPHAR_BUILD_STATIC=ON`: Build GraphAr as static libraries.
 2. `-DUSE_STATIC_ARROW=ON`: Link arrow static library to build GraphAr. If set 
this option, the option `GRAPHAR_BUILD_STATIC=ON` will be set.
+3. `-DGRAPHAR_ENABLE_SANITIZER=ON|OFF`: Enable AddressSanitizer for Debug 
builds only (default: `ON`).
 
 ### Building with Arrow from source
 In case you want to build GraphAr as single static library including all 
dependencies, we include a [apache-arrow.cmake](cmake/apache-arrow.cmake) file 
that allows you to build Arrow and its dependencies from source and link it 
statically. To do this, you can follow the steps below:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to