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

  set(MSVC_WARNINGS
      /W4
      /w14242
      /w14254
      /w14263
      /w14265 
      /w14287
      /we4289
      /w14296
      /w14311
      /w14545
      /w14546
      /w14547
      /w14549 
      /w14555
      /w14619
      /w14640
      /w14826
      /w14905
      /w14906
      /w14928
  )

  set(CLANG_WARNINGS
      -Wall
      -Wextra
      -Wshadow
      # -Wcast-align
      -Wunused
      -Wpedantic
      -Wconversion
      -Wsign-conversion
      -Wnull-dereference
      -Wdouble-promotion
      -Wformat=2
  )

  if (WARNINGS_AS_ERRORS)
    set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
    set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
  endif()

  set(GCC_WARNINGS
      ${CLANG_WARNINGS}
      -Wmisleading-indentation
      -Wduplicated-cond
      -Wduplicated-branches
      -Wlogical-op
  )

  if(MSVC)
    set(PROJECT_WARNINGS ${MSVC_WARNINGS})
  elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
    message("CASE: CMAKE_C_COMPILER_ID STREQUAL Clang")
    set(PROJECT_WARNINGS ${CLANG_WARNINGS})
  elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
    set(PROJECT_WARNINGS ${CLANG_WARNINGS})
  else()
    set(PROJECT_WARNINGS ${GCC_WARNINGS})
  endif()

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

endfunction()
