Work around false xlc-13.1.5 bug in SIMD test
[gromacs.git] / cmake / gmxSetBuildInformation.cmake
blob52b60c3ea0a8a65558c1c5149f8d0aa5c781b51b
2 # This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
35 # - Check the username performing the build, as well as date and time
37 # gmx_set_build_information()
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)
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
53 # we rely on inline asm support for GNU!
54 include(gmxTestInlineASM)
56 macro(gmx_set_build_information)
57     IF(NOT DEFINED BUILD_USER)
59     gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
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()
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()
84     # Set up some defaults that will usually be overridden
85     if(CMAKE_CROSSCOMPILING)
86         set(_reason ", cross-compiled")
87     endif()
88     set(OUTPUT_CPU_VENDOR   "Unknown${_reason}")
89     set(OUTPUT_CPU_BRAND    "Unknown${_reason}")
90     set(OUTPUT_CPU_FAMILY   "0")
91     set(OUTPUT_CPU_MODEL    "0")
92     set(OUTPUT_CPU_STEPPING "0")
93     set(OUTPUT_CPU_FEATURES "Unknown${_reason}")
94     unset(_reason)
96     if(NOT CMAKE_CROSSCOMPILING)
97         # Get CPU information, e.g. for deciding what SIMD support probably exists
98         if(GMX_TARGET_X86)
99             set(GMX_TARGET_X86_VALUE 1)
100         else()
101             set(GMX_TARGET_X86_VALUE 0)
102         endif()
103         set(_compile_definitions "${GCC_INLINE_ASM_DEFINE} -I${CMAKE_SOURCE_DIR}/src -DGMX_CPUINFO_STANDALONE ${GMX_STDLIB_CXX_FLAGS} -DGMX_TARGET_X86=${GMX_TARGET_X86_VALUE}")
105         set(GMX_BUILDINFORMATION_BINARY "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/GmxBuildInformation${CMAKE_EXECUTABLE_SUFFIX}")
106         set(LINK_LIBRARIES "${GMX_STDLIB_LIBRARIES}")
107         # TODO Extract this try_compile to a helper function, because
108         # it duplicates code in gmxDetectSimd.cmake
109         try_compile(GMX_BUILDINFORMATION_COMPILED
110             "${CMAKE_CURRENT_BINARY_DIR}"
111             "${CMAKE_CURRENT_SOURCE_DIR}/src/gromacs/hardware/cpuinfo.cpp"
112             COMPILE_DEFINITIONS "${_compile_definitions}"
113             CMAKE_FLAGS "-DLINK_LIBRARIES=${LINK_LIBRARIES}"
114             OUTPUT_VARIABLE GMX_BUILDINFORMATION_COMPILED_OUTPUT
115             COPY_FILE ${GMX_BUILDINFORMATION_BINARY})
116         unset(_compile_definitions)
118         if(GMX_BUILDINFORMATION_COMPILED)
119             # TODO Extract this duplication to a helper function (also
120             # from gmxDetectSimd.cmake)
121             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_VENDOR)
122                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-vendor"
123                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_VENDOR
124                     OUTPUT_VARIABLE OUTPUT_TMP
125                     ERROR_QUIET)
126                 set(GMX_BUILDINFORMATION_RUN_VENDOR "${GMX_BUILDINFORMATION_RUN_VENDOR}" CACHE INTERNAL "Result of running cpuinfo code with arg -vendor")
127                 if(GMX_BUILDINFORMATION_RUN_VENDOR EQUAL 0)
128                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_VENDOR)
129                 endif()
130             endif()
131             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_BRAND)
132                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-brand"
133                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_BRAND
134                     OUTPUT_VARIABLE OUTPUT_TMP
135                     ERROR_QUIET)
136                 set(GMX_BUILDINFORMATION_RUN_BRAND "${GMX_BUILDINFORMATION_RUN_BRAND}" CACHE INTERNAL "Result of running cpuinfo code with arg -brand")
137                 if(GMX_BUILDINFORMATION_RUN_BRAND EQUAL 0)
138                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_BRAND)
139                 endif()
140             endif()
141             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_FAMILY)
142                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-family"
143                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_FAMILY
144                     OUTPUT_VARIABLE OUTPUT_TMP
145                     ERROR_QUIET)
146                 set(GMX_BUILDINFORMATION_RUN_FAMILY "${GMX_BUILDINFORMATION_RUN_FAMILY}" CACHE INTERNAL "Result of running cpuinfo code with arg -family")
147                 if(GMX_BUILDINFORMATION_RUN_FAMILY EQUAL 0)
148                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_FAMILY)
149                 endif()
150             endif()
151             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_MODEL)
152                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-model"
153                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_MODEL
154                     OUTPUT_VARIABLE OUTPUT_TMP
155                     ERROR_QUIET)
156                 set(GMX_BUILDINFORMATION_RUN_MODEL "${GMX_BUILDINFORMATION_RUN_MODEL}" CACHE INTERNAL "Result of running cpuinfo code with arg -model")
157                 if(GMX_BUILDINFORMATION_RUN_MODEL EQUAL 0)
158                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_MODEL)
159                 endif()
160             endif()
161             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_STEPPING)
162                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-stepping"
163                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_STEPPING
164                     OUTPUT_VARIABLE OUTPUT_TMP
165                     ERROR_QUIET)
166                 set(GMX_BUILDINFORMATION_RUN_STEPPING "${GMX_BUILDINFORMATION_RUN_STEPPING}" CACHE INTERNAL "Result of running cpuinfo code with arg -stepping")
167                 if(GMX_BUILDINFORMATION_RUN_STEPPING EQUAL 0)
168                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_STEPPING)
169                 endif()
170             endif()
171             if(NOT DEFINED GMX_BUILDINFORMATION_RUN_FEATURES)
172                 execute_process(COMMAND ${GMX_BUILDINFORMATION_BINARY} "-features"
173                     RESULT_VARIABLE GMX_BUILDINFORMATION_RUN_FEATURES
174                     OUTPUT_VARIABLE OUTPUT_TMP
175                     ERROR_QUIET)
176                 set(GMX_BUILDINFORMATION_RUN_FEATURES "${GMX_BUILDINFORMATION_RUN_FEATURES}" CACHE INTERNAL "Result of running cpuinfo code with arg -features")
177                 if(GMX_BUILDINFORMATION_RUN_FEATURES EQUAL 0)
178                     string(STRIP "${OUTPUT_TMP}" OUTPUT_CPU_FEATURES)
179                 endif()
180             endif()
181         endif()
182     endif()
184     set(BUILD_CPU_VENDOR   "${OUTPUT_CPU_VENDOR}"   CACHE INTERNAL "Build CPU vendor")
185     set(BUILD_CPU_BRAND    "${OUTPUT_CPU_BRAND}"    CACHE INTERNAL "Build CPU brand")
186     set(BUILD_CPU_FAMILY   "${OUTPUT_CPU_FAMILY}"   CACHE INTERNAL "Build CPU family")
187     set(BUILD_CPU_MODEL    "${OUTPUT_CPU_MODEL}"    CACHE INTERNAL "Build CPU model")
188     set(BUILD_CPU_STEPPING "${OUTPUT_CPU_STEPPING}" CACHE INTERNAL "Build CPU stepping")
189     set(BUILD_CPU_FEATURES "${OUTPUT_CPU_FEATURES}" CACHE INTERNAL "Build CPU features")
191     ENDIF(NOT DEFINED BUILD_USER)
192 endmacro(gmx_set_build_information)