Set optimization flags based on build type, limit to max -O1

Apparently, the build-specific flags automatically get appended
to the generic flags... so we can't put them in the generic list
of flags because the build-specific ones take precedence
( -O0 -O3 is the same as -O3 )
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df3b1f3..7231565 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,11 +52,27 @@
 endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
 
 if(NOT CMAKE_BUILD_TYPE)
-  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
-      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
-      FORCE)
+    set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
+        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
+        FORCE)
 endif(NOT CMAKE_BUILD_TYPE)
 
+if (CXX11)
+    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g"
+        CACHE STRING
+        "Flags used by the CXX compiler during RELWITHDEBINFO builds." FORCE)
+    SET(CMAKE_CXX_FLAGS_RELEASE "-O1 -DNDEBUG"
+        CACHE STRING
+        "Flags used by the CXX compiler during RELEASE builds." FORCE)
+    SET(CMAKE_CXX_FLAGS_DEBUG  "-O0 -g"
+        CACHE STRING
+        "Flags used by the CXX compiler during DEBUG builds." FORCE)
+    SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG"
+        CACHE STRING
+        "Flags used by the CXX compiler during MINSIZEREL builds." FORCE)
+endif(CXX11)
+
+
 # The C++11 standard overlaps a lot with older versions of Boost.
 # So before deciding what standard to use for the whole project, we
 #  first detect Boost to see what version is on the system.
@@ -174,7 +190,7 @@
     endif(APPLE)
 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
     if(CXX11)
-        set(CMAKE_CXX_FLAGS "-stdlib=libc++ -std=c++11"
+        SET(CMAKE_CXX_FLAGS "-stdlib=libc++ -std=c++11"
             CACHE STRING
             "Flags used by the compiler during all build types." FORCE)
     else(CXX11)