Skip to content

Instantly share code, notes, and snippets.

@scivision
Created August 31, 2026 19:14
Show Gist options
  • Select an option

  • Save scivision/ea9882f92577a1992de2202031324aed to your computer and use it in GitHub Desktop.

Select an option

Save scivision/ea9882f92577a1992de2202031324aed to your computer and use it in GitHub Desktop.
Test CMAKE_COMPILE_WARNING_AS_ERROR with Fortran

Test CMAKE_COMPILE_WARNING_AS_ERROR with Fortran

As noted in CMake MR 12455 CMake's own test suite doesn't test CMAKE_COMPILE_WARNING_AS_ERROR, so we made this little test.

cmake_minimum_required(VERSION 4.4)
project(FlangErr LANGUAGES Fortran)
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU|LLVMFlang")
add_compile_options(-Wunused-variable)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
add_compile_options(-warn:unused)
endif()
file(GENERATE OUTPUT "err.f90"
CONTENT "program test
integer :: i
end program")
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
add_executable(Err ${CMAKE_CURRENT_BINARY_DIR}/err.f90)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment