Minor CMake cleanup & modernization
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 20 Nov 2016 08:02:25 +0000 (10:02 +0200)
committerTeemu Murtola <teemu.murtola@gmail.com>
Sat, 10 Dec 2016 15:11:36 +0000 (16:11 +0100)
- Our minimum CMake version now supports BYPRODUCTS for
  add_custom_target(), which allows simplification of
  gmxCustomCommandUtilities.cmake.
- Specify USES_TERMINAL for targets that provide status output for nicer
  usability with Ninja.
- Rely on add_custom_command() automatically marking its outputs as
  generated.
- Update the minimum required version for building the template to match
  the main project.
- Do not unnecessarily put regressiontests MD5 to the cache.
- Fix the branch used for regression tests download for git builds.

Change-Id: Iee9a7e67d694724ad79cce9801bea670ef2f94c8

cmake/gmxCustomCommandUtilities.cmake
cmake/gmxVersionInfo.cmake
docs/doxygen/CMakeLists.txt
share/template/CMakeLists.txt.template
src/gromacs/CMakeLists.txt
tests/CheckTarget.cmake

index ae3279a8317d9e5a9d8048d0356adde3589fd2b4..082c3eec80d300f0c45f142b89779801b6129e3c 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2016, 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.
@@ -90,10 +90,6 @@ endfunction()
 
 # More flexible alternative to add_custom_command() and add_custom_target()
 # for dependent custom commands.  It adds a few convenience features:
-#   - Support for custom commands that always run (like add_custom_target()),
-#     but still have the ability to act as dependencies of other custom
-#     commands (such that the dependent commands run only if the output
-#     has been updated) also for Ninja.
 #   - Adds file-level dependencies between custom targets added with this
 #     command such that if there is a target-level dependency, it also implies
 #     that the custom command should always be run if the output file of the
@@ -110,16 +106,13 @@ endfunction()
 #                                [WORKING_DIRECTORY <dir>]
 #                                [DEPENDS <deps...>]
 #                                [DEPENDS_FILE_LIST <list>]
-#                                [COMMENT <comment>])
+#                                [COMMENT <comment>] [USES_TERMINAL])
 #
 #   <target>
 #     - Name of the custom target to create.
 #   RUN_ALWAYS
-#     - Create the command such that it always runs.
-#       This takes care of differences between the Ninja generator and others,
-#       which require different rules to make this happen such that
-#       dependencies on the output of the target work correctly, also in the
-#       case the command does not always update the timestamp of the output.
+#     - Create the command such that it always runs, and may update the output
+#       file in the process.
 #       The dependencies listed with DEPENDS are ignored in this case.
 #   ADD_FAST_TARGET
 #     - In addition to creating <target>, create a secondary target
@@ -143,6 +136,8 @@ endfunction()
 #     - Passed to add_custom_command()/add_custom_target()
 #   COMMENT
 #     - Passed to add_custom_command()/add_custom_target()
+#   USES_TERMINAL
+#     - Passed to add_custom_command()/add_custom_target()
 #   DEPENDS
 #     - Dependencies passed to add_custom_command().  Any targets in this list
 #       that have been created with gmx_add_custom_output_target() are
@@ -176,7 +171,7 @@ function (gmx_add_custom_output_target targetname)
             set(_add_fast ON)
         elseif ("x${_arg}" MATCHES "^x(OUTPUT|DEPENDS|DEPENDS_FILE_LIST)$")
             set(_option ${_arg})
-        elseif ("x${_arg}" MATCHES "^x(COMMAND|COMMENT|WORKING_DIRECTORY)$")
+        elseif ("x${_arg}" MATCHES "^x(COMMAND|COMMENT|WORKING_DIRECTORY|USES_TERMINAL)$")
             set(_option "PASS")
             list(APPEND _command_args "${_arg}")
         elseif ("x${_option}" STREQUAL "xDEPENDS")
@@ -214,37 +209,12 @@ function (gmx_add_custom_output_target targetname)
     endif()
     # Create the actual command as requested.
     if (NOT _always)
-        # If the command does not need to run always, the standard CMake
-        # mechanism is sufficient.
         add_custom_command(OUTPUT ${_output}
             ${_command_args} DEPENDS ${_deps} VERBATIM)
         add_custom_target(${targetname} DEPENDS ${_output})
-    elseif (CMAKE_GENERATOR STREQUAL "Ninja")
-        # Ninja requires all generated files mentioned in dependencies of custom
-        # commands to be actually mentioned in the build system, and luckily
-        # add_custom_command() makes that possible.
-        # But it seems impossible to create a robust custom command that would be
-        # always run, so other generators that do not have this constraint simply
-        # use an add_custom_target().
-        #
-        # The second, phony file is never created, so the rule is always
-        # triggered again.  TODO: Figure out why this works, even though ninja
-        # very eagerly complains about missing files.
-        # This unfortunately does not work with the make generator, as
-        # the non-existent second file causes some part of the generated system
-        # erase the first file at the beginning of every build, causing a full
-        # rebuild of the dependencies.
-        add_custom_command(OUTPUT ${_output} ${targetname}-phony
-            ${_command_args} VERBATIM)
-        # The generated Ninja build system would probably work fine even
-        # without this target, but CMake requires all custom commands to belong
-        # to a target in the same CMakeLists.txt to generate anything for them.
-        add_custom_target(${targetname} DEPENDS ${_output})
     else()
-        # For other generators, a target-level dependency on the custom target
-        # ensures that the output is created before the dependent targets'
-        # dependencies are even evaluated.
-        add_custom_target(${targetname} ${_command_args} VERBATIM)
+        add_custom_target(${targetname} BYPRODUCTS ${_output}
+            ${_command_args} VERBATIM)
     endif()
     # Store the output file name in a custom property to be used in dependency
     # resolution later.
index 6a4b9619ef1bb045711dec147e9fb2822f3b9a4f..44ffa8197828e9a36ab568fe663fca59cbcc3a08 100644 (file)
 # The main interface to this machinery is the gmx_configure_version_file()
 # CMake function.  The signature is
 #   gmx_configure_version_file(<input> <output>
-#                              [REMOTE_HASH] [SOURCE_FILE]
+#                              [REMOTE_HASH]
 #                              [TARGET <target>]
 #                              [COMMENT <comment>])
 #   <input>      Specify the input and output files as for configure_file().
 #                This variable is much more expensive to initialize than the
 #                others, so this allows local changes in this file to only
 #                compute that value when required if that becomes necessary.
-#   SOURCE_FILE  Signals that <output> will be used as a source file.
-#                The function will set properties for the source file
-#                appropriately to signify that it is generated.
 #   TARGET       By default, this function uses add_custom_command() to
 #                generate the output file.  If TARGET is specified, then
 #                add_custom_target() is used to create a target with the given
@@ -224,12 +221,12 @@ if (NOT SOURCE_IS_SOURCE_DISTRIBUTION AND NOT GMX_BUILD_TARBALL)
 endif()
 
 set(REGRESSIONTEST_VERSION "${GMX_VERSION_STRING}")
-set(REGRESSIONTEST_BRANCH "refs/heads/release-2016")
+set(REGRESSIONTEST_BRANCH "refs/heads/master")
 # TODO Find some way of ensuring that this is bumped appropriately for
 # each release. It's hard to test because it is only used for
 # REGRESSIONTEST_DOWNLOAD, which doesn't work until that tarball has
 # been placed on the server.
-set(REGRESSIONTEST_MD5SUM "366438549270d005fa6def6e56ca0256" CACHE INTERNAL "MD5 sum of the regressiontests tarball")
+set(REGRESSIONTEST_MD5SUM "366438549270d005fa6def6e56ca0256")
 
 math(EXPR GMX_VERSION_NUMERIC
      "${GMX_VERSION_MAJOR}*10000 + ${GMX_VERSION_PATCH}")
@@ -350,7 +347,7 @@ unset(GMX_VERSION_CENTRAL_BASE_HASH)
 # See documentation at the top of the script.
 function (gmx_configure_version_file INFILE OUTFILE)
     include(CMakeParseArguments)
-    set(_options REMOTE_HASH SOURCE_FILE)
+    set(_options REMOTE_HASH)
     set(_one_value_args COMMENT TARGET)
     set(_multi_value_args EXTRA_VARS)
     cmake_parse_arguments(
@@ -392,7 +389,4 @@ function (gmx_configure_version_file INFILE OUTFILE)
         add_custom_target(${ARG_TARGET} DEPENDS ${OUTFILE} VERBATIM)
         gmx_set_custom_target_output(${ARG_TARGET} ${OUTFILE})
     endif()
-    if (ARG_SOURCE_FILE)
-        set_source_files_properties(${OUTFILE} PROPERTIES GENERATED true)
-    endif()
 endfunction()
index 50d5460e3fdb95a6c5e561e20197939cc221c690..3ce003eed2c41a5ee012a82a42ebfaac104e3ebb 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by
+# Copyright (c) 2012,2013,2014,2015,2016, 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.
@@ -144,7 +144,7 @@ if (DOXYGEN_FOUND)
             COMMAND ${CMAKE_COMMAND} -DDOCTYPE=${TYPE} -P RunDoxygen.cmake
             DEPENDS ${_deps}
             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-            COMMENT "${COMMENT}")
+            COMMENT "${COMMENT}" USES_TERMINAL)
         if (_fast_arg)
             add_dependencies(${TARGET}-fast doxygen-version)
         endif()
@@ -171,7 +171,8 @@ if (DOXYGEN_FOUND)
                 ${CMAKE_CURRENT_SOURCE_DIR}/gmxtree.py
                 ${CMAKE_CURRENT_SOURCE_DIR}/graphbuilder.py
                 ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt
-            COMMENT "Generating include dependency graphs for dot")
+            COMMENT "Generating include dependency graphs for dot"
+            USES_TERMINAL)
 
         # Add separate targets for converting the .dot files to .png.
         # These are not needed by the Doxygen targets, but are useful for
@@ -212,9 +213,9 @@ if (DOXYGEN_FOUND)
             --ignore ${CMAKE_CURRENT_SOURCE_DIR}/suppressions.txt
             --ignore-cycles ${CMAKE_CURRENT_SOURCE_DIR}/cycle-suppressions.txt)
         add_custom_target(check-source      COMMAND ${check_source_command}
-            COMMENT "Checking source code for various issues" VERBATIM)
+            COMMENT "Checking source code for various issues" VERBATIM USES_TERMINAL)
         add_custom_target(check-source-fast COMMAND ${check_source_command}
-            COMMENT "Checking source code for various issues" VERBATIM)
+            COMMENT "Checking source code for various issues" VERBATIM USES_TERMINAL)
         add_dependencies(check-source       doxygen-xml)
     endif()
 else()
index 6720381b35328b8e05ab8962a5897f6547aab4cf..271abfd1db4a3e9434232ed35d4d37b8e96b1b60 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.8)
+cmake_minimum_required(VERSION 3.4.3)
 
 project(template CXX)
 
index fcc693fd010d74be62076bf161f23cd8bb0c277c..be72d3df3793f6d21eb29cb611ea3ead99c16fdc 100644 (file)
@@ -146,7 +146,7 @@ gmx_install_headers(
 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
 gmx_configure_version_file(
     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
-    REMOTE_HASH SOURCE_FILE)
+    REMOTE_HASH)
 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
 
 if (GMX_USE_CUDA)
index 3cb38376ab165c6df6e8ae70b9f787cbff038b7a..d621cf4fb2c19ef68a38c9ee96745cf269075948 100644 (file)
@@ -40,7 +40,7 @@ add_custom_target(tests)
 add_custom_target(run-ctest
                   COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
                   COMMENT "Running all tests"
-                  VERBATIM)
+                  USES_TERMINAL VERBATIM)
 add_dependencies(run-ctest tests)
 # "check" target builds and runs all tests.
 add_custom_target(check DEPENDS run-ctest)