Fix nblib flags
[alexxy/gromacs.git] / cmake / gmxGenerateVersionInfoWithoutGit.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2020, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 # Generate GROMACS release build version information, as well as build
36 # directory integrity checking.
37
38 # This script generates version information for a build from a release tarball
39 # source tree based on the release information in the released tarball.
40 # It is assumed that by default the script is run in cmake script mode.
41 # If *not* called in script mode but used in generating cache variables,
42 # GEN_VERSION_INFO_INTERNAL has to be set ON.
43 #
44 # The following variables have to be previously defined:
45 # PROJECT_VERSION         - hard-coded version string (generated info is appended)
46 # PROJECT_SOURCE_DIR      - top level source directory
47 # DIRECTORIES_TO_CHECKSUM - List of directories to hash
48 # VERSION_CMAKEIN         - path to an input template file
49 # VERSION_OUT             - path to the output file
50 #
51 # The following a possible additional definitions
52 # PYTHON_EXECUTABLE       - Needed to run checking stage of current tree
53 # VERSION_STRING_OF_FORK  - Possibly defined custom version string to override
54 #                          process of checking source file hashes.
55 # Output:
56 # VERSION_OUT is configured from the input VERSION_CMAKEIN
57 # using the variables listed below.
58 #
59 # GMX_VERSION_STRING_FULL       - version string
60 # GMX_RELEASE_SOURCE_FILE_CHECKSUM - Sha256 hash of source tree files at release
61 # GMX_CURRENT_SOURCE_FILE_CHECKSUM - Sha256 hash of current source tree files
62 #
63 # Paul Bauer (paul.bauer.q@gmail.com)
64 # (authors of git Version of the script that this is based on below)
65 # Szilard Pall (pszilard@cbr.su.se)
66 # Teemu Murtola (teemu.murtola@gmail.com)
67
68 # Check input variables.
69 if("${PROJECT_VERSION}" STREQUAL "")
70     message(FATAL_ERROR "PROJECT_VERSION undefined!")
71 endif()
72 if (NOT EXISTS "${PROJECT_SOURCE_DIR}")
73     message(FATAL_ERROR "Project source directory ${PROJECT_SOURCE_DIR} does not exist")
74 endif()
75 if ("${DIRECTORIES_TO_CHECKSUM}" STREQUAL "")
76     message(FATAL_ERROR "Need list of directories to generate the hash for")
77 endif()
78 if ("${VERSION_CMAKEIN}" STREQUAL "")
79     message(FATAL_ERROR "Missing input parameter VERSION_CMAKEIN!")
80 endif()
81 if ("${VERSION_OUT}" STREQUAL "")
82     message(FATAL_ERROR "Missing input parameter VERSION_OUT!")
83 endif()
84
85 # Prepare version string to populate
86 set(GMX_VERSION_STRING_FULL          ${PROJECT_VERSION})
87
88 # We had to pass the directory list as a string, so now we convert it back to a list
89 string(REPLACE ":" ";" DIRECTORIES_TO_CHECKSUM_LIST ${DIRECTORIES_TO_CHECKSUM})
90
91 # We need the full path to the directories after passing it through
92 set(FULL_PATH_DIRECTORIES "")
93 foreach(DIR ${DIRECTORIES_TO_CHECKSUM_LIST})
94     list(APPEND FULL_PATH_DIRECTORIES "${PROJECT_SOURCE_DIR}/${DIR}")
95 endforeach()
96
97 # Change path depending on if this is a source distribution (e.g. release tarball)
98 # or just a source directory that is managed by something else, like an IDE.
99 # If the git executable isn't found by CMake, there will not be version info even
100 # if the .git folder is present and SOURCE_IS_GIT_REPOSITORY is true.
101 # Don't issue warnings in this case.
102 if (SOURCE_IS_SOURCE_DISTRIBUTION)
103     # Prepare for checking source tree file hashes.
104     # To notify the user during compilation and at runtime that the build source
105     # has not been modified after unpacking the source tarball, the contents are hashed
106     # to be compared to a hash computed during the release process. If the hash matches
107     # all is fine and the user gets a message in the log file indicating that.
108     # If either the release hash file is missing, or if the hash does not match
109     # a different message is printed to indicate that the source has been changed
110     # compared to the version actually released. This is not needed in case a build
111     # is done in git, as we have the information there already.
112     # This is not done if the user has explicitly set an additional custom version string with
113     # -DGMX_VERSION_STRING_OF_FORK, as this indicates that they are knowing that a custom
114     # version of GROMACS is in use.
115     set(RELEASE_CHECKSUM_FILE "${PROJECT_SOURCE_DIR}/src/reference_checksum")
116     if(NOT VERSION_STRING_OF_FORK OR "${VERSION_STRING_OF_FORK}" STREQUAL "")
117         if(EXISTS ${RELEASE_CHECKSUM_FILE} AND PYTHON_EXECUTABLE)
118             file(READ ${RELEASE_CHECKSUM_FILE} GMX_RELEASE_SOURCE_FILE_CHECKSUM)
119             string(STRIP ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} GMX_RELEASE_SOURCE_FILE_CHECKSUM)
120             set(CHECKSUM_RESULT_FILE "${CMAKE_CURRENT_BINARY_DIR}/computed_checksum")
121             execute_process(COMMAND ${PYTHON_EXECUTABLE}
122                                     ${PROJECT_SOURCE_DIR}/admin/createFileHash.py
123                                     -s ${FULL_PATH_DIRECTORIES}
124                                     -o ${CHECKSUM_RESULT_FILE}
125                             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
126                             OUTPUT_QUIET)
127                         file(READ ${CHECKSUM_RESULT_FILE} GMX_CURRENT_SOURCE_FILE_CHECKSUM)
128             string(STRIP ${GMX_CURRENT_SOURCE_FILE_CHECKSUM} GMX_CURRENT_SOURCE_FILE_CHECKSUM)
129             if(NOT ${GMX_RELEASE_SOURCE_FILE_CHECKSUM} STREQUAL ${GMX_CURRENT_SOURCE_FILE_CHECKSUM})
130                 set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-MODIFIED")
131                 message(STATUS "The source code for this GROMACS installation is different from the officially released version.")
132             endif()
133         elseif(PYTHON_EXECUTABLE)
134             set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED")
135             set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoChecksumFile")
136             set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoChecksumFile")
137             message(WARNING "Could not valdiate the GROMACS source due to missing reference checksum file.")
138         else()
139             set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED")
140             set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NoPythonAvailable")
141             set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NoPythonAvailable")
142             message(STATUS "Could not calculate checksum of source files without Python")
143         endif()
144     endif()
145 else()
146     set(GMX_VERSION_STRING_FULL "${GMX_VERSION_STRING_FULL}-UNCHECKED")
147     set(GMX_RELEASE_SOURCE_FILE_CHECKSUM "NotSourceDistribution")
148     set(GMX_CURRENT_SOURCE_FILE_CHECKSUM "NotSourceDistribution")
149     message(STATUS "Build without git or source information")
150 endif()
151
152 # Generate the output file.
153 configure_file(${VERSION_CMAKEIN} ${VERSION_OUT})