Reorganize CPack management
authorTeemu Murtola <teemu.murtola@gmail.com>
Tue, 23 Sep 2014 04:18:12 +0000 (07:18 +0300)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 23 Sep 2014 09:05:23 +0000 (11:05 +0200)
- Move all CPack variable setting to a separate file to reduce clutter
  in the main CMakeLists.txt.
- Move calling CPack to the end of the build system, since this allows
  gathering information for CPack from other parts.  Also some other
  CPack features (like identifying the existing components) works better
  there.
- Instead of hard-coding the generated directories to include in the
  source package, add a helper function that can be called from the code
  that actually does the generation.  This makes it a lot easier to
  understand how this works from just reading the CMake code.
- Add some TODOs for further improvements.

Change-Id: I2ca76f0f3b3e848527f2340b4aab1d62a5de8328

CMakeLists.txt
CPackInit.cmake
cmake/gmxCPackUtilities.cmake [new file with mode: 0644]
docs/install-guide/CMakeLists.txt
docs/man/CMakeLists.txt
docs/old-html/CMakeLists.txt
src/programs/CMakeLists.txt

index de857c316c04c2d689b733b1ab051926ff688ab2..65e4de501f18caba91db1a63e724f580c98b4cb8 100644 (file)
@@ -84,30 +84,6 @@ endif()
 set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBUGINFO RELWITHASSERT MINSIZEREL PROFILE)
 
 set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
-set(CPACK_PACKAGE_NAME "gromacs")
-set(CPACK_PACKAGE_VERSION_MAJOR ${GMX_VERSION_MAJOR})
-set(CPACK_PACKAGE_VERSION_MINOR ${GMX_VERSION_MINOR})
-set(CPACK_PACKAGE_VERSION_PATCH ${GMX_VERSION_PATCH})
-set(CPACK_PACKAGE_VERSION       ${GMX_VERSION_STRING})
-set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
-set(CPACK_PACKAGE_VENDOR "gromacs.org")
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
-set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
-# Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
-set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
-set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
-set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$;\\\\.gitattributes;")
-set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
-# CPack source archives include only the directories we list here.
-# This variable is a list of pairs of names of source and destination
-# directories. Most of these are used for content GROMACS generates as
-# 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}") #No longer works because GMX_BUILD_HELP is defined later.
-
-#must come after all cpack settings!
-include(CPack)
 
 # Set a default valgrind suppression file.
 # This unfortunately needs to duplicate information from CTest to work as
@@ -118,6 +94,9 @@ set(MEMORYCHECK_SUPPRESSIONS_FILE
     "File that contains suppressions for the memory checker")
 include(CTest)
 
+include(gmxCPackUtilities)
+gmx_cpack_init()
+
 # Variables that accumulate stuff influencing the installed headers
 set(INSTALLED_HEADER_INCLUDE_DIRS "")
 set(INSTALLED_HEADER_DEFINITIONS "")
@@ -875,6 +854,8 @@ if (BUILD_TESTING)
     add_subdirectory(tests)
 endif()
 
+gmx_cpack_write_config()
+
 # Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
 # Don't bother the user after the first configure pass.
 if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT GMX_GPU_DETECTION_DONE)
index 25046b8b562ec6948ea1dcb34773e36ec593595e..c7e7e3cc07064e64c671600f6a804dd0482ec34e 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.
 
-#TODO: add check that source doesn't contain any untracked files
-if(NOT CPACK_INSTALL_CMAKE_PROJECTS) #building source package
+set(BUILDING_SOURCE_PACKAGE OFF)
+# The essential difference in building a source package is that install() rules
+# from the CMake project are not considered when deciding what to package.
+# Instead, only the listed directories are packaged (and the listed directories
+# contain the source tree).
+if (NOT CPACK_INSTALL_CMAKE_PROJECTS)
+    set(BUILDING_SOURCE_PACKAGE ON)
+endif()
+
+if (BUILDING_SOURCE_PACKAGE)
+    # TODO: add check that source doesn't contain any untracked files
     get_filename_component(CMAKE_BINARY_DIR ${CPACK_OUTPUT_CONFIG_FILE} PATH)
+    # TODO: The list could be generated at the same time as the list of
+    # directories to include to keep the probe file names at the same place.
+    # And this does not detect if things have been built in the past, but are
+    # outdated.
     if (NOT EXISTS "${CMAKE_BINARY_DIR}/docs/man/man1/gmx-view.1" OR
         NOT EXISTS "${CMAKE_BINARY_DIR}/docs/install-guide/final/INSTALL" OR
         NOT EXISTS "${CMAKE_BINARY_DIR}/docs/old-html/final/online.html" OR
@@ -48,14 +61,18 @@ if(NOT CPACK_INSTALL_CMAKE_PROJECTS) #building source package
             "GMX_BUILD_HELP=ON to automatically build the HTML parts.")
     endif()
 else()
-    # 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()
+    # TODO: If GMX_BUILD_HELP is AUTO, it may happen that the generation fails,
+    # and things are silently left out.
+    # Also, it is currently impossible to get these files into the binary
+    # package for cross-compilation.  However, binary packages are not
+    # currently used much, either...
+    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()
diff --git a/cmake/gmxCPackUtilities.cmake b/cmake/gmxCPackUtilities.cmake
new file mode 100644 (file)
index 0000000..bf22099
--- /dev/null
@@ -0,0 +1,134 @@
+#
+# 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.
+
+# Helper functions to encapsulate and modularize usage of CPack
+#
+# This file is intended to be the only place that directly sets CPack variables
+# (in gmx_cpack_write_config()), and other parts of the build system should
+# only call the functions declared here to set up the packaging.
+
+# Initialize the machinery that collects CPack information during other
+# build system generation
+#
+# This function should be called before other functions from this file.
+function (gmx_cpack_init)
+    # Add the source tree to the source package.
+    # If we would not set CPACK_SOURCE_INSTALLED_DIRECTORIES, this is what
+    # CPack would set as default.
+    set_property(GLOBAL PROPERTY GMX_CPACK_SOURCE_INSTALLED_DIRECTORIES
+        ${PROJECT_SOURCE_DIR} /)
+endfunction()
+
+# Add a generated directory to be included in the source package.
+#
+# Usage:
+#   gmx_cpack_add_generated_source_directory(<dir> [DESTINATION <dest>])
+#
+#   <dir>   Name of directory to include.
+#           Relative paths are interpreted relative to current build dir.
+#   <dest>  Path in the source package where files from <dir> will be put.
+#           If not set, the files are put in the corresponding location in
+#           the source tree.
+#
+# By default, CPack source archives includes all files from the source tree.
+# This function adds a directory from the build tree to be packaged into the
+# source archive.  These are used for content GROMACS generates as part of the
+# configuration or build.
+# The values end up in CPACK_SOURCE_INSTALLED_DIRECTORIES, which is a list of
+# pairs of names of source and destination directories.
+function (gmx_cpack_add_generated_source_directory DIR)
+    include(CMakeParseArguments)
+    set(_one_value_args DESTINATION)
+    cmake_parse_arguments(ARG "" "${_one_value_args}" "" ${ARGN})
+    if (ARG_UNPARSED_ARGUMENTS)
+        message(FATAL_ERROR "Unknown arguments: ${ARG_UNPARSED_ARGUMENTS}")
+    endif()
+    set(_dir ${DIR})
+    if (NOT IS_ABSOLUTE ${_dir})
+        set(_dir ${CMAKE_CURRENT_BINARY_DIR}/${_dir})
+    endif()
+    if (ARG_DESTINATION)
+        set(_dest ${ARG_DESTINATION})
+    else()
+        file(RELATIVE_PATH _dest ${PROJECT_BINARY_DIR} ${_dir})
+    endif()
+    set_property(GLOBAL APPEND PROPERTY GMX_CPACK_SOURCE_INSTALLED_DIRECTORIES
+        ${_dir} ${_dest})
+endfunction()
+
+# Write CPack configuration files
+#
+# This function should be called at the end of the main CMakeLists.txt, after
+# all other calls to functions in this file.
+# CPack also automatically populates the list of components based on components
+# used in installation rules, so it should come after all install() commands.
+function (gmx_cpack_write_config)
+    # Set basic package information.
+    set(CPACK_PACKAGE_NAME    "gromacs")
+    set(CPACK_PACKAGE_VENDOR  "gromacs.org")
+    set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
+    set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
+        "Gromacs - a toolkit for high-performance molecular simulation")
+    # Set version info.
+    set(CPACK_PACKAGE_VERSION_MAJOR ${GMX_VERSION_MAJOR})
+    set(CPACK_PACKAGE_VERSION_MINOR ${GMX_VERSION_MINOR})
+    set(CPACK_PACKAGE_VERSION_PATCH ${GMX_VERSION_PATCH})
+    set(CPACK_PACKAGE_VERSION       ${GMX_VERSION_STRING})
+    # Add various text resources for some installers.
+    set(CPACK_RESOURCE_FILE_WELCOME "${PROJECT_SOURCE_DIR}/admin/InstallWelcome.txt")
+    # Its GPL/LGPL, so they do not have to agree to a license for mere usage,
+    # but some installers require this...
+    set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING")
+    set(CPACK_RESOURCE_FILE_README  "${PROJECT_SOURCE_DIR}/admin/InstallInfo.txt")
+
+    # Our custom config file that is run by CPack for each generator, used to
+    # check for prerequisites of the packaging.
+    set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/CPackInit.cmake")
+
+    # Settings specific to source packages.
+    set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
+    set(CPACK_SOURCE_IGNORE_FILES
+        "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$;\\\\.gitattributes;")
+    # Get the list of directories added with gmx_cpack_add_generated_source_directory()
+    get_property(CPACK_SOURCE_INSTALLED_DIRECTORIES
+        GLOBAL PROPERTY GMX_CPACK_SOURCE_INSTALLED_DIRECTORIES)
+
+    # Propagate additional values for CPackInit.cmake to use.
+    # CPack includes all variables starting with CPACK_ into the generated
+    # config files that are included by CPack.
+    set(CPACK_GMX_BUILD_HELP "${GMX_BUILD_HELP}")
+
+    # Generate the CPack configuration files.
+    include(CPack)
+endfunction()
index 7342ba4d7100f30a485b0400a58bcda67656c8ba..8b3eed92dba3195728a8b80e0015baee5baeb0b2 100644 (file)
@@ -60,4 +60,5 @@ if(MARKDOWN_CONFIGURE_IS_POSSIBLE AND PANDOC_EXECUTABLE)
             ${HTML_OUTPUT_DIR}/${name}.pdf
         VERBATIM
         )
+    gmx_cpack_add_generated_source_directory(final DESTINATION /)
 endif()
index 456b59cf3fa06f812f6c737a2de844d2d69cf2b3..be9241498346e37a07c2e91c29908ec39004787a 100644 (file)
@@ -62,3 +62,5 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP)
         DESTINATION ${MAN_INSTALL_DIR}
         COMPONENT man OPTIONAL)
 endif()
+gmx_cpack_add_generated_source_directory(man1)
+gmx_cpack_add_generated_source_directory(man7)
index 1b9b12e41a4d9428d2431c1ae599f93801b897f7..2b119f9afcc9d5a733267d1717386b6d92032ac9 100644 (file)
@@ -75,3 +75,4 @@ if (SOURCE_IS_SOURCE_DISTRIBUTION OR GMX_BUILD_HELP_FORCE)
         DESTINATION ${DATA_INSTALL_DIR}/html
         COMPONENT html)
 endif()
+gmx_cpack_add_generated_source_directory(${OUTPUT_DIR})
index 1b6c4518cd978e3370eb920d49522ddace8f9b65..d4643c9d94856b1687b9bdad30c371507fb71585 100644 (file)
@@ -107,6 +107,7 @@ else()
         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gmx-completion-${BINARY_NAME}.bash
                 DESTINATION ${BIN_INSTALL_DIR} COMPONENT runtime)
     endif()
+    gmx_cpack_add_generated_source_directory(completion)
 
     if (GMX_SYMLINK_OLD_BINARY_NAMES)
         configure_file(CreateLinks.cmake.cmakein CreateLinks.cmake @ONLY)