# ID 96a6ff8a05cd548fa548ffd02570399b

cmake_minimum_required(VERSION 4.0...4.2)

project(background
  VERSION 0.3
  DESCRIPTION "C++ background refresher"
  LANGUAGES CXX
)

if(PROJECT_IS_TOP_LEVEL)
  if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
    message(FATAL_ERROR "In-source builds are not supported by this exercise.")
  endif()

  get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  if(NOT is_multi_config AND NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
      STRINGS Debug Release RelWithDebInfo MinSizeRel)
  endif()

  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()


add_library(background_warnings INTERFACE)
add_library(background::warnings ALIAS background_warnings)
target_compile_options(background_warnings INTERFACE
  $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall;-Wextra;-Wconversion>
  $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fno-rtti>
)


option(BACKGROUND_ENABLE_SANITIZERS
  "Build Debug configurations with AddressSanitizer and UBSan" ON)
add_library(background_sanitizers INTERFACE)
add_library(background::sanitizers ALIAS background_sanitizers)
if(BACKGROUND_ENABLE_SANITIZERS)
  set(background_sanitizer_flags
    $<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:-fsanitize=address,undefined;-fno-omit-frame-pointer>
  )
  target_compile_options(background_sanitizers INTERFACE ${background_sanitizer_flags})
  target_link_options(background_sanitizers INTERFACE ${background_sanitizer_flags})
endif()


add_subdirectory(lib)


option(BUILD_TESTING "Build the unit tests" ON)
if(BUILD_TESTING)
  enable_testing()
  add_subdirectory(test)
endif()
