Generate man pages and completions by default if possible
[alexxy/gromacs.git] / cmake / gmxOptionUtilities.cmake
index 1cbf7c89aa9d34d441862f7cd2b09b2cfd596977..603f3c5cfd4b61dbc347b6f4d61a34b5474a11c8 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2013, by the GROMACS development team, led by
+# Copyright (c) 2013,2014, by the GROMACS development team, led by
 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 # and including many others, as listed in the AUTHORS file in the
 # top-level source directory and at http://www.gromacs.org.
@@ -67,7 +67,7 @@ function(GMX_OPTION_MULTICHOICE NAME DESCRIPTION DEFAULT)
     string(REPLACE "[built-in]" "" _allowed "${ARGN}")
 
     # Set the cache properties
-    set(${NAME} ${DEFAULT} CACHE STRING ${_description})
+    set(${NAME} ${DEFAULT} CACHE STRING "${_description}")
     set_property(CACHE ${NAME} PROPERTY STRINGS ${_allowed})
 
     # Check that the value is one of the allowed
@@ -78,7 +78,7 @@ function(GMX_OPTION_MULTICHOICE NAME DESCRIPTION DEFAULT)
     if (_found_index EQUAL -1)
         message(FATAL_ERROR "Invalid value for ${NAME}: ${_org_value}.  "
                             "Pick one of: ${_allowed_comma_separated}")
-    endif ()
+    endif()
     # Always provide the upper-case value to the caller
     set(${NAME} "${${NAME}}" PARENT_SCOPE)
 endfunction()
@@ -88,6 +88,39 @@ function(GMX_INVALID_OPTION_VALUE NAME)
     message(FATAL_ERROR "Invalid value for ${NAME}: ${${NAME}}")
 endfunction()
 
+# Declares a cache variable with ON/OFF/AUTO values
+#
+# Usage:
+#   gmx_option_trivalue(VAR "Description" DEFAULT)
+#
+# Output:
+#   VAR is created in the cache, and the caller can assume that the value is
+#   always one of ON/OFF/AUTO.  Additionally, VAR_AUTO is set if value is AUTO,
+#   and VAR_FORCE is set if value is ON.
+#   These make it convenient to check for any combination of states with simple
+#   if() statements (simple if(VAR) matches AUTO and ON).
+function(GMX_OPTION_TRIVALUE NAME DESCRIPTION DEFAULT)
+    set(_description "${DESCRIPTION}. ON/OFF/AUTO")
+    set(${NAME} ${DEFAULT} CACHE STRING "${_description}")
+    set_property(CACHE ${NAME} PROPERTY STRINGS ON OFF AUTO)
+
+    set(${NAME}_AUTO OFF)
+    set(${NAME}_FORCE OFF)
+    string(TOUPPER "${${NAME}}" ${NAME})
+    if ("${NAME}" STREQUAL "AUTO")
+        set(${NAME}_AUTO ON)
+    elseif (${NAME})
+        set(${NAME}_FORCE ON)
+        set(${NAME} ON)
+    else()
+        set(${NAME} OFF)
+    endif()
+    # Always provide the sanitized value to the caller
+    set(${NAME}       "${${NAME}}"       PARENT_SCOPE)
+    set(${NAME}_AUTO  "${${NAME}_AUTO}"  PARENT_SCOPE)
+    set(${NAME}_FORCE "${${NAME}_FORCE}" PARENT_SCOPE)
+endfunction()
+
 # Hides or shows a cache value based on conditions
 #
 # Usage: