convert CMakeLists to use CMake's OPTION command (with our own wrapper)
authorTero Marttila <terom@fixme.fi>
Mon, 26 Jan 2009 23:39:08 +0200
changeset 433 4ee797e09383
parent 432 82b0f4e55a13
child 434 a8ba81432ddd
convert CMakeLists to use CMake's OPTION command (with our own wrapper)
src/CMakeLists.txt
src/config.h.in
--- a/src/CMakeLists.txt	Mon Jan 26 23:26:44 2009 +0200
+++ b/src/CMakeLists.txt	Mon Jan 26 23:39:08 2009 +0200
@@ -3,30 +3,23 @@
 
 set_source_files_properties("version.c" PROPERTIES GENERATED true)
 
-# Component selection
-if (DEFINED GRAPHICS_ENABLED)
-    # leave it
-
-elseif (DEFINED ENABLE_GRAPHICS)
-    set (GRAPHICS_ENABLED ${ENABLE_GRAPHICS})
-
-else (DEFINED GRAPHICS_ENABLED)
-    set (GRAPHICS_ENABLED true)
-
-endif (DEFINED GRAPHICS_ENABLED)
+# define + adapt option value, these need to be set as C++ booleans
+macro (kg_option option_var option_config description default)
+    option (${option_var} ${description} ${default})
 
-if (DEFINED NETWORK_ENABLED)
-    # leave it
-
-elseif (DEFINED ENABLE_NETWORK)
-    set (NETWORK_ENABLED ${ENABLE_NETWORK})
+    if (${option_var})
+        set (${option_config} true)
+    else (${option_var})
+        set (${option_config} false)
+    endif (${option_var})
 
-else (DEFINED NETWORK_ENABLED)
-    set (NETWORK_ENABLED true)
+    mark_as_advanced(${option_var})
+endmacro (kg_option)
 
-endif (DEFINED NETWORK_ENABLED)
-
-mark_as_advanced (CLEAR GRAPHICS_ENABLED NETWORK_ENABLED)
+# Define options
+KG_OPTION (ENABLE_DEBUG     DEBUG_ENABLED       "Enable debug behaviour"    ON)
+KG_OPTION (ENABLE_GRAPHICS  GRAPHICS_ENABLED    "Enable graphics support"   ON)
+KG_OPTION (ENABLE_NETWORK   NETWORK_ENABLED     "Enable network support"    ON)
 
 # Generate config.h
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY)
--- a/src/config.h.in	Mon Jan 26 23:26:44 2009 +0200
+++ b/src/config.h.in	Mon Jan 26 23:39:08 2009 +0200
@@ -18,7 +18,7 @@
  *
  *  * Default log level is DEBUG instead of INFO
  */
-#define DEBUG_ENABLED false
+#define DEBUG_ENABLED @DEBUG_ENABLED@
 
 /**
  * Provide possibility to compile without graphics code.