bd215f959014f28786f68983ef2c289dde5b62db
[alexxy/gromacs.git] / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012, 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 cmake_minimum_required(VERSION 2.8)
36 # Keep CMake suitably quiet on Cygwin
37 set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
38
39 # Allows CPack to act differently for normal tools and mdrun (e.g. because of MPI)
40 set(CPACK_COMPONENT_GROUP_TOOLS_DESCRIPTION "All GROMACS executable tools")
41 set(CPACK_COMPONENT_GROUP_MDRUN_DESCRIPTION "GROMACS executable for running simulations")
42
43 # override bugs on OS X where Cmake picks gcc (GNU) for C instead of system default cc (Clang).
44 if(APPLE)
45     set(CMAKE_C_COMPILER_INIT "cc")
46 endif(APPLE)
47
48 project(Gromacs C)
49 include(Dart)
50 mark_as_advanced(DART_ROOT)
51
52 # PROJECT_VERSION should have the following structure: 
53 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
54 #
55 # The "-dev" suffix is important to keep because it makes possible to distinguish 
56 # between a build from official release and a build from git release branch on a 
57 # machine with no git. 
58 #
59 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
60 set(PROJECT_VERSION "4.6-beta1-dev")
61 set(CUSTOM_VERSION_STRING ""
62     CACHE STRING "Custom version string (if empty, use hard-coded default)")
63 mark_as_advanced(CUSTOM_VERSION_STRING)
64 if (CUSTOM_VERSION_STRING)
65     set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
66 endif (CUSTOM_VERSION_STRING)
67 set(SOVERSION 6)
68 # It is a bit irritating, but this has to be set separately for now!
69 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
70 SET(CPACK_PACKAGE_VERSION_MINOR "6")
71 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
72
73 # The numerical gromacs version. It is 40600 for 4.6.0.
74 # The #define GMX_VERSION in gmx_header_config_h is set to this value.
75 math(EXPR NUM_VERSION 
76     "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
77 if(CPACK_PACKAGE_VERSION_PATCH)
78     math(EXPR NUM_VERSION 
79          "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
80 endif()
81
82 # The API version tracks the numerical Gromacs version (for now).
83 # It is potentially different from the Gromacs version in the future, if
84 # the programs/libraries diverge from the presumably more stable API.
85 # The #define GMX_API_VERSION in version.h is set to this value to
86 # provide backward compatibility of software written against the Gromacs API.
87 set(API_VERSION ${NUM_VERSION})
88
89 # Cmake modules/macros are in a subdirectory to keep this file cleaner
90 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
91
92 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
93 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
94 endif()
95
96 include(gmxBuildTypeReference)
97
98 if(NOT CMAKE_BUILD_TYPE)
99     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
100 endif(NOT CMAKE_BUILD_TYPE)
101
102 enable_language(C)
103
104 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
105 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
106
107 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
108 set(CPACK_PACKAGE_VENDOR "gromacs.org")
109 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
110 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
111     set(CPACK_SET_DESTDIR "ON")
112 endif()
113 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
114 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
115 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
116 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
117 set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$")
118 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
119 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
120 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
121
122 #must come after all cpack settings!
123 include(CPack)
124
125 ########################################################################
126 # Check and warn if cache generated on a different host is being reused
127 ########################################################################
128 if(CMAKE_HOST_UNIX)
129     execute_process(COMMAND hostname
130                     OUTPUT_VARIABLE TMP_HOSTNAME
131                     OUTPUT_STRIP_TRAILING_WHITESPACE)
132     if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
133         message(WARNING "
134             The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
135             is being reused! This could lead to inconsitencies; therefore, it is
136             recommended to regenerate the cache!")
137     endif()
138     set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
139             "Hostname of the machine where the cache was generated.")
140 endif()
141
142 ########################################################################
143 # User input options - enable C++ - before any CXX flags are changed   #
144 ########################################################################
145
146 # decide on GPU settings based on user-settings and GPU/CUDA detection
147 include(gmxManageGPU)
148
149 # TODO: move OpenMM to contrib
150 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (not fully supported)" OFF)
151 mark_as_advanced(GMX_OPENMM)
152
153 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
154 mark_as_advanced(GMX_FORCE_CXX)
155
156 if(GMX_GPU OR GMX_OPENMM OR GMX_FORCE_CXX)
157     enable_language(CXX)
158 endif()
159 set(CMAKE_PREFIX_PATH "" CACHE STRING "Extra locations to search for external libraries and tools (give directory without lib, bin, or include)")
160
161 ########################################################################
162 # Fix stupid flags on Windows
163 ########################################################################
164 SET(SHARED_LIBS_DEFAULT ON) 
165 IF( WIN32 AND NOT CYGWIN)
166   if (NOT BUILD_SHARED_LIBS)
167     option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
168     mark_as_advanced(GMX_PREFER_STATIC_LIBS)
169     SET(SHARED_LIBS_DEFAULT OFF)
170   else()
171     add_definitions(-DUSE_VISIBILITY -DTMPI_USE_VISIBILITY)
172   endif()
173
174   IF (GMX_PREFER_STATIC_LIBS)
175     #Only setting Debug and Release flags. Others configurations current not used.
176     STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
177     SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
178     STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
179     SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
180     if(CMAKE_CXX_COMPILER_LOADED)
181         STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
182         SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
183         STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
184         SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
185     endif()
186   ENDIF()
187
188   #Workaround for cmake bug 13174. Replace deprecated options.
189   IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
190     STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
191     SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
192   ENDIF()
193   IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
194     STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
195     STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
196     SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
197
198     STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
199     SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
200   ENDIF()
201 ENDIF()
202
203
204 ########################################################################
205 # User input options                                                   #
206 ########################################################################
207 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
208 option(GMX_MPI    "Build a parallel (message-passing) version of GROMACS" OFF)
209 option(GMX_THREAD_MPI  "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
210 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
211 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
212 option(GMX_POWERPC_INVSQRT "Use PowerPC hardware 1/sqrt" OFF)
213 mark_as_advanced(GMX_POWERPC_INVSQRT)
214 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
215 mark_as_advanced(GMX_FAHCORE)
216
217 include(gmxDetectAcceleration)
218 if(NOT DEFINED GMX_CPU_ACCELERATION)
219     if(CMAKE_CROSSCOMPILING)
220         set(GMX_SUGGESTED_CPU_ACCELERATION "None")
221     else(CMAKE_CROSSCOMPILING)
222         gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
223     endif(CMAKE_CROSSCOMPILING)
224 endif(NOT DEFINED GMX_CPU_ACCELERATION)
225
226 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
227     CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene, Power6, Fortran")
228
229 set(GMX_FFT_LIBRARY "fftw3" 
230     CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
231 option(GMX_BUILD_OWN_FFTW "Download and build FFTW 3 during the GROMACS build process, rather than fall back on the really slow fftpack." OFF)
232 mark_as_advanced(GMX_BUILD_OWN_FFTW)
233 option(GMX_DISABLE_FFTW_MEASURE 
234        "Do not optimize FFTW setups (not needed with SSE)" OFF)
235 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
236 set(GMX_QMMM_PROGRAM "none" 
237     CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
238 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
239 mark_as_advanced(GMX_BROKEN_CALLOC)
240 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
241 mark_as_advanced(GMX_MPI_IN_PLACE)
242 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
243 mark_as_advanced(GMX_LOAD_PLUGINS)
244
245 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
246
247 option(USE_VERSION_H "Generate development version string/information" ON)
248 mark_as_advanced(USE_VERSION_H)
249
250 option(GMX_DEFAULT_SUFFIX "Use default suffixes for GROMACS binaries and libs (_d for double, _mpi for MPI; rerun cmake after changing to see relevant options)" ON)
251
252 if(UNIX)
253     option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static archives (not available on non-*nix platforms and it will only work if static versions of external dependencies are available and found)!" OFF)
254     mark_as_advanced(GMX_PREFER_STATIC_LIBS)
255 endif()
256
257 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
258 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
259
260 ######################################################################
261 # Compiler tests
262 # These need to be done early (before further tests).
263 #####################################################################
264
265 # The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
266 # are used with permission from CMake v2.8.9 so that GROMACS can detect
267 # invalid options with the Intel Compilers.
268 # These files should be removed from the source tree when a CMake version that
269 # includes the features in question becomes required for building GROMACS.
270 include(CheckCCompilerFlag)
271 if(CMAKE_CXX_COMPILER_LOADED)
272     include(CheckCXXCompilerFlag)
273 endif()
274
275 # OpenMP check must come before other CFLAGS!
276 if(GMX_OPENMP)
277     find_package(OpenMP)
278     if(OPENMP_FOUND)
279         # CMake on Windows doesn't support linker flags passed to target_link_libraries
280         # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed.
281         if(NOT (WIN32 AND NOT CYGWIN))
282             if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
283                 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
284                 set(OpenMP_SHARED_LINKER_FLAGS "")
285             else()
286                 # Only set a linker flag if the user didn't set them manually
287                 if(NOT DEFINED OpenMP_LINKER_FLAGS)
288                     set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
289                 endif()
290                 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
291                     set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
292                 endif()
293             endif()
294         endif()
295     else(OPENMP_FOUND)
296         message(WARNING
297                 "The compiler you are using does not support OpenMP parallelism. This might hurt your performance a lot, in particular with GPUs. Try using a more recent version, or a different compiler. For now, we are proceeding by turning off OpenMP.")
298         set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE)
299     endif(OPENMP_FOUND)
300 endif()
301
302
303 include(gmxCFlags)
304 gmx_c_flags()
305
306 include(gmxGetCompilerInfo)
307 get_compiler_version()
308
309 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
310 # Detect here whether applying a workaround is needed and will apply it later
311 # on the affected files.
312 include(gmxGCC44O3BugWorkaround)
313 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
314
315 # clang 3.0 is buggy for some unknown reason detected during adding
316 # the SSE2 group kernels for GROMACS 4.6. If we ever work out what
317 # that is, we should replace these tests with a compiler feature test,
318 # update GROMACS Redmine task #1039 and perhaps report a clang bug.
319 #
320 # In the meantime, until we require CMake 2.8.10 we cannot rely on it to detect
321 # the compiler version for us. So we need a manual check for clang 3.0.
322 include(gmxDetectClang30)
323 gmx_detect_clang_3_0(COMPILER_IS_CLANG_3_0)
324 if(COMPILER_IS_CLANG_3_0)
325     message(FATAL_ERROR "Your compiler is clang version 3.0, which is known to be buggy for GROMACS. Use a different compiler.")
326 endif()
327
328 ########################################################################
329 # Set up binary and library suffixing 
330 ########################################################################
331 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
332 set(GMX_LIBS_SUFFIX "" 
333   CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
334 if (GMX_DEFAULT_SUFFIX)
335   set(GMX_BINARY_SUFFIX "")
336   set(GMX_LIBS_SUFFIX "")
337   if (GMX_MPI)
338     set(GMX_BINARY_SUFFIX "_mpi")
339     set(GMX_LIBS_SUFFIX "_mpi")
340   endif(GMX_MPI)
341   if (GMX_DOUBLE)
342     set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
343     set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
344   endif(GMX_DOUBLE)
345   if (GMX_OPENMM)
346     set (GMX_BINARY_SUFFIX "-openmm")
347     set (GMX_LIBS_SUFFIX "_openmm")
348   endif(GMX_OPENMM)
349   mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
350   if (NOT SUFFIX_QUIETLY)
351     message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
352     message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
353   endif (NOT SUFFIX_QUIETLY)
354 else(GMX_DEFAULT_SUFFIX)
355   mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
356   if (NOT SUFFIX_QUIETLY)
357     message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
358     message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
359   endif (NOT SUFFIX_QUIETLY)
360 endif(GMX_DEFAULT_SUFFIX)
361 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
362
363 set(PKG_CFLAGS "")
364 if(GMX_DOUBLE)
365     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
366 endif(GMX_DOUBLE)
367 if(GMX_SOFTWARE_INVSQRT)
368   set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
369 endif(GMX_SOFTWARE_INVSQRT)
370 if(GMX_POWERPC_INVSQRT)
371   set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_POWERPC_INVSQRT")
372 endif(GMX_POWERPC_INVSQRT)
373
374 ########################################################################
375 #Process MPI settings
376 ########################################################################
377 include(gmxManageMPI)
378
379 #######################################################################
380 # Check for options incompatible with OpenMM build                    #
381 #######################################################################
382 if(GMX_OPENMM)
383     # we'll use the built-in fft to avoid unnecessary dependencies
384     string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
385     if(NOT ${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
386         message(STATUS "No external FFT libraries needed for the OpenMM build, switching to fftpack!")
387         set(GMX_FFT_LIBRARY "fftpack" CACHE STRING 
388                 "No external FFT libraries needed for the OpenMM build, switching to  fftpack!" FORCE)
389     endif()
390     if(GMX_MPI)
391         message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
392     endif(GMX_MPI)
393     if(GMX_THREAD_MPI)
394         message(STATUS "Thread-MPI not compatible with OpenMM, disabled!")
395         set(GMX_THREAD_MPI OFF CACHE BOOL
396                 "Thread-MPI not compatible with OpenMM build, disabled!" FORCE)
397     endif(GMX_THREAD_MPI)
398     if(GMX_OPENMP)
399         message(STATUS "OpenMP multithreading not compatible with OpenMM, disabled")
400         set(GMX_OPENMP OFF CACHE BOOL
401             "OpenMP multithreading not compatible with OpenMM, disabled!" FORCE)
402     endif()
403     if(GMX_SOFTWARE_INVSQRT)
404         set(GMX_SOFTWARE_INVSQRT OFF CACHE STRING 
405                 "The OpenMM build does not need GROMACS software 1/sqrt!" FORCE)
406     endif(GMX_SOFTWARE_INVSQRT)
407     string(TOUPPER ${GMX_CPU_ACCELERATION} GMX_CPU_ACCELERATION)
408     if(NOT GMX_CPU_ACCELERATION STREQUAL "NONE")
409         message(STATUS "Switching off CPU-based acceleration, the OpenMM build does not support/need any!")
410         set(GMX_CPU_ACCELERATION "None" CACHE STRING
411             "Switching off CPU-based acceleration, the OpenMM build does not support/need any!" FORCE)
412     endif()
413     if(GMX_FAHCORE)
414         message(FATAL_ERROR "The OpenMM build does not support FAH build!")
415     endif(GMX_FAHCORE)
416     if(GMX_DOUBLE)
417         message(FATAL_ERROR  "The OpenMM-build does not support double precision calculations!")
418     endif()
419     # mark as advanced the unused variables
420     mark_as_advanced(FORCE GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY 
421         GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
422 else(GMX_OPENMM)
423      mark_as_advanced(CLEAR GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY 
424         GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
425 endif(GMX_OPENMM)
426
427
428 ########################################################################
429 # Basic system tests (standard libraries, headers, functions, types)   #
430 ########################################################################
431 include(CheckIncludeFiles)
432 check_include_files(string.h     HAVE_STRING_H)
433 check_include_files(math.h       HAVE_MATH_H)
434 check_include_files(limits.h     HAVE_LIMITS_H)
435 check_include_files(memory.h     HAVE_MEMORY_H)
436 check_include_files(unistd.h     HAVE_UNISTD_H)
437 check_include_files(direct.h     HAVE_DIRECT_H)
438 check_include_files(pwd.h        HAVE_PWD_H)
439 check_include_files(stdint.h     HAVE_STDINT_H)
440 check_include_files(stdlib.h     HAVE_STDLIB_H)
441 check_include_files(pthread.h    HAVE_PTHREAD_H)
442 check_include_files(dirent.h     HAVE_DIRENT_H)
443 check_include_files(inttypes.h   HAVE_INTTYPES_H)
444 check_include_files(regex.h      HAVE_REGEX_H)
445 check_include_files(sys/types.h  HAVE_SYS_TYPES_H)
446 check_include_files(sys/stat.h   HAVE_SYS_STAT_H)
447 check_include_files(sys/time.h   HAVE_SYS_TIME_H)
448 check_include_files(rpc/rpc.h    HAVE_RPC_RPC_H)
449 check_include_files("rpc/rpc.h;rpc/xdr.h"    HAVE_RPC_XDR_H)
450 check_include_files(io.h                 HAVE_IO_H)
451 check_include_files(sched.h      HAVE_SCHED_H)
452
453 include(CheckFunctionExists)
454 check_function_exists(strcasecmp        HAVE_STRCASECMP)
455 check_function_exists(strdup            HAVE_STRDUP)
456 check_function_exists(vprintf           HAVE_VPRINTF)
457 check_function_exists(memcmp            HAVE_MEMCMP)
458 check_function_exists(posix_memalign    HAVE_POSIX_MEMALIGN)
459 check_function_exists(memalign          HAVE_MEMALIGN)
460 check_function_exists(_aligned_malloc   HAVE__ALIGNED_MALLOC)
461 check_function_exists(gettimeofday      HAVE_GETTIMEOFDAY)
462 check_function_exists(isnan             HAVE_ISNAN)
463 check_function_exists(_isnan            HAVE__ISNAN)
464 check_function_exists(fsync             HAVE_FSYNC)
465 check_function_exists(_fileno           HAVE__FILENO)
466 check_function_exists(fileno            HAVE_FILENO)
467 check_function_exists(_commit           HAVE__COMMIT)
468 check_function_exists(sigaction         HAVE_SIGACTION)
469 check_function_exists(sysconf           HAVE_SYSCONF)
470 check_function_exists(sched_setaffinity HAVE_SCHED_SETAFFINITY)
471 check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
472 check_function_exists(rsqrt             HAVE_RSQRT)
473 check_function_exists(rsqrtf            HAVE_RSQRTF)
474 check_function_exists(sqrtf             HAVE_SQRTF)
475
476 include(CheckLibraryExists)
477 check_library_exists(m sqrt "" HAVE_LIBM)
478 check_library_exists(m cbrt "" HAVE_CBRT)
479
480
481 include(CheckTypeSize)
482
483 check_type_size("bool"          SIZEOF_BOOL) # will also set HAVE_BOOL
484 check_type_size("int"           SIZEOF_INT) 
485 check_type_size("long int"      SIZEOF_LONG_INT) 
486 check_type_size("long long int" SIZEOF_LONG_LONG_INT) 
487 check_type_size("off_t"         SIZEOF_OFF_T)
488 check_type_size("void *"        SIZEOF_VOIDP)
489
490 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
491     set(GMX_64_BIT TRUE)
492 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
493     set(GMX_64_BIT FALSE)
494 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
495
496 # Check for some basic types that we *need*, so set these to int if they are not present 
497 check_type_size(uid_t uid_t)
498 if(NOT uid_t)
499   set(uid_t int)
500 else(NOT uid_t)
501   set(uid_t 0)
502 endif(NOT uid_t)
503
504 check_type_size(gid_t gid_t)
505 if(NOT gid_t)
506   set(gid_t 1)
507 else(NOT gid_t)
508   set(gid_t 0)
509 endif(NOT gid_t)
510
511 check_type_size(size_t size_t)
512 if(NOT size_t)
513   set(size_t int)
514 else(NOT size_t)
515   set(size_t 0)
516 endif(NOT size_t)
517
518 check_type_size(off_t off_t)
519 if(NOT off_t)
520   set(off_t int)
521 else(NOT off_t)
522   set(off_t 0)
523 endif(NOT off_t)
524
525 include(TestBigEndian)
526 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
527
528
529
530
531 ########################################################################
532 # Find external packages                                               #
533 ########################################################################
534 if(UNIX)
535     if(GMX_PREFER_STATIC_LIBS)
536         # On Linux .a is the static library suffix, on Mac OS X .lib can also
537         # be used, so we'll add both to the preference list.
538         SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
539         if(SHARED_LIBS_DEFAULT)
540             if(BUILD_SHARED_LIBS) #Warn the user about the combination. But don't overwrite the request.
541                 message(WARNING "Static libraries requested, and shared Gromacs libraries requested.")
542             elseif(NOT DEFINED BUILD_SHARED_LIBS) #Change default to OFF. Don't warn if it's already off.
543                 message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
544                 set(SHARED_LIBS_DEFAULT OFF)
545             endif()
546         endif()
547     endif()
548 endif()
549 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
550
551 option(GMX_GSL "Add support for gsl" OFF)
552 if (GMX_GSL)
553   find_package(gsl)
554   set(PKG_GSL "")
555   if(GSL_FOUND)
556     include_directories(${GSL_INCLUDE_DIR})
557     set(PKG_GSL gsl)
558     set(HAVE_LIBGSL 1)
559   endif(GSL_FOUND)
560 endif (GMX_GSL)
561
562 option(GMX_X11 "Use X window system" OFF)
563 if (GMX_X11)
564         find_package(X11)
565         # X11 includes/libraries are only set in the ngmx subdirectory!
566         if(X11_FOUND)
567         set(HAVE_X11 1)
568         endif(X11_FOUND)
569 endif(GMX_X11)
570
571 include(ThreadMPI)
572 set(THREAD_MPI_LIB thread_mpi)
573 if(GMX_THREAD_MPI)
574     tmpi_get_source_list(THREAD_MPI_SRC)
575     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
576     set(GMX_MPI 1)
577 else(GMX_THREAD_MPI)
578     tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
579 endif(GMX_THREAD_MPI)
580
581 if(GMX_OPENMM)
582     set(CUDA_BUILD_EMULATION OFF)
583     find_package(CUDA 3.1 REQUIRED)
584     add_definitions(-DGMX_OPENMM)
585     if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")    
586         set(CUDA_VERBOSE_BUILD ON)
587     endif()
588     find_package(OpenMM) 
589 endif(GMX_OPENMM)
590
591 if(GMX_GPU)
592     # now that we have detected the dependencies, do the second configure pass
593     gmx_gpu_setup()
594 endif(GMX_GPU)
595
596 if(APPLE)
597    find_library(ACCELERATE_FRAMEWORK Accelerate)
598    list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
599 endif(APPLE)
600
601 if(CYGWIN)
602     set(GMX_CYGWIN 1)
603 endif(CYGWIN)
604
605 if(WIN32 AND NOT CYGWIN)
606     set(GMX_NATIVE_WINDOWS 1)
607 endif()
608
609 # only bother with finding git and using version.h if the source is a git repo
610 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
611     if(USE_VERSION_H)
612         # We need at least git v1.5.3 be able to parse git's date output. If not
613         # found or the version is too small, we can't generate version information.
614         find_package(Git)
615
616         # Find out the git version
617         if(GIT_FOUND AND NOT GIT_VERSION)
618           execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
619             OUTPUT_VARIABLE _exec_out
620             OUTPUT_STRIP_TRAILING_WHITESPACE)
621           string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
622           set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
623           mark_as_advanced(GIT_VERSION)
624         endif()
625
626         if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
627           message("No compatible git version found, won't be able to generate proper development version information.")
628           set(USE_VERSION_H OFF)
629         endif()
630     endif()
631 else()
632     set(USE_VERSION_H OFF)
633 endif()
634
635 ########################################################################
636 # Generate development version info for cache
637 ########################################################################
638 # set(GEN_VERSION_INFO_INTERNAL "ON")
639 # include(gmxGenerateVersionString)
640
641 ########################################################################
642 # Our own GROMACS tests
643 ########################################################################
644
645 add_definitions( -DHAVE_CONFIG_H )
646 include_directories(${CMAKE_BINARY_DIR}/src)
647 include_directories(${CMAKE_BINARY_DIR}/include)
648 include_directories(${CMAKE_SOURCE_DIR}/include)
649
650 include(gmxTestInlineASM)
651 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
652
653 include(gmxSetBuildInformation)
654 gmx_set_build_information()
655 if(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
656     # The timestep counter headers do not include config.h
657     add_definitions(-DHAVE_RDTSCP)
658 endif(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
659
660 include(gmxTestFloatFormat)
661 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754 
662                       GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
663                       GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
664
665 include(gmxTestLargeFiles)
666 gmx_test_large_files(GMX_LARGEFILES)
667
668 include(gmxTestSignal)
669 gmx_test_sigusr1(HAVE_SIGUSR1)
670
671 include(gmxTestInline)
672 gmx_test_inline(INLINE_KEYWORD)
673
674 include(gmxTestRestrict)
675 gmx_test_restrict(RESTRICT_KEYWORD)
676
677 include(gmxTestPipes)
678 gmx_test_pipes(HAVE_PIPES)
679
680 include(gmxTestIsfinite)
681 gmx_test_isfinite(HAVE_ISFINITE)
682 gmx_test__isfinite(HAVE__ISFINITE)
683 gmx_test__finite(HAVE__FINITE)
684
685 include(gmxTestXDR)
686 gmx_test_xdr(GMX_SYSTEM_XDR)
687 if(NOT GMX_SYSTEM_XDR)
688     set(GMX_INTERNAL_XDR 1)
689     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
690 endif(NOT GMX_SYSTEM_XDR)
691
692 # Process nonbonded accelerated kernels settings
693 string(TOUPPER ${GMX_CPU_ACCELERATION} ${GMX_CPU_ACCELERATION})
694 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
695     # nothing to do
696 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
697
698     GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" GROMACS_C_FLAGS)
699     if(NOT GNU_SSE2_CFLAG)
700         GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
701     endif(NOT GNU_SSE2_CFLAG)
702
703     if (CMAKE_CXX_COMPILER_LOADED)
704         GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
705         if(NOT GNU_SSE2_CXXFLAG)
706             GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
707         endif(NOT GNU_SSE2_CXXFLAG)
708     endif()
709
710     # We dont warn for lacking SSE2 flag support, since that is probably standard today.
711
712     # Only test the include after we have tried to add the correct flag for SSE2 support
713     check_include_file(emmintrin.h  HAVE_EMMINTRIN_H ${GROMACS_C_FLAGS})
714
715     if(NOT HAVE_EMMINTRIN_H)
716         message(FATAL_ERROR "Cannot find emmintrin.h, which is required for SSE2 intrinsics support.")
717     endif(NOT HAVE_EMMINTRIN_H)
718
719     set(GMX_CPU_ACCELERATION_X86_SSE2 1)
720     # The user should not be able to set this orthogonally to the acceleration
721     set(GMX_X86_SSE2 1)
722     if (NOT ACCELERATION_QUIETLY)
723       message(STATUS "Enabling SSE2 Gromacs acceleration, and it will help compiler optimization.")
724     endif()
725
726 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
727
728     GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" GROMACS_C_FLAGS)
729     if (NOT GNU_SSE4_CFLAG)
730         GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" GROMACS_C_FLAGS)
731     endif(NOT GNU_SSE4_CFLAG)
732     if (NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
733         message(WARNING "No C SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
734         # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
735         # intrinsics when SSE2 support is enabled, so we try that instead.
736         GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
737     endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
738
739     if (CMAKE_CXX_COMPILER_LOADED)
740         GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
741         if (NOT GNU_SSE4_CXXFLAG)
742             GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
743         endif(NOT GNU_SSE4_CXXFLAG)
744         if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG) 
745             message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
746             # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
747             # intrinsics when SSE2 support is enabled, so we try that instead.
748             GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
749         endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
750     endif()
751
752     # This must come after we have added the -msse4.1 flag on some platforms.
753     check_include_file(smmintrin.h  HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
754
755     if(NOT HAVE_SMMINTRIN_H)
756         message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
757     endif(NOT HAVE_SMMINTRIN_H)
758
759     set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
760     # The user should not be able to set this orthogonally to the acceleration
761     set(GMX_X86_SSE4_1 1)
762     set(GMX_X86_SSE2   1)
763     if (NOT ACCELERATION_QUIETLY)
764       message(STATUS "Enabling SSE4.1 Gromacs acceleration, and it will help compiler optimization.")
765     endif()
766
767 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
768
769     # Set the AVX compiler flag for both these choices!
770
771     GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" GROMACS_C_FLAGS)
772     if (NOT GNU_AVX_CFLAG)
773         GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" GROMACS_C_FLAGS)
774     endif (NOT GNU_AVX_CFLAG)
775     if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
776         message(WARNING "No C AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
777     endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
778
779     if (CMAKE_CXX_COMPILER_LOADED)
780         GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
781         if (NOT GNU_AVX_CXXFLAG)
782             GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
783         endif (NOT GNU_AVX_CXXFLAG)
784         if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
785             message(WARNING "No C++ AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
786         endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
787     endif()
788
789     # Set the FMA4 flags (MSVC doesn't require any)
790     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
791         GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
792         if (NOT GNU_FMA_CFLAG)
793             message(WARNING "No C FMA4 flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
794         endif(NOT GNU_FMA_CFLAG)
795         GMX_TEST_CFLAG(GNU_XOP_CFLAG "-mxop" GROMACS_C_FLAGS)
796         # No big deal if we do not have xop, so no point yelling warnings about it.
797         if (CMAKE_CXX_COMPILER_LOADED)
798             GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
799             if (NOT GNU_FMA_CXXFLAG)
800                 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
801             endif (NOT GNU_FMA_CXXFLAG)
802             GMX_TEST_CXXFLAG(GNU_XOP_CXXFLAG "-mxop" GROMACS_CXX_FLAGS)
803             # No big deal if we do not have xop, so no point yelling warnings about it.
804         endif()
805     endif()
806
807     # Only test the header after we have tried to add the flag for AVX support
808     check_include_file(immintrin.h  HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
809
810     if(NOT HAVE_IMMINTRIN_H)
811         message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
812     endif(NOT HAVE_IMMINTRIN_H)
813
814     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
815         try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
816             "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
817             COMPILE_DEFINITIONS "${GROMACS_C_FLAGS}")
818         if(NOT TEST_AVX)
819             message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
820         endif()
821     endif()
822
823     # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
824     check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
825     check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
826
827     # The user should not be able to set this orthogonally to the acceleration
828     set(GMX_X86_SSE4_1 1)
829     set(GMX_X86_SSE2   1)
830
831     # But just enable one of the choices internally...
832     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
833         set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
834         set(GMX_X86_AVX_128_FMA 1)
835         if (NOT ACCELERATION_QUIETLY)
836           message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add), and it will help compiler optimization.")
837         endif()
838     else()
839         # If we are not doing AVX_128, it must be AVX_256...
840         set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
841         set(GMX_X86_AVX_256 1)
842         if (NOT ACCELERATION_QUIETLY)
843           message(STATUS "Enabling 256-bit AVX Gromacs acceleration, and it will help compiler optimization.")
844         endif()
845     endif()
846
847 elseif(${GMX_CPU_ACCELERATION} STREQUAL "FORTRAN")
848
849 #    Fortran is temporarily disabled while we push in nbNxN kernels.
850 #    We need to fake it a bit here to avoid jenkins build errors!
851 #    add_definitions(-DGMX_FORTRAN)
852
853 elseif(${GMX_CPU_ACCELERATION} STREQUAL "BLUEGENE")
854 # GMX_CPU_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
855     if (NOT ACCELERATION_QUIETLY)
856       message(STATUS "Configuring for BlueGene")
857     endif()
858     set(GMX_BLUEGENE 1)
859     if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
860         set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
861         set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
862     endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
863     set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
864     set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on BlueGene" FORCE)
865     set(GMX_X11 OFF CACHE BOOL "X11 not compatible with BlueGene, disabled!" FORCE)
866     set(GMX_THREAD_MPI OFF CACHE BOOL "Thread-MPI not compatible with BlueGene, disabled!" FORCE)
867     set(GMX_MPI ON CACHE BOOL "Use MPI on BlueGene" FORCE)
868 # Access to /etc/passwd is not available on the back end of BlueGene,
869 # despite being detected by CMake. This can cause linker warnings
870 # about harmless things in src/gmxlib/string2.h.
871     set(HAVE_PWD_H OFF)
872 # The automatic testing for endianness does not work for the BlueGene cross-compiler
873     set(GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP byte order (by default)" FORCE)
874     set(GMX_IEEE754_BIG_ENDIAN_WORD_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP word order (by default)" FORCE)
875 elseif(${GMX_CPU_ACCELERATION} STREQUAL "POWER6")
876     set(GMX_POWER6 1)
877     set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on Power6" FORCE)
878     set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on Power6" FORCE)
879 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
880     MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_CPU_ACCELERATION}. Pick one of None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, Fortran, BlueGene, Power6")
881 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
882 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
883
884 if(GMX_FORTRAN OR GMX_POWER6)
885     if (GMX_THREAD_MPI)
886         message(FATAL_ERROR "FORTRAN/POWER6 is incompatible with thread-MPI and only provides a speed-up on certain IBM compilers. Disable FORTRAN (or threads if you really want to use FORTRAN kernels).")
887     endif(GMX_THREAD_MPI)
888     enable_language(Fortran)
889     include(FortranCInterface)
890     discover_fortran_mangling(prefix isupper suffix extra_under_score found)
891     if(extra_under_score)
892         set(extrasuffix "_")
893     endif(extra_under_score)
894     if(prefix)
895       set(prefix "${prefix} ##")
896     endif(prefix)
897     if(suffix)
898       set(suffix "## ${suffix}")
899       if(extrasuffix)
900         set(extrasuffix "${suffix}${extrasuffix}")
901       endif(extrasuffix)
902     else(suffix)
903       if(extrasuffix)
904         # Don't know if this is needed, but it can't hurt
905         set(extrasuffix "## ${extrasuffix}")
906       endif(extrasuffix)
907     endif(suffix)
908
909     if(isupper)
910         set(F77_FUNCDEF   "${prefix} NAME ${suffix}")
911         set(F77_FUNCDEF_  "${prefix} NAME ${extrasuffix}")
912     else(isupper)
913         set(F77_FUNCDEF   "${prefix} name ${suffix}")
914         set(F77_FUNCDEF_  "${prefix} name ${extrasuffix}")
915     endif(isupper)
916 else(GMX_FORTRAN OR GMX_POWER6)
917         set(F77_FUNCDEF   "name ## _")
918         set(F77_FUNCDEF_  "name ## _")
919 endif(GMX_FORTRAN OR GMX_POWER6)
920
921 # Process QM/MM Settings
922 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
923 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
924     set(GMX_QMMM_GAUSSIAN 1)
925 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
926     set(GMX_QMMM_MOPAC 1)
927 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
928     set(GMX_QMMM_GAMESS 1)
929 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
930     set(GMX_QMMM_ORCA 1)
931 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
932     # nothing to do
933 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
934     MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
935 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
936
937 # Process FFT library settings - if not OpenMM build 
938 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
939 set(PKG_FFT "")
940 set(PKG_FFT_LIBS "")
941 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
942     if(GMX_DOUBLE)
943         set(FFTW fftw)
944     else()
945         set(FFTW fftwf)
946     endif()
947
948     if(GMX_BUILD_OWN_FFTW)
949       add_subdirectory(src/contrib/fftw)
950     else()
951       find_package(FFTW COMPONENTS ${FFTW})
952     endif()
953
954     string(TOUPPER "${FFTW}" FFTW)
955     set(PKG_FFT "${${FFTW}_PKG}")
956     include_directories(${${FFTW}_INCLUDE_DIRS})
957     set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
958     if(NOT ${FFTW}_FOUND)
959       MESSAGE(FATAL_ERROR "Cannot find FFTW 3 (with correct precision - libfftw3f for single-precision GROMACS or libfftw3 for double-precision GROMACS). Either choose the right precision, choose another FFT(W) library, enable the advanced option to let GROMACS build FFTW 3 for you, or use the really slow GROMACS built-in fftpack library.")
960     endif()
961
962     set(GMX_FFT_FFTW3 1)
963
964     if (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD) 
965       message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
966     endif()
967
968     if(NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND ${FFTW}_HAVE_AVX)
969         # If we're not doing CPU acceleration, we don't care about FFTW performance on x86 either
970         message(WARNING "The FFTW library was compiled with --enable-avx to enable AVX SIMD instructions. That might sound like a good idea for your processor, but for FFTW versions up to 3.3.3, these are slower than the SSE/SSE2 SIMD instructions for the way GROMACS uses FFTs. Limitations in the way FFTW allows GROMACS to measure performance make it awkward for either GROMACS or FFTW to make the decision for you based on runtime performance. You should compile a different FFTW library with --enable-sse or --enable-sse2. If you have a more recent FFTW, you may like to compare the performance of GROMACS with FFTW libraries compiled with and without --enable-avx. However, the GROMACS developers do not really expect the FFTW AVX optimization to help, because the performance is limited by memory access, not computation.")
971     endif()
972
973 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
974 #    MESSAGE(STATUS "Using external FFT library - Intel MKL")
975     find_package(MKL REQUIRED)
976     include_directories(${MKL_INCLUDE_DIR})
977     set(FFT_LIBRARIES ${MKL_LIBRARIES})
978     set(PKG_FFT_LIBS ${MKL_LIBRARIES})
979
980     set(GMX_FFT_MKL 1)
981     set(HAVE_MKL 1)
982
983 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
984 #    MESSAGE(STATUS "Using external FFT library - AMD core math library")
985 #    set(GMX_FFT_ACML 1)
986 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
987     MESSAGE(STATUS "Using internal FFT library - fftpack")
988     set(GMX_FFT_FFTPACK 1)
989 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
990     MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
991 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
992
993 # enable threaded fftw3 if we've found it 
994 if(FFTW3_THREADS OR FFTW3F_THREADS)
995     add_definitions(-DFFT5D_FFTW_THREADS)
996 endif()
997
998 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
999 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
1000 # MKL has BLAS/LAPACK routines
1001 if(NOT HAVE_MKL AND NOT ACCELERATE_FRAMEWORK)
1002   if(GMX_EXTERNAL_BLAS)
1003     if (GMX_BLAS_USER)
1004         list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
1005     else(GMX_BLAS_USER)
1006         set(BLAS_FIND_QUIETLY ON)
1007         find_package(BLAS)
1008         if (BLAS_FOUND)
1009           list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
1010         else()
1011           MESSAGE(STATUS "Using internal BLAS library")
1012           set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in" FORCE)
1013         endif()
1014     endif(GMX_BLAS_USER)
1015   endif(GMX_EXTERNAL_BLAS)
1016   if(GMX_EXTERNAL_LAPACK)
1017     if (GMX_LAPACK_USER)
1018         list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
1019     else(GMX_LAPACK_USER)
1020         set(LAPACK_FIND_QUIETLY ON)
1021         find_package(LAPACK)
1022         if (LAPACK_FOUND)
1023           list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
1024         else()
1025           MESSAGE(STATUS "Using internal LAPACK library")
1026           set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in" FORCE)
1027         endif()
1028     endif(GMX_LAPACK_USER)
1029   endif(GMX_EXTERNAL_LAPACK)
1030 endif()
1031 mark_as_advanced(GMX_EXTERNAL_LAPACK)
1032 mark_as_advanced(GMX_EXTERNAL_BLAS)
1033
1034 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
1035
1036 if(GMX_LOAD_PLUGINS)
1037   if(CYGWIN OR NOT WIN32)
1038     # Native Windows does not have, nor need dlopen
1039     # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
1040     include(gmxTestdlopen)
1041     gmx_test_dlopen(HAVE_DLOPEN)
1042   endif()
1043
1044   # so, should we use plug-ins?
1045   if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1046     if(NOT VMD_QUIETLY)
1047       MESSAGE(STATUS
1048           "Found the ability to use plug-ins when building shared libaries, "
1049           "so will compile to use plug-ins (e.g. to read VMD-supported file "
1050           "formats).")
1051     endif()
1052     if(NOT GMX_VMD_PLUGIN_PATH)
1053       find_package(VMD)
1054     endif()
1055     set(GMX_USE_PLUGINS ON)
1056     list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1057     set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1058   else()
1059     set(PKG_DL_LIBS)
1060   endif()
1061 endif(GMX_LOAD_PLUGINS)
1062 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1063
1064 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1065     if(NOT CMAKE_CROSSCOMPILING)
1066         option(GMX_BUILD_MANPAGES "Build man pages" ON)
1067     else()
1068         message(STATUS "Building the man pages is not available when "
1069             "cross-compiling the developer version from git")
1070     endif()
1071 else()
1072     #make sure source package contains all man pages
1073     if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1074         message(FATAL_ERROR "Man pages are missing from source package.")
1075     endif()
1076 endif()
1077 mark_as_advanced(GMX_BUILD_MANPAGES)
1078
1079 # Math and thread libraries must often come after all others when linking...
1080 if(HAVE_LIBM)
1081     list(APPEND GMX_EXTRA_LIBRARIES m)
1082 endif(HAVE_LIBM)
1083
1084 if(GMX_FAHCORE)
1085   set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING 
1086       "Path to swindirect.h")
1087   include_directories(${COREWRAP_INCLUDE_DIR})
1088 endif(GMX_FAHCORE)
1089
1090 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1091 # these are set after everything else
1092 if (NOT DEFINED GROMACS_C_FLAGS_SET)
1093     set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags" 
1094         FORCE)
1095     set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING 
1096         "Flags used by the compiler during all build types" FORCE)
1097     if (CMAKE_CXX_COMPILER_LOADED)
1098         set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING 
1099             "Flags used by the compiler during all build types" FORCE)
1100     endif()
1101     set(CMAKE_EXE_LINKER_FLAGS 
1102         "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" 
1103         CACHE STRING "Linker flags for creating executables" FORCE) 
1104     set(CMAKE_SHARED_LINKER_FLAGS 
1105         "${GROMACS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" 
1106         CACHE STRING "Linker flags for creating shared libraries" FORCE) 
1107 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
1108
1109 if(NOT GMX_OPENMP)
1110     #Unset all OpenMP flags in case OpenMP was disabled either by the user
1111     #or because it was only partially detected (e.g. only for C but not C++ compiler)
1112     unset(OpenMP_C_FLAGS CACHE) 
1113     unset(OpenMP_CXX_FLAGS CACHE)
1114     unset(OpenMP_LINKER_FLAGS CACHE)
1115     unset(OpenMP_SHARED_LINKER_FLAGS)
1116 endif()
1117
1118 ######################################
1119 # Output compiler and CFLAGS used
1120 ######################################
1121 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
1122 if (CMAKE_CXX_COMPILER_LOADED)
1123     get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
1124 endif ()
1125
1126 ########################################################################
1127 # Specify install locations and which subdirectories to process        #
1128 ########################################################################
1129 if (GMX_USE_RELATIVE_INSTALL_PATH)
1130     set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1131     mark_as_advanced(GMX_INSTALL_PREFIX)
1132 else()
1133     set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1134 endif()
1135
1136 if ( NOT DEFINED GMXLIB )
1137     set(GMXLIB lib)
1138 endif()
1139 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1140 set(BIN_INSTALL_DIR  ${GMX_INSTALL_PREFIX}bin)
1141 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1142 set(MAN_INSTALL_DIR  ${GMX_INSTALL_PREFIX}share/man)
1143 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1144
1145 set(GMXLIBDIR        ${DATA_INSTALL_DIR}/top)
1146
1147 ##################################################################
1148 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
1149 ##################################################################
1150 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1151     set(CMAKE_SKIP_BUILD_RPATH  FALSE)
1152     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1153     set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1154     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1155 endif()
1156
1157 #COPYING file: Only necessary for binary distributions.
1158 #Simpler to always install.
1159 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1160
1161 add_subdirectory(share)
1162 add_subdirectory(include)
1163 add_subdirectory(src)
1164 add_subdirectory(scripts)
1165
1166 # issue GPU acceleration/CUDA-related warning or error if GMX_GPU was set
1167 # Auto and NVIDIA GPUs were detected.
1168 if (CUDA_NOTFOUND_AUTO AND NOT GMX_GPU_DETECTION_DONE)
1169     message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
1170     unset(CUDA_NOTFOUND_AUTO)
1171     unset(CUDA_NOTFOUND_MESSAGE)
1172 endif()
1173 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
1174
1175 #######################
1176 ## uninstall target
1177 #######################
1178     CONFIGURE_FILE(
1179                    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1180                    "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1181                    IMMEDIATE @ONLY)
1182 ###########################
1183 ADD_CUSTOM_TARGET(uninstall
1184                   "${CMAKE_COMMAND}" -P 
1185                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1186 ###########################
1187
1188 ########################################################################
1189 # Tests                                                                #
1190 ########################################################################
1191
1192 include(CTest)
1193 mark_as_advanced(BUILD_TESTING)
1194 IF(BUILD_TESTING)
1195         enable_testing()
1196         add_subdirectory(tests)
1197 ENDIF()
1198