Generate man pages and completions by default if possible
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 21 Sep 2014 13:40:19 +0000 (16:40 +0300)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 23 Sep 2014 09:03:24 +0000 (11:03 +0200)
Make GMX_BUILD_HELP a tristate option to support three different use
cases:
 - OFF: never build anything (default for source distributions, where
   everything is already generated)
 - ON: always build everything as part of the ALL target, give an error
   if anything fails.
 - AUTO: try to build man pages and completions as part of the ALL
   target, and install the result if successful; if it fails, some
   warnings will be given, but build will still be otherwise functional.
This allows making the default AUTO for builds from a git repo, making
the shell completions and man pages work automatically also in such
cases (as long as the build host can run the compiled executables).

HTML help is generated only with GMX_BUILD_HELP=ON, since it is
currently in somewhat of a flux what will happen to it, and most people
will not notice it missing, either.

Change-Id: Id7a69b1b912381a2f1ad3678b82cbaa01cba8479

CMakeLists.txt
CPackInit.cmake
cmake/gmxOptionUtilities.cmake
docs/man/BuildManPages.cmake [new file with mode: 0644]
docs/man/CMakeLists.txt
docs/old-html/BuildHtmlHelp.cmake
docs/old-html/CMakeLists.txt
src/programs/BuildCompletions.cmake [new file with mode: 0644]
src/programs/CMakeLists.txt

index d3e6720c424f9885ce37444056127471e69db310..de857c316c04c2d689b733b1ab051926ff688ab2 100644 (file)
@@ -104,7 +104,7 @@ set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
 # part of the configuration or build.
 set(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/src/programs/completion;src/programs/completion;${CMAKE_BINARY_DIR}/docs/man/man1;docs/man/man1;${CMAKE_BINARY_DIR}/docs/man/man7;docs/man/man7;${CMAKE_BINARY_DIR}/docs/old-html/final;docs/old-html/final;${CMAKE_BINARY_DIR}/docs/install-guide/final;/")
 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
-set(CPACK_GMX_BUILD_HELP "${GMX_BUILD_HELP}") #Works even though GMX_BUILD_HELP is defined later because it is off by default.
+#set(CPACK_GMX_BUILD_HELP "${GMX_BUILD_HELP}") #No longer works because GMX_BUILD_HELP is defined later.
 
 #must come after all cpack settings!
 include(CPack)
@@ -703,12 +703,18 @@ if(GMX_FAHCORE)
   include_directories(${COREWRAP_INCLUDE_DIR})
 endif()
 
-option(GMX_BUILD_HELP "Build man pages, HTML help, and completions automatically (requires that compiled binaries can be executed on the build host)" OFF)
+# Value of AUTO tries to generate things, but will only produce warnings if
+# that fails.
+set(build_help_default AUTO)
+if (SOURCE_IS_SOURCE_DISTRIBUTION)
+    set(build_help_default OFF)
+endif()
+gmx_option_trivalue(GMX_BUILD_HELP "Build man pages, HTML help, and completions automatically (requires that compiled binaries can be executed on the build host)" ${build_help_default})
 mark_as_advanced(GMX_BUILD_HELP)
 if (GMX_BUILD_HELP AND SOURCE_IS_SOURCE_DISTRIBUTION AND BUILD_IS_INSOURCE)
     message(FATAL_ERROR
-        "Rebuilding HTML and man pages is not supported for in-source "
-        "builds from a source distribution. "
+        "Rebuilding HTML and man pages or shell completions is not supported "
+        "for in-source builds from a source distribution. "
         "Set GMX_BUILD_HELP=OFF or do an out-of-source build to proceed.")
 endif()
 
index 498b034306f05bcd4f03dbda8f664ffd538e7e92..25046b8b562ec6948ea1dcb34773e36ec593595e 100644 (file)
@@ -48,13 +48,14 @@ if(NOT CPACK_INSTALL_CMAKE_PROJECTS) #building source package
             "GMX_BUILD_HELP=ON to automatically build the HTML parts.")
     endif()
 else()
-    if (NOT CPACK_GMX_BUILD_HELP)
-        message(WARNING
-            "To create a complete binary package, bash completions, and "
-            "man and HTML pages need to be generated. "
-            "You need to configure with GMX_BUILD_HELP=ON to include all "
-            "in the binary package.")
-        # Building the man, html, ... targets is not sufficient because than the
-        # install is still not done.
-    endif()
+    # TODO: Make this work again.
+    #if (NOT CPACK_GMX_BUILD_HELP)
+    #    message(WARNING
+    #        "To create a complete binary package, bash completions, and "
+    #        "man and HTML pages need to be generated. "
+    #        "You need to configure with GMX_BUILD_HELP=ON to include all "
+    #        "in the binary package.")
+    #    # Building the man, html, ... targets is not sufficient because than the
+    #    # install is still not done.
+    #endif()
 endif()
index 7da67d4403e7a0284ecf4b837baa8ec8d27f8777..603f3c5cfd4b61dbc347b6f4d61a34b5474a11c8 100644 (file)
@@ -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
@@ -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:
diff --git a/docs/man/BuildManPages.cmake b/docs/man/BuildManPages.cmake
new file mode 100644 (file)
index 0000000..80c5aeb
--- /dev/null
@@ -0,0 +1,60 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 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.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+if (NOT DEFINED GMX_EXECUTABLE OR NOT DEFINED SOURCE_DIR)
+    message(FATAL_ERROR "Required input parameter not set")
+endif()
+
+file(MAKE_DIRECTORY man1)
+file(MAKE_DIRECTORY man7)
+file(COPY ${SOURCE_DIR}/man7/gromacs.7.in DESTINATION man7/)
+execute_process(
+    COMMAND ${GMX_EXECUTABLE} -quiet help -export man
+    RESULT_VARIABLE exitcode)
+if (exitcode)
+    # Ensure that no partial output is left behind.
+    file(REMOVE_RECURSE man1)
+    file(REMOVE man7/gromacs.7)
+    if (ERRORS_ARE_FATAL)
+        message(FATAL_ERROR
+            "Failed to generate man pages. "
+            "Set GMX_BUILD_HELP=OFF if you want to skip them.\n"
+            "Error/exit code: ${exitcode}")
+    else()
+        message(
+            "Failed to generate man pages, will build GROMACS without. "
+            "Set GMX_BUILD_HELP=OFF if you want to skip this notification and "
+            "warnings during installation.")
+    endif()
+endif()
index cf193662e445c047ee3e6a7eae0cce157d796de6..456b59cf3fa06f812f6c737a2de844d2d69cf2b3 100644 (file)
 
 include(gmxCustomCommandUtilities)
 
-gmx_add_custom_output_target(man OUTPUT STAMP
-    COMMAND ${CMAKE_COMMAND} -E make_directory man1
-    COMMAND ${CMAKE_COMMAND} -E make_directory man7
-    COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/man7/gromacs.7.in" man7/
-    COMMAND gmx -quiet help -export man
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-    DEPENDS gmx ${CMAKE_CURRENT_SOURCE_DIR}/man7/gromacs.7.in
-    COMMENT "Generating man pages")
-
 set(MAN_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 if (GMX_BUILD_HELP)
+    gmx_add_custom_output_target(man OUTPUT STAMP
+        COMMAND ${CMAKE_COMMAND}
+            -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
+            -D SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
+            -D ERRORS_ARE_FATAL=${GMX_BUILD_HELP_FORCE}
+            -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildManPages.cmake
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+        DEPENDS gmx
+            ${CMAKE_CURRENT_SOURCE_DIR}/man7/gromacs.7.in
+            ${CMAKE_CURRENT_SOURCE_DIR}/BuildManPages.cmake
+        COMMENT "Generating man pages")
     set_target_properties(man PROPERTIES EXCLUDE_FROM_ALL OFF)
     set_directory_properties(PROPERTIES
         ADDITIONAL_MAKE_CLEAN_FILES "man1;man7/gromacs.7")
@@ -55,8 +57,8 @@ endif()
 if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
     install(FILES ${MAN_PAGE_DIR}/man7/gromacs.7
         DESTINATION ${MAN_INSTALL_DIR}/man7
-        COMPONENT man)
+        COMPONENT man OPTIONAL)
     install(DIRECTORY ${MAN_PAGE_DIR}/man1
         DESTINATION ${MAN_INSTALL_DIR}
-        COMPONENT man)
+        COMPONENT man OPTIONAL)
 endif()
index 8a4f169a5f751bdf747e3d641a67ea17895f941a..16c31da177a36e87c7aaa9003bf52ee14a590157 100644 (file)
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-if (NOT DEFINED OUTPUT_DIR OR NOT DEFINED SOURCE_HTML_DIR)
+if (NOT DEFINED GMX_EXECUTABLE OR NOT DEFINED OUTPUT_DIR OR NOT DEFINED SOURCE_HTML_DIR)
     message(FATAL_ERROR "Required input parameter not set")
 endif()
 
-function(PRE_EXPORT_ACTIONS)
-    file(MAKE_DIRECTORY ${OUTPUT_DIR})
-    file(MAKE_DIRECTORY ${OUTPUT_DIR}/programs)
-    file(COPY ${SOURCE_HTML_DIR}/header.html.in DESTINATION .)
-    file(COPY ${SOURCE_HTML_DIR}/footer.html DESTINATION .)
-    file(COPY ${SOURCE_HTML_DIR}/links.dat   DESTINATION .)
-endfunction()
+file(MAKE_DIRECTORY ${OUTPUT_DIR})
+file(MAKE_DIRECTORY ${OUTPUT_DIR}/programs)
+file(COPY ${SOURCE_HTML_DIR}/header.html.in DESTINATION .)
+file(COPY ${SOURCE_HTML_DIR}/footer.html DESTINATION .)
+file(COPY ${SOURCE_HTML_DIR}/links.dat   DESTINATION .)
+
+# This is generated by gmx help -export html
+set(HEADER_FILE header.html)
 
-function(POST_EXPORT_ACTIONS)
-    # This is generated by gmx help -export html
-    set(HEADER_FILE header.html)
-    set(FOOTER_FILE ${SOURCE_HTML_DIR}/footer.html)
-    file(READ ${HEADER_FILE} HEADER_TEXT)
-    file(READ ${FOOTER_FILE} FOOTER_TEXT)
-    set(_title_re "[Tt][Ii][Tt][Ll][Ee]")
+execute_process(
+    COMMAND ${GMX_EXECUTABLE} -quiet help -export html
+    RESULT_VARIABLE exitcode)
+if (exitcode)
+    # Ensure that no partial output is left behind.
+    file(REMOVE_RECURSE ${OUTPUT_DIR})
+    file(REMOVE ${HEADER_FILE})
+    message(FATAL_ERROR
+        "Failed to generate HTML help. "
+        "Set GMX_BUILD_HELP=OFF or GMX_BUILD_HELP=AUTO if you want to skip them.\n"
+        "Error/exit code: ${exitcode}")
+endif()
 
-    function(CREATE_HTML_FILE SOURCE_FILE ROOTPATH)
-        file(RELATIVE_PATH _rel_path ${SOURCE_HTML_DIR} ${SOURCE_FILE})
-        file(READ ${SOURCE_FILE} _content)
-        string(REGEX REPLACE "^ *<${_title_re}>(.*)</${_title_re}>\n" "" _content "${_content}")
-        set(TITLE "${CMAKE_MATCH_1}")
-        string(CONFIGURE "${HEADER_TEXT}" _header @ONLY)
-        set(_content "${_header}${_content}${FOOTER_TEXT}")
-        file(WRITE ${OUTPUT_DIR}/${_rel_path} "${_content}")
-    endfunction()
+set(FOOTER_FILE ${SOURCE_HTML_DIR}/footer.html)
+file(READ ${HEADER_FILE} HEADER_TEXT)
+file(READ ${FOOTER_FILE} FOOTER_TEXT)
+set(_title_re "[Tt][Ii][Tt][Ll][Ee]")
 
-    create_html_file(${SOURCE_HTML_DIR}/online.html "")
-    file(COPY ${SOURCE_HTML_DIR}/images DESTINATION ${OUTPUT_DIR})
-    file(MAKE_DIRECTORY ${OUTPUT_DIR}/online)
-    file(COPY ${SOURCE_HTML_DIR}/online/style.css DESTINATION ${OUTPUT_DIR}/online)
-    file(GLOB _source_files ${SOURCE_HTML_DIR}/online/*.html)
-    foreach(_file ${_source_files})
-        create_html_file(${_file} "../")
-    endforeach()
+function(CREATE_HTML_FILE SOURCE_FILE ROOTPATH)
+    file(RELATIVE_PATH _rel_path ${SOURCE_HTML_DIR} ${SOURCE_FILE})
+    file(READ ${SOURCE_FILE} _content)
+    string(REGEX REPLACE "^ *<${_title_re}>(.*)</${_title_re}>\n" "" _content "${_content}")
+    set(TITLE "${CMAKE_MATCH_1}")
+    string(CONFIGURE "${HEADER_TEXT}" _header @ONLY)
+    set(_content "${_header}${_content}${FOOTER_TEXT}")
+    file(WRITE ${OUTPUT_DIR}/${_rel_path} "${_content}")
 endfunction()
 
-if (STEP STREQUAL "PRE")
-    pre_export_actions()
-elseif (STEP STREQUAL "POST")
-    post_export_actions()
-else()
-    message(FATAL_ERROR "Unknown parameter STEP=${STEP}")
-endif()
+create_html_file(${SOURCE_HTML_DIR}/online.html "")
+file(COPY ${SOURCE_HTML_DIR}/images DESTINATION ${OUTPUT_DIR})
+file(MAKE_DIRECTORY ${OUTPUT_DIR}/online)
+file(COPY ${SOURCE_HTML_DIR}/online/style.css DESTINATION ${OUTPUT_DIR}/online)
+file(GLOB _source_files ${SOURCE_HTML_DIR}/online/*.html)
+foreach(_file ${_source_files})
+    create_html_file(${_file} "../")
+endforeach()
index c407467e7c387a26663139a54af2b1122052edbf..1b9b12e41a4d9428d2431c1ae599f93801b897f7 100644 (file)
@@ -36,42 +36,41 @@ include(gmxCustomCommandUtilities)
 
 set(OUTPUT_DIR final)
 
-file(GLOB_RECURSE deps
-     ${CMAKE_CURRENT_SOURCE_DIR}/images/*
-     ${CMAKE_CURRENT_SOURCE_DIR}/*.html
-     ${CMAKE_CURRENT_SOURCE_DIR}/*.css
-     )
-list(APPEND deps
-     ${CMAKE_CURRENT_SOURCE_DIR}/BuildHtmlHelp.cmake
-     ${CMAKE_CURRENT_SOURCE_DIR}/header.html.in
-     ${CMAKE_CURRENT_SOURCE_DIR}/links.dat
-     )
-
-gmx_add_custom_output_target(html OUTPUT STAMP
-    COMMAND ${CMAKE_COMMAND}
-        -D SOURCE_HTML_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-        -D OUTPUT_DIR=${OUTPUT_DIR}
-        -D STEP=PRE
-        -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildHtmlHelp.cmake
-    COMMAND gmx -quiet help -export html
-    COMMAND ${CMAKE_COMMAND}
-        -D SOURCE_HTML_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-        -D OUTPUT_DIR=${OUTPUT_DIR}
-        -D STEP=POST
-        -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildHtmlHelp.cmake
-    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-    DEPENDS gmx ${deps}
-    COMMENT "Generating HTML help")
-
 set(HTML_PAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${OUTPUT_DIR})
 if (GMX_BUILD_HELP)
-    set_target_properties(html PROPERTIES EXCLUDE_FROM_ALL OFF)
+    # Unlike the man and completion targets, this target is not built
+    # automatically with GMX_BUILD_HELP=AUTO, since most people will not
+    # notice it missing.
+    file(GLOB_RECURSE deps
+         ${CMAKE_CURRENT_SOURCE_DIR}/images/*
+         ${CMAKE_CURRENT_SOURCE_DIR}/*.html
+         ${CMAKE_CURRENT_SOURCE_DIR}/*.css
+         )
+    list(APPEND deps
+         ${CMAKE_CURRENT_SOURCE_DIR}/BuildHtmlHelp.cmake
+         ${CMAKE_CURRENT_SOURCE_DIR}/header.html.in
+         ${CMAKE_CURRENT_SOURCE_DIR}/links.dat
+         )
+
+    gmx_add_custom_output_target(html OUTPUT STAMP
+        COMMAND ${CMAKE_COMMAND}
+            -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
+            -D SOURCE_HTML_DIR=${CMAKE_CURRENT_SOURCE_DIR}
+            -D OUTPUT_DIR=${OUTPUT_DIR}
+            -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildHtmlHelp.cmake
+        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+        DEPENDS gmx ${deps}
+        COMMENT "Generating HTML help")
+
+    if (GMX_BUILD_HELP_FORCE)
+        set_target_properties(html PROPERTIES EXCLUDE_FROM_ALL OFF)
+    endif()
     set_directory_properties(PROPERTIES
         ADDITIONAL_MAKE_CLEAN_FILES "${OUTPUT_DIR};header.html")
     set(HTML_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_DIR})
 endif()
 
-if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
+if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP_FORCE)
     install(DIRECTORY ${HTML_PAGE_DIR}/
         DESTINATION ${DATA_INSTALL_DIR}/html
         COMPONENT html)
diff --git a/src/programs/BuildCompletions.cmake b/src/programs/BuildCompletions.cmake
new file mode 100644 (file)
index 0000000..cea5ea1
--- /dev/null
@@ -0,0 +1,58 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 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.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+if (NOT DEFINED GMX_EXECUTABLE)
+    message(FATAL_ERROR "Required input parameter not set")
+endif()
+
+file(MAKE_DIRECTORY completion)
+execute_process(
+    COMMAND ${GMX_EXECUTABLE} -quiet help -export completion
+    WORKING_DIRECTORY completion
+    RESULT_VARIABLE exitcode)
+if (exitcode)
+    # Ensure that no partial output is left behind.
+    file(REMOVE_RECURSE completion)
+    if (ERRORS_ARE_FATAL)
+        message(FATAL_ERROR
+            "Failed to generate shell completions. "
+            "Set GMX_BUILD_HELP=OFF if you want to skip the completions.\n"
+            "Error/exit code: ${exitcode}")
+    else()
+        message(
+            "Failed to generate shell completions, will build GROMACS without. "
+            "Set GMX_BUILD_HELP=OFF if you want to skip this notification and "
+            "warnings during installation.")
+    endif()
+endif()
index 50573b2977a96ac8d711b696336a05e97e5af29d..1b6c4518cd978e3370eb920d49522ddace8f9b65 100644 (file)
@@ -81,18 +81,19 @@ else()
 
     include(gmxCustomCommandUtilities)
 
-    gmx_add_custom_output_target(completion OUTPUT STAMP
-        COMMAND ${CMAKE_COMMAND} -E make_directory completion
-        COMMAND ${CMAKE_COMMAND} -E chdir completion
-            $<TARGET_FILE:gmx> -quiet help -export completion
-        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-        DEPENDS gmx
-        COMMENT "Generating command-line completions for programs")
+    set(COMPLETION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/completion)
     # Using GMX_BUILD_HELP here is somewhat confusing, but the conditions when
     # this can be done are exactly the same (ability to run the compiled
     # binaries).
-    set(COMPLETION_DIR ${CMAKE_CURRENT_SOURCE_DIR}/completion)
     if (GMX_BUILD_HELP)
+        gmx_add_custom_output_target(completion OUTPUT STAMP
+            COMMAND ${CMAKE_COMMAND}
+                -D GMX_EXECUTABLE=$<TARGET_FILE:gmx>
+                -D ERRORS_ARE_FATAL=${GMX_BUILD_HELP_FORCE}
+                -P ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
+            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+            DEPENDS gmx ${CMAKE_CURRENT_SOURCE_DIR}/BuildCompletions.cmake
+            COMMENT "Generating command-line completions for programs")
         set_target_properties(completion PROPERTIES EXCLUDE_FROM_ALL OFF)
         set_directory_properties(PROPERTIES
             ADDITIONAL_MAKE_CLEAN_FILES "completion")
@@ -100,7 +101,7 @@ else()
     endif()
     if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
         install(DIRECTORY ${COMPLETION_DIR}/
-                DESTINATION ${BIN_INSTALL_DIR} COMPONENT runtime)
+                DESTINATION ${BIN_INSTALL_DIR} COMPONENT runtime OPTIONAL)
         file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
              "complete -o nospace -F _gmx_compl ${BINARY_NAME}")
         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash