# from here:
#
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md

function(set_project_warnings project_name)
  option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE)

  set(GCC_WARNINGS
      -Wall
      -Wextra
      -pedantic
      -Wshadow
      -Wdouble-promotion
      -Wformat=2
      -Wformat-truncation
      -Wundef
      -fno-common
      -Wcast-align
      -Wunused
      -Wconversion
      -Wsign-conversion
      -Wnull-dereference
  )

  if(WARNINGS_AS_ERRORS)
    set(GCC_WARNINGS -Werror)
  endif()

  if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
    set(PROJECT_WARNINGS ${GCC_WARNINGS})
  else()
    message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_C_COMPILER_ID}' compiler.")
  endif()

  target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS})

endfunction()