diff --git a/cmake/SociConfig.cmake b/cmake/SociConfig.cmake
index 8a74330d..2bce264d 100644
--- a/cmake/SociConfig.cmake
+++ b/cmake/SociConfig.cmake
@@ -63,8 +63,15 @@ if (MSVC)
else()
+ # Set the -Werror compilation flag (where all the compilation warnings are
+ # considered as errors) only when building in Debug mode
+ set(SOCI_WERROR_OPTION "")
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+ set(SOCI_WERROR_OPTION "-Werror")
+ endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
+
set(SOCI_GCC_CLANG_COMMON_FLAGS
- "-pedantic -Werror -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long")
+ "-pedantic ${SOCI_WERROR_OPTION} -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long")
if (SOCI_CXX11)