diff --git a/CMakeLists.txt b/CMakeLists.txt
index f30dadebe5380b6d984f77f6ffc8baa789dd698f..41d659851636da9a1c620b95589396312c9e2cfd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,8 +71,8 @@ if(HAVE_WALL)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 endif()
 
-check_cxx_compiler_flag("-03" HAVE_WALL)
-if(HAVE_WALL)
+check_cxx_compiler_flag("-03" HAVE_O3)
+if(HAVE_O3)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
 endif()