Misc. improvements to docs build system
[alexxy/gromacs.git] / docs / CMakeLists.txt
index b9ef0a280f9c7876357544674b68efea91007efe..1a4f40eacf95cb8348f6f9c93e64d355ce99cf96 100644 (file)
 # conf-vars.py.cmakein), which in turn is included by the Sphinx configuration
 # file conf.py.
 
-option(GMX_BUILD_WEBPAGE "Whether to try to configure to build the GROMACS static webpages" OFF)
-option(GMX_BUILD_MANUAL "Whether to try to configure to build the PDF manual" OFF)
-mark_as_advanced(GMX_BUILD_WEBPAGE GMX_BUILD_MANUAL)
+set(SOURCE_MD5SUM "unknown" CACHE STRING
+    "MD5 sum of the source tarball, normally used only for the pre-release webpage build")
+# REGRESSIONTEST_MD5SUM is set in cmake/gmxVersionInfo.cmake because it is used also in tests/CMakeLists.txt
+mark_as_advanced(SOURCE_MD5SUM)
 
 set(EXPECTED_DOXYGEN_VERSION 1.8.5)
 
@@ -75,16 +76,7 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION)
 endif()
 
 add_subdirectory(doxygen)
-
-set(SOURCE_MD5SUM "unknown" CACHE STRING "MD5 sum of the source tarball, normally used only for the pre-release webpage build")
-# REGRESSIONTEST_MD5SUM is set in cmake/gmxVersionInfo.cmake because it is used also in tests/CMakeLists.txt
-mark_as_advanced(SOURCE_MD5SUM)
-
-if(GMX_BUILD_MANUAL)
-    # Make sure we only do detection of manual-building dependencies
-    # when the user opted in for that.
-    add_subdirectory(manual)
-endif()
+add_subdirectory(manual)
 
 if (SPHINX_FOUND)
     # We need to have all the Sphinx input files in a single directory, and
@@ -176,6 +168,8 @@ if (SPHINX_FOUND)
     gmx_add_custom_output_target(sphinx-input OUTPUT STAMP
         DEPENDS ${SPHINX_INPUT_FILES})
     # TODO: Make this remove obsolete .rst files.
+    # TODO: This does not work in cross-compilation scenarios; disable up to
+    # the necessary level.
     gmx_add_custom_output_target(sphinx-programs OUTPUT STAMP
         COMMAND ${CMAKE_COMMAND} -E make_directory onlinehelp
         COMMAND gmx -quiet help -export rst
@@ -249,6 +243,15 @@ if (SPHINX_FOUND)
         # manually build the target.
         set(MAN_PAGE_DIR ${CMAKE_CURRENT_BINARY_DIR})
     endif()
+else()
+    add_custom_target(webpage-sphinx
+        COMMAND ${CMAKE_COMMAND} -E echo
+            "HTML pages cannot be built because Sphinx is not available"
+        VERBATIM)
+    add_custom_target(man
+        COMMAND ${CMAKE_COMMAND} -E echo
+            "man pages cannot be built because Sphinx is not available"
+        VERBATIM)
 endif()
 
 if (MAN_PAGE_DIR)
@@ -266,68 +269,81 @@ if (MAN_PAGE_DIR)
 endif()
 gmx_cpack_add_generated_source_directory(man)
 
-set(HTML_BUILD_IS_POSSIBLE OFF)
-# We can only configure to build the webpage if the user asked for it,
-# the build is outside of the source dir, and all the components can
-# be built. There's no intrinsic need to be talkative if we fail -
-# most people never need to know, unless they've asked for the webpage
-# build.
-if(GMX_BUILD_WEBPAGE)
-    set(HTML_BUILD_IS_POSSIBLE ON)
-    # Next, turn it off in any of the preconditions are unsatisified
-
-    if(NOT MANUAL_BUILD_IS_POSSIBLE)
-        set(HTML_BUILD_IS_POSSIBLE OFF)
-        message(STATUS "Cannot build webpage without being able to build the reference PDF manual")
-    endif()
-
-    if(NOT PYTHON_EXECUTABLE)
-        set(HTML_BUILD_IS_POSSIBLE OFF)
-        message(STATUS "Cannot build webpage without python")
-    endif()
+# Determine whether we can build all the HTML pages and content linked from
+# there.  If not, construct an informative message if the user tries to
+# build the target; most people never need to know, unless they've asked for
+# the webpage build.
+set(HTML_BUILD_IS_POSSIBLE ON)
+set(HTML_BUILD_NOT_POSSIBLE_REASON)
+set(HTML_BUILD_WARNINGS)
 
-    if(NOT SPHINX_FOUND)
-        set(HTML_BUILD_IS_POSSIBLE OFF)
-        message(STATUS "Cannot build webpage without sphinx")
-    endif()
+# Next, turn it off if any of the preconditions are unsatisified
+if (NOT PYTHON_EXECUTABLE)
+    set(HTML_BUILD_IS_POSSIBLE OFF)
+    set(HTML_BUILD_NOT_POSSIBLE_REASON "Python is required")
+elseif (NOT SPHINX_FOUND)
+    # Hardly anything gets built if Sphinx is not available, so don't bother.
+    set(HTML_BUILD_IS_POSSIBLE OFF)
+    set(HTML_BUILD_NOT_POSSIBLE_REASON "Sphinx is required")
+endif()
+if (NOT MANUAL_BUILD_IS_POSSIBLE)
+    list(APPEND HTML_BUILD_WARNINGS
+         "Reference PDF manual was not built, so links to it do not work")
+endif()
+if (NOT DOXYGEN_EXECUTABLE)
+    list(APPEND HTML_BUILD_WARNINGS
+        "Doxygen was not available, so links to Doxygen do not work")
+endif()
+if (NOT DOXYGEN_DOT_EXECUTABLE)
+    list(APPEND HTML_BUILD_WARNINGS
+        "dot/graphviz was not found, so some graphs are missing")
+endif()
 
-    if(NOT DOXYGEN_EXECUTABLE)
-        set(HTML_BUILD_IS_POSSIBLE OFF)
-        message(STATUS "Cannot build webpage without doxygen")
+if (HTML_BUILD_IS_POSSIBLE)
+    set(_webpage_target_properties)
+    if (HTML_BUILD_WARNINGS)
+        list(APPEND _webpage_target_properties
+             COMMAND ${CMAKE_COMMAND} -E echo
+                 "webpage was built, but with the following limitations:")
+        foreach(_warning ${HTML_BUILD_WARNINGS})
+        list(APPEND _webpage_target_properties
+             COMMAND ${CMAKE_COMMAND} -E echo " - ${_warning}")
+        endforeach()
     endif()
 
-    if(NOT DOXYGEN_MSCGEN_EXECUTABLE)
-        set(HTML_BUILD_IS_POSSIBLE OFF)
-        message(STATUS "Cannot build webpage without mscgen")
+    if (MANUAL_BUILD_IS_POSSIBLE)
+        # Make the PDF reference guide
+        # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
+        # TODO Make this depend on the output of the manual build, so that the
+        # file actually gets copied multiple times.
+        set(_manual_target_location ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf)
+        add_custom_command(
+            OUTPUT ${_manual_target_location}
+            COMMAND ${CMAKE_COMMAND}
+                -E remove -f ${_manual_target_location}
+            COMMAND ${CMAKE_COMMAND}
+                -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${_manual_target_location}
+            DEPENDS manual
+            VERBATIM)
+        list(APPEND _webpage_target_properties
+             DEPENDS ${_manual_target_location})
     endif()
-endif()
-
-if(HTML_BUILD_IS_POSSIBLE)
-    # Make the PDF reference guide
-    # TODO Try to make the PDF arrive directly in ${HTML_OUTPUT_DIR}
-    add_custom_command(
-        OUTPUT ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
-        COMMAND ${CMAKE_COMMAND}
-            -E remove -f ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
-        COMMAND ${CMAKE_COMMAND}
-            -E copy ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf
-        # UseLATEX.cmake makes a target called pdf, not ${CMAKE_CURRENT_BINARY_DIR}/manual/gromacs.pdf
-        DEPENDS pdf
-        VERBATIM
-        )
 
     # The Doxygen configuration in doxygen/Doxyfile-common.cmakein
     # makes all the Doxygen output directly in
     # ${HTML_OUTPUT_DIR}/doxygen (and makes the directory if it needs
     # to).
 
-    # Add a top-level target for the others to hook onto
-    add_custom_target(webpage
-        DEPENDS ${HTML_OUTPUT_DIR}/manual-${GMX_VERSION_STRING}.pdf)
+    # Add a top-level target that builds everything related to the webpage,
+    # for Jenkins (and possibly others) to use
+    add_custom_target(webpage ${_webpage_target_properties}
+        COMMENT "Building webpage"
+        VERBATIM)
     add_dependencies(webpage webpage-sphinx doxygen-all)
 else()
     add_custom_target(webpage
-        COMMAND ${CMAKE_COMMAND} -E echo "Cannot build webpage because of missing requirements. Check cmake status output for reasons"
-        COMMENT "Webpage build disabled"
-        )
+        COMMAND ${CMAKE_COMMAND} -E echo
+            "Cannot build webpage because ${HTML_BUILD_NOT_POSSIBLE_REASON}"
+        COMMENT "Webpage build not possible"
+        VERBATIM)
 endif()