
INCLUDE(CheckCXXCompilerFlag)


IF ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR
    ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")

  CHECK_CXX_COMPILER_FLAG(-fno-permissive COMPILER_SUPPORT_FNOPERMISSIVE)
  CHECK_CXX_COMPILER_FLAG(-ggdb3 COMPILER_SUPPORT_GGDB3)
  CHECK_CXX_COMPILER_FLAG(-Wall COMPILER_SUPPORT_WALL)
  CHECK_CXX_COMPILER_FLAG(-Weverything COMPILER_SUPPORT_WEVERYTHING)
  CHECK_CXX_COMPILER_FLAG(-Wno-c++98-compat-pedantic COMPILER_SUPPORT_NO_CXX98_COMPAT_PENDANTIC)
  CHECK_CXX_COMPILER_FLAG(-Wno-c++98-compat COMPILER_SUPPORT_NO_CXX98_COMPAT)
  CHECK_CXX_COMPILER_FLAG(-Wno-undef COMPILER_SUPPORT_NO_UNDEF)
  CHECK_CXX_COMPILER_FLAG(-Wno-write-strings COMPILER_SUPPORT_NO_WRITE_STRINGS)
  CHECK_CXX_COMPILER_FLAG(-Wno-deprecated COMPILER_SUPPORT_NO_DEPRECATED)
  CHECK_CXX_COMPILER_FLAG(-Wno-padded COMPILER_SUPPORT_NO_PADDED)
  CHECK_CXX_COMPILER_FLAG(-Wextra COMPILER_SUPPORT_WEXTRA)
  CHECK_CXX_COMPILER_FLAG(-Wno-format-nonliteral COMPILER_SUPPORT_NO_FORMAT_NONLITERAL)
  CHECK_CXX_COMPILER_FLAG(-fsanitize=thread COMPILER_SUPPORT_FSANITIZE_ADDRESS)
  CHECK_CXX_COMPILER_FLAG(-Wno-zero-as-null-pointer-constant COMPILER_SUPPORT_NO_ZERO_AS_NULL)
  CHECK_CXX_COMPILER_FLAG(-Wno-unknown-warning COMPILER_SUPPORT_NO_UNKNOWN_WARNING)

  IF(${COMPILER_SUPPORT_FSANITIZE_ADDRESS})
    ADD_COMPILE_OPTIONS(-fsanitize=thread)
  ENDIF()

  IF (${COMPILER_SUPPORT_WEVERYTHING})
    ADD_COMPILE_OPTIONS(-Weverything)
  ELSE()
    IF (${COMPILER_SUPPORT_WALL})
      ADD_COMPILE_OPTIONS(-Wall)
    ENDIF()

    IF (${COMPILER_SUPPORT_WEXTRA})
      ADD_COMPILE_OPTIONS(-Wextra)
    ENDIF()

    IF (${COMPILER_SUPPORT_WALL})
      ADD_COMPILE_OPTIONS(-Wall)
    ENDIF()

    IF (${COMPILER_SUPPORT_NO_WRITE_STRINGS})
      ADD_COMPILE_OPTIONS(-Wno-write-strings)
    ENDIF()
  ENDIF()

  IF (${COMPILER_SUPPOER_NO_UNDEF})
    ADD_COMPILE_OPTIONS(-Wno-undef)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_FORMAT_NONLITERAL})
    ADD_COMPILE_OPTIONS(-Wno-format-nonliteral)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_PADDED})
    ADD_COMPILE_OPTIONS(-Wno-padded)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_CXX98_COMPAT})
    ADD_COMPILE_OPTIONS(-Wno-c++98-compat)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_CXX98_COMPAT_PENDANTIC})
    ADD_COMPILE_OPTIONS(-Wno-c++98-compat-pedantic)
  ENDIF()

  IF (${COMPILER_SUPPORT_GGDB3})
    ADD_COMPILE_OPTIONS(-ggdb3)
    #add_compile_options(-O3)
  ENDIF()

  IF (${COMPILER_SUPPORT_FNOPERMISSIVE})
    ADD_COMPILE_OPTIONS(-fno-permissive)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_DEPRECATED})
    ADD_COMPILE_OPTIONS(-Wno-deprecated)
  ENDIF()

  IF (${COMPILER_SUPPORT_NO_UNKNOWN_WARNING})
    ADD_COMPILE_OPTIONS(-Wno-unknown-warning)
  ENDIF()

ENDIF()
