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