| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # Compiler flags for SmartBotic
- # Warning flags
- if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
- add_compile_options(
- -Wall
- -Wextra
- -Wpedantic
- -Wno-unused-parameter
- -Wno-missing-field-initializers
- )
- # Debug flags
- if(CMAKE_BUILD_TYPE STREQUAL "Debug")
- add_compile_options(-g -O0 -DDEBUG)
- # Note: _GLIBCXX_DEBUG is disabled because it causes ABI incompatibility
- # with pre-compiled system libraries (gRPC, etc.)
- # add_compile_definitions(_GLIBCXX_DEBUG)
- endif()
- # Release flags
- if(CMAKE_BUILD_TYPE STREQUAL "Release")
- add_compile_options(-O3 -DNDEBUG)
- add_compile_options(-flto)
- add_link_options(-flto)
- endif()
- # RelWithDebInfo flags
- if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
- add_compile_options(-O2 -g -DNDEBUG)
- endif()
- endif()
- # MSVC flags (for potential Windows support)
- if(MSVC)
- add_compile_options(/W4 /permissive-)
- add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
- if(CMAKE_BUILD_TYPE STREQUAL "Debug")
- add_compile_options(/Od /Zi)
- else()
- add_compile_options(/O2)
- endif()
- endif()
- # Enable colored output
- if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
- add_compile_options(-fdiagnostics-color=always)
- elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- add_compile_options(-fcolor-diagnostics)
- endif()
- # Position independent code
- set(CMAKE_POSITION_INDEPENDENT_CODE ON)
- # Address Sanitizer. CLAUDE.md documents
- # cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON ..
- # as how to build this project with ASAN - this option is what makes that
- # command actually do it, rather than silently produce an ordinary
- # non-sanitized build (which is exactly what happened before this option
- # existed: the flag was documented but had no matching cmake option, so it
- # was ignored with no error). -fno-omit-frame-pointer keeps ASAN's stack
- # traces readable; leak detection rides along with ASAN on Linux/macOS
- # rather than needing -fsanitize=leak separately.
- option(ENABLE_ASAN "Build with AddressSanitizer (and leak detection) enabled" OFF)
- if(ENABLE_ASAN)
- if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
- add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
- add_link_options(-fsanitize=address)
- else()
- message(WARNING "ENABLE_ASAN was requested but the compiler (${CMAKE_CXX_COMPILER_ID}) "
- "is not GNU or Clang; AddressSanitizer was not enabled")
- endif()
- endif()
|