Browse Source

Meta: Enable ASan and UBSan, disable warnings in vendor directory

(address sanitizer, undefined behavior sanitizer)
master
Riyyi 2 months ago
parent
commit
3ae6ecae8a
  1. 26
      CMakeLists.txt
  2. 1
      example/CMakeLists.txt
  3. 1
      src/CMakeLists.txt
  4. 1
      vendor/CMakeLists.txt

26
CMakeLists.txt

@ -11,6 +11,7 @@ endif()
# Options # Options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(INFERNO_BUILD_EXAMPLES "Build the Inferno example programs" ${INFERNO_STANDALONE}) option(INFERNO_BUILD_EXAMPLES "Build the Inferno example programs" ${INFERNO_STANDALONE})
option(INFERNO_BUILD_WARNINGS "Build with warnings enabled" ${INFERNO_STANDALONE})
# ------------------------------------------ # ------------------------------------------
@ -25,10 +26,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
# Compiler flags used for all build types # Compiler flags used for all build types
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") set(COMPILE_FLAGS_DEPS -w)
if(INFERNO_BUILD_WARNINGS)
set(COMPILE_FLAGS_PROJECT -Wall -Wextra -Wpedantic)
# -Wall = All warnings about contructions that are easily avoidable # -Wall = All warnings about contructions that are easily avoidable
# -Wextra = Extra warning flags not covered by -Wall # -Wextra = Extra warning flags not covered by -Wall
# -Wpedantic = Warnings for compiler extensions not part of the standard # -Wpedantic = Warnings for compiler extensions not part of the standard
else()
set(COMPILE_FLAGS_PROJECT ${COMPILE_FLAGS_DEPS})
endif()
# Set default build type if not specified # Set default build type if not specified
set(DEFAULT_BUILD_TYPE Release) set(DEFAULT_BUILD_TYPE Release)
@ -42,14 +48,20 @@ endif()
# Set build type specific compiler flags # Set build type specific compiler flags
message("--- ${CMAKE_BUILD_TYPE} ---") message("--- ${CMAKE_BUILD_TYPE} ---")
if(${CMAKE_BUILD_TYPE} STREQUAL Debug) if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g -pg") # Optimizations that do not interfere with debugging
# -Og = Optimizations that do not interfere with debugging string(APPEND CMAKE_CXX_FLAGS_DEBUG " -Og")
# -g = Produce debugging information in OS's native format # Produce debugging information in OS's native format
# -pg = Generate profile information for analysis with gprof string(APPEND CMAKE_CXX_FLAGS_DEBUG " -g")
# Generate profile information for analysis with gprof
# $ gprof <PROJECT> gmon.out > profile-data.txt # $ gprof <PROJECT> gmon.out > profile-data.txt
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -pg")
# Enable ASan (Address Sanitizer) and UBSan (Undefined Behavior Sanitizer)
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fsanitize=address,undefined")
# Do not omit frame pointer, which helps with debugging.
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -fno-omit-frame-pointer")
elseif(${CMAKE_BUILD_TYPE} STREQUAL Release) elseif(${CMAKE_BUILD_TYPE} STREQUAL Release)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") # Optimizations that increase compilation time and performance
# -O3 = Optimizations that increase compilation time and performance string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3")
endif() endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

1
example/CMakeLists.txt

@ -15,6 +15,7 @@ add_executable(${GAME} ${GAME_SOURCES})
target_include_directories(${GAME} PRIVATE target_include_directories(${GAME} PRIVATE
"src") "src")
target_link_libraries(${GAME} ${ENGINE}) target_link_libraries(${GAME} ${ENGINE})
target_compile_options(${GAME} PRIVATE ${COMPILE_FLAGS_PROJECT})
target_precompile_headers(${GAME} REUSE_FROM ${ENGINE}) target_precompile_headers(${GAME} REUSE_FROM ${ENGINE})

1
src/CMakeLists.txt

@ -10,6 +10,7 @@ target_include_directories(${ENGINE} PUBLIC
"../vendor/sol2/include" "../vendor/sol2/include"
"../vendor/stb") "../vendor/stb")
target_link_libraries(${ENGINE} ${ENGINE}-dependencies) target_link_libraries(${ENGINE} ${ENGINE}-dependencies)
target_compile_options(${ENGINE} PRIVATE ${COMPILE_FLAGS_PROJECT})
# ------------------------------------------ # ------------------------------------------

1
vendor/CMakeLists.txt vendored

@ -33,3 +33,4 @@ target_include_directories(${ENGINE}-dependencies PUBLIC
"glad/include" "glad/include"
"lua") "lua")
target_link_libraries(${ENGINE}-dependencies glfw ruc ruc-test assimp) target_link_libraries(${ENGINE}-dependencies glfw ruc ruc-test assimp)
target_compile_options(${ENGINE}-dependencies PRIVATE ${COMPILE_FLAGS_DEPS})

Loading…
Cancel
Save