Re-add support for linking against external TinyXML-2
[alexxy/gromacs.git] / cmake / gmxSetBuildInformation.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013,2014,2015,2016, 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 # - Check the username performing the build, as well as date and time
36 #
37 # gmx_set_build_information()
38 #
39 # The macro variables will be set to the user/host/cpu used for configuration,
40 # or anonymous/unknown if it cannot be detected (windows)
41 #
42 # BUILD_TIME
43 # BUILD_USER
44 # BUILD_HOST
45 # BUILD_CPU_VENDOR
46 # BUILD_CPU_BRAND
47 # BUILD_CPU_FAMILY
48 # BUILD_CPU_MODEL
49 # BUILD_CPU_STEPPING
50 # BUILD_CPU_FEATURES
51 #
52
53 # we rely on inline asm support for GNU!
54 include(gmxTestInlineASM)
55
56 macro(gmx_set_build_information)
57     IF(NOT DEFINED BUILD_USER)
58
59     gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
60
61     if(GMX_X86_GCC_INLINE_ASM)
62         set(GCC_INLINE_ASM_DEFINE "-DGMX_X86_GCC_INLINE_ASM=1")
63     else()
64         set(GCC_INLINE_ASM_DEFINE "-DGMX_X86_GCC_INLINE_ASM=0")
65     endif()
66
67     message(STATUS "Setting build user/date/host/cpu information")
68     if(CMAKE_HOST_UNIX)
69         execute_process( COMMAND date     OUTPUT_VARIABLE TMP_TIME    OUTPUT_STRIP_TRAILING_WHITESPACE)
70         execute_process( COMMAND whoami   OUTPUT_VARIABLE TMP_USER       OUTPUT_STRIP_TRAILING_WHITESPACE)
71         execute_process( COMMAND hostname OUTPUT_VARIABLE TMP_HOSTNAME   OUTPUT_STRIP_TRAILING_WHITESPACE)
72         set(BUILD_USER    "${TMP_USER}\@${TMP_HOSTNAME} [CMAKE]" CACHE INTERNAL "Build user")
73         set(BUILD_TIME    "${TMP_TIME}" CACHE INTERNAL "Build date & time")
74         execute_process( COMMAND uname -srm OUTPUT_VARIABLE TMP_HOST OUTPUT_STRIP_TRAILING_WHITESPACE)
75         set(BUILD_HOST    "${TMP_HOST}" CACHE INTERNAL "Build host & architecture")
76         message(STATUS "Setting build user & time - OK")
77     else()
78         set(BUILD_USER    "Anonymous\@unknown [CMAKE]" CACHE INTERNAL "Build user")
79         set(BUILD_TIME    "Unknown date" CACHE INTERNAL "Build date & time")
80         set(BUILD_HOST    "${CMAKE_HOST_SYSTEM} ${CMAKE_HOST_SYSTEM_PROCESSOR}" CACHE INTERNAL "Build host & architecture")
81         message(STATUS "Setting build user & time - not on Unix, using anonymous")
82     endif()
83
84     if(NOT CMAKE_CROSSCOMPILING)
85         # Get CPU information, e.g. for deciding what SIMD support exists
86         set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE")
87         try_run(GMX_CPUINFO_RUN_VENDOR GMX_CPUINFO_COMPILED
88             ${CMAKE_BINARY_DIR}
89             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
90             COMPILE_DEFINITIONS ${_compile_definitions}
91             RUN_OUTPUT_VARIABLE OUTPUT_CPU_VENDOR ARGS "-vendor")
92         try_run(GMX_CPUINFO_RUN_BRAND GMX_CPUINFO_COMPILED
93             ${CMAKE_BINARY_DIR}
94             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
95             COMPILE_DEFINITIONS ${_compile_definitions}
96             RUN_OUTPUT_VARIABLE OUTPUT_CPU_BRAND ARGS "-brand")
97         try_run(GMX_CPUINFO_RUN_FAMILY GMX_CPUINFO_COMPILED
98             ${CMAKE_BINARY_DIR}
99             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
100             COMPILE_DEFINITIONS ${_compile_definitions}
101             RUN_OUTPUT_VARIABLE OUTPUT_CPU_FAMILY ARGS "-family")
102         try_run(GMX_CPUINFO_RUN_MODEL GMX_CPUINFO_COMPILED
103             ${CMAKE_BINARY_DIR}
104             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
105             COMPILE_DEFINITIONS ${_compile_definitions}
106             RUN_OUTPUT_VARIABLE OUTPUT_CPU_MODEL ARGS "-model")
107        try_run(GMX_CPUINFO_RUN_STEPPING GMX_CPUINFO_COMPILED
108             ${CMAKE_BINARY_DIR}
109             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
110             COMPILE_DEFINITIONS ${_compile_definitions}
111             RUN_OUTPUT_VARIABLE OUTPUT_CPU_STEPPING ARGS "-stepping")
112         try_run(GMX_CPUINFO_RUN_FEATURES GMX_CPUINFO_COMPILED
113             ${CMAKE_BINARY_DIR}
114             ${CMAKE_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp
115             COMPILE_DEFINITIONS ${_compile_definitions}
116             RUN_OUTPUT_VARIABLE OUTPUT_CPU_FEATURES ARGS "-features")
117         unset(_compile_definitions)
118
119         string(STRIP "${OUTPUT_CPU_VENDOR}" OUTPUT_CPU_VENDOR)
120         string(STRIP "${OUTPUT_CPU_BRAND}" OUTPUT_CPU_BRAND)
121         string(STRIP "${OUTPUT_CPU_FAMILY}" OUTPUT_CPU_FAMILY)
122         string(STRIP "${OUTPUT_CPU_MODEL}" OUTPUT_CPU_MODEL)
123         string(STRIP "${OUTPUT_CPU_STEPPING}" OUTPUT_CPU_STEPPING)
124         string(STRIP "${OUTPUT_CPU_FEATURES}" OUTPUT_CPU_FEATURES)
125
126         if(GMX_CPUINFO_RUN_VENDOR EQUAL 0)
127             set(BUILD_CPU_VENDOR   "${OUTPUT_CPU_VENDOR}"   CACHE INTERNAL "Build CPU vendor")
128         else()
129             set(BUILD_CPU_VENDOR   "Unknown, detect failed" CACHE INTERNAL "Build CPU vendor")
130         endif()
131         if(GMX_CPUINFO_RUN_BRAND EQUAL 0)
132             set(BUILD_CPU_BRAND    "${OUTPUT_CPU_BRAND}"    CACHE INTERNAL "Build CPU brand")
133         else()
134             set(BUILD_CPU_BRAND    "Unknown, detect failed" CACHE INTERNAL "Build CPU brand")
135         endif()
136         if(GMX_CPUINFO_RUN_FAMILY EQUAL 0)
137             set(BUILD_CPU_FAMILY   "${OUTPUT_CPU_FAMILY}"   CACHE INTERNAL "Build CPU family")
138         else()
139             set(BUILD_CPU_FAMILY   "0"                     CACHE INTERNAL "Build CPU family")
140         endif()
141         if(GMX_CPUINFO_RUN_MODEL EQUAL 0)
142             set(BUILD_CPU_MODEL    "${OUTPUT_CPU_MODEL}"    CACHE INTERNAL "Build CPU model")
143         else()
144             set(BUILD_CPU_MODEL    "0"                     CACHE INTERNAL "Build CPU model")
145         endif()
146         if(GMX_CPUINFO_RUN_STEPPING EQUAL 0)
147             set(BUILD_CPU_STEPPING "${OUTPUT_CPU_STEPPING}" CACHE INTERNAL "Build CPU stepping")
148         else()
149             set(BUILD_CPU_STEPPING "0"                     CACHE INTERNAL "Build CPU stepping")
150         endif()
151             if(GMX_CPUINFO_RUN_FEATURES EQUAL 0)
152             set(BUILD_CPU_FEATURES "${OUTPUT_CPU_FEATURES}" CACHE INTERNAL "Build CPU features")
153         else()
154             set(BUILD_CPU_FEATURES ""                      CACHE INTERNAL "Build CPU features")
155         endif()
156
157     else()
158
159         set(BUILD_CPU_VENDOR   "Unknown, cross-compiled"   CACHE INTERNAL "Build CPU vendor")
160         set(BUILD_CPU_BRAND    "Unknown, cross-compiled"    CACHE INTERNAL "Build CPU brand")
161         set(BUILD_CPU_FAMILY   "0"   CACHE INTERNAL "Build CPU family")
162         set(BUILD_CPU_MODEL    "0"    CACHE INTERNAL "Build CPU model")
163         set(BUILD_CPU_STEPPING "0" CACHE INTERNAL "Build CPU stepping")
164         set(BUILD_CPU_FEATURES "" CACHE INTERNAL "Build CPU features")
165
166     endif()
167
168     ENDIF(NOT DEFINED BUILD_USER)
169 endmacro(gmx_set_build_information)