include(copts_defs)

set(CCTEST_LSAN_LINKOPTS "")
set(CCTEST_HAVE_LSAN OFF)
set(CCTEST_DEFAULT_LINKOPTS "")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  set(CCTEST_DEFAULT_COPTS "${CCTEST_GCC_FLAGS}")
  set(CCTEST_TEST_COPTS "${CCTEST_GCC_FLAGS};${CCTEST_GCC_TEST_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  # MATCHES so we get both Clang and AppleClang
  set(CCTEST_DEFAULT_COPTS "${CCTEST_LLVM_FLAGS}")
  set(CCTEST_TEST_COPTS "${CCTEST_LLVM_FLAGS};${CCTEST_LLVM_TEST_FLAGS}")
  set(CCTEST_RANDOM_RANDEN_COPTS "${CCTEST_RANDOM_HWAES_X64_FLAGS}")
  if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    # AppleClang doesn't have lsan
    # https://developer.apple.com/documentation/code_diagnostics
    if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
      set(CCTEST_LSAN_LINKOPTS "-fsanitize=leak")
      set(CCTEST_HAVE_LSAN ON)
    endif()
  endif()
else()
  message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER}.  Building with no default flags")
  set(CCTEST_DEFAULT_COPTS "")
  set(CCTEST_TEST_COPTS "")
  set(CCTEST_RANDOM_RANDEN_COPTS "")
endif()

if("${CMAKE_CXX_STANDARD}" EQUAL 98)
  message(FATAL_ERROR "cctest requires at least C++11")
elseif(NOT "${CMAKE_CXX_STANDARD}")
  message(STATUS "No CMAKE_CXX_STANDARD set, assuming 11")
  set(CCTEST_CXX_STANDARD 11)
else()
  set(CCTEST_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
endif()
