* CMakeLists.txt: Set the build type first, by forcing it into the cache.

git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1834837 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 758a393..4822bfd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,15 @@
         "has not been tested on many supported platforms.")
 enable_testing()
 
+# Initialize the build type if it was not set on the command line.
+if(NOT CMAKE_BUILD_TYPE)
+  if(DEBUG)
+    set(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Default to debug build.")
+  else()
+    set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "Default to release build.")
+  endif()
+endif()
+
 include(SerfPlatform)
 include(SerfWindowsToolkit)
 
@@ -259,16 +268,6 @@
 endif(NOT MSVC)
 
 
-# This must come *AFTER* all the compiler flags and definitioins are set.
-if(NOT CMAKE_BUILD_TYPE)
-  if(DEBUG)
-    set(CMAKE_BUILD_TYPE DEBUG)
-  else()
-    set(CMAKE_BUILD_TYPE RELEASE)
-  endif()
-endif()
-
-
 # Define all targets
 add_library(serf SHARED ${SOURCES} ${SHARED_SOURCES})
 target_link_libraries(serf ${DEPENDENCY_LIBRARIES})