Fix message about incorrect usage of dihedral type 9
[alexxy/gromacs.git] / CMakeLists.txt
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 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 # CMake modules/macros are in a subdirectory to keep this file cleaner
44 # This needs to be set before project() in order to pick up toolchain files
45 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Platform)
46
47 project(Gromacs C)
48 include(Dart)
49 mark_as_advanced(DART_ROOT)
50
51 # PROJECT_VERSION should have the following structure: 
52 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
53 #
54 # The "-dev" suffix is important to keep because it makes possible to distinguish 
55 # between a build from official release and a build from git release branch on a 
56 # machine with no git. 
57 #
58 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
59 set(PROJECT_VERSION "4.6.8-dev")
60 # The version number of the regressiontest tarball against which this
61 # git branch can be tested. Normally, this will be the version of the
62 # last patch release. Comment the next line out for branches leading
63 # to a major/minor release.
64 set(REGRESSIONTEST_VERSION "4.6.7")
65 set(CUSTOM_VERSION_STRING ""
66     CACHE STRING "Custom version string (if empty, use hard-coded default)")
67 mark_as_advanced(CUSTOM_VERSION_STRING)
68 if (CUSTOM_VERSION_STRING)
69     set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
70 endif (CUSTOM_VERSION_STRING)
71 set(SOVERSION 8)
72 # It is a bit irritating, but this has to be set separately for now!
73 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
74 SET(CPACK_PACKAGE_VERSION_MINOR "6")
75 SET(CPACK_PACKAGE_VERSION_PATCH "1")
76
77 # The numerical gromacs version. It is 40600 for 4.6.0.
78 # The #define GMX_VERSION in gmx_header_config_h is set to this value.
79 math(EXPR NUM_VERSION 
80     "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
81 if(CPACK_PACKAGE_VERSION_PATCH)
82     math(EXPR NUM_VERSION 
83          "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
84 endif()
85
86 # The API version tracks the numerical Gromacs version (for now).
87 # It is potentially different from the Gromacs version in the future, if
88 # the programs/libraries diverge from the presumably more stable API.
89 # The #define GMX_API_VERSION in version.h is set to this value to
90 # provide backward compatibility of software written against the Gromacs API.
91 set(API_VERSION ${NUM_VERSION})
92
93 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
94 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
95 endif()
96
97 include(gmxBuildTypeReference)
98
99 if(NOT CMAKE_BUILD_TYPE)
100     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
101 endif(NOT CMAKE_BUILD_TYPE)
102
103 enable_language(C)
104
105 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
106 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
107
108 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
109 set(CPACK_PACKAGE_VENDOR "gromacs.org")
110 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
111 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
112     set(CPACK_SET_DESTDIR "ON")
113 endif()
114 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
115 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
116 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
117 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
118 set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$")
119 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
120 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
121 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
122
123 #must come after all cpack settings!
124 include(CPack)
125
126 ########################################################################
127 # Check and warn if cache generated on a different host is being reused
128 ########################################################################
129 if(CMAKE_HOST_UNIX)
130     execute_process(COMMAND hostname
131                     OUTPUT_VARIABLE TMP_HOSTNAME
132                     OUTPUT_STRIP_TRAILING_WHITESPACE)
133     if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
134         message(WARNING "
135             The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
136             is being reused! This could lead to inconsitencies; therefore, it is
137             recommended to regenerate the cache!")
138     endif()
139     set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
140             "Hostname of the machine where the cache was generated.")
141 endif()
142
143 ########################################################################
144 # User input options - enable C++ - before any CXX flags are changed   #
145 ########################################################################
146
147 # decide on GPU settings based on user-settings and GPU/CUDA detection
148 include(gmxManageGPU)
149
150 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
151 mark_as_advanced(GMX_FORCE_CXX)
152
153 option(GMX_COOL_QUOTES "Enable Gromacs cool quotes" ON)
154 mark_as_advanced(GMX_COOL_QUOTES)
155
156 if(GMX_GPU OR GMX_FORCE_CXX OR GMX_OPENMM)
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 # User input options                                                   #
163 ########################################################################
164 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
165 option(GMX_MPI    "Build a parallel (message-passing) version of GROMACS" OFF)
166 option(GMX_THREAD_MPI  "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
167 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
168 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
169 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
170 mark_as_advanced(GMX_FAHCORE)
171
172 if(NOT DEFINED GMX_CPU_ACCELERATION AND NOT CMAKE_CROSSCOMPILING)
173     include(gmxDetectAcceleration)
174     gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
175 endif()
176
177 # Detect the architecture the compiler is targetting, detect
178 # acceleration possibilities on that hardware, suggest an acceleration
179 # to use if none is specified, and populate the cache option for CPU
180 # accleration.
181 include(gmxDetectTargetArchitecture)
182 gmx_detect_target_architecture()
183 include(gmxDetectAcceleration)
184 gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
185 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
186     CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, IBM_QPX, Sparc64_HPC_ACE")
187
188 set(GMX_FFT_LIBRARY "fftw3" 
189     CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
190 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)
191 mark_as_advanced(GMX_BUILD_OWN_FFTW)
192 option(GMX_DISABLE_FFTW_MEASURE 
193        "Do not optimize FFTW setups (not needed with SSE)" OFF)
194 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
195 set(GMX_QMMM_PROGRAM "none" 
196     CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
197 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
198 mark_as_advanced(GMX_BROKEN_CALLOC)
199 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
200 mark_as_advanced(GMX_MPI_IN_PLACE)
201 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
202 mark_as_advanced(GMX_LOAD_PLUGINS)
203
204 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
205
206 option(USE_VERSION_H "Generate development version string/information" ON)
207 mark_as_advanced(USE_VERSION_H)
208
209 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)
210
211 if(UNIX)
212     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)
213     mark_as_advanced(GMX_PREFER_STATIC_LIBS)
214 endif()
215
216 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
217 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
218
219 option(GMX_SKIP_DEFAULT_CFLAGS "Don't automatically add suggested/required Compiler flags." OFF)
220 mark_as_advanced(GMX_SKIP_DEFAULT_CFLAGS)
221
222 ######################################################################
223 # Compiler tests
224 # These need to be done early (before further tests).
225 #####################################################################
226
227 # The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
228 # are used with permission from CMake v2.8.9 so that GROMACS can detect
229 # invalid options with the Intel Compilers.
230 # These files should be removed from the source tree when a CMake version that
231 # includes the features in question becomes required for building GROMACS.
232 include(CheckCCompilerFlag)
233 if(CMAKE_CXX_COMPILER_LOADED)
234     include(CheckCXXCompilerFlag)
235 endif()
236
237 # Get compiler version information, needs to be done early as check that depend
238 # on compiler verison follow below.
239 include(gmxGetCompilerInfo)
240 get_compiler_version()
241
242 # First exclude compilers known to not work with OpenMP although claim to support it:
243 # gcc 4.2.1 and gcc-llvm 4.2.1 (also claims to be 4.2.1) on Mac OS X
244 # This fixes redmine 900 and needs to run before OpenMP flags are set below.
245 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND
246     (CMAKE_COMPILER_IS_GNUCC AND C_COMPILER_VERSION AND C_COMPILER_VERSION VERSION_LESS 4.3))
247     message(STATUS "OpenMP multithreading not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled")
248     set(GMX_OPENMP OFF CACHE BOOL
249         "OpenMP multithreading not not supported with gcc/llvm-gcc 4.2 on Mac OS X, disabled!" FORCE)
250 endif()
251
252 # OpenMP check must come before other CFLAGS!
253 if(GMX_OPENMP)
254     find_package(OpenMP)
255     if(OPENMP_FOUND)
256         # CMake on Windows doesn't support linker flags passed to target_link_libraries
257         # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed.
258         if(NOT (WIN32 AND NOT CYGWIN))
259             if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
260                 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
261                 set(OpenMP_SHARED_LINKER_FLAGS "")
262             else()
263                 # Only set a linker flag if the user didn't set them manually
264                 if(NOT DEFINED OpenMP_LINKER_FLAGS)
265                     set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
266                 endif()
267                 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
268                     set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
269                 endif()
270             endif()
271         endif()
272     else(OPENMP_FOUND)
273         message(WARNING
274                 "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.")
275         set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE)
276     endif(OPENMP_FOUND)
277 endif()
278
279
280 include(gmxCFlags)
281 gmx_c_flags()
282
283 # This variable should be used for additional compiler flags which are not
284 # generated in gmxCFlags nor are acceleration or MPI related.
285 set(EXTRA_C_FLAGS "")
286
287 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
288 # Detect here whether applying a workaround is needed and will apply it later
289 # on the affected files.
290 include(gmxGCC44O3BugWorkaround)
291 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
292
293 # clang 3.0 is buggy for some unknown reason detected during adding
294 # the SSE2 group kernels for GROMACS 4.6. If we ever work out what
295 # that is, we should replace these tests with a compiler feature test,
296 # update GROMACS Redmine task #1039 and perhaps report a clang bug.
297 #
298 # In the meantime, until we require CMake 2.8.10 we cannot rely on it to detect
299 # the compiler version for us. So we need a manual check for clang 3.0.
300 include(gmxDetectClang30)
301 gmx_detect_clang_3_0(COMPILER_IS_CLANG_3_0)
302 if(COMPILER_IS_CLANG_3_0)
303     message(FATAL_ERROR "Your compiler is clang version 3.0, which is known to be buggy for GROMACS. Use a different compiler.")
304 endif()
305
306 # clang <=3.2 contains a bug that causes incorrect code to be generated for the
307 # vfmaddps instruction and therefore the bug is triggered with AVX_128_FMA.
308 # (see: http://llvm.org/bugs/show_bug.cgi?id=15040).
309 # We can work around this by not using the integrated assembler (except on OS X
310 # which has an outdated assembler that does not support AVX instructions).
311 if (${CMAKE_C_COMPILER_ID} MATCHES "Clang" AND C_COMPILER_VERSION VERSION_LESS "3.3")
312     set(GMX_USE_CLANG_FMA_BUG_WORKAROUND TRUE)
313 endif()
314
315 # GMX_CPU_ACCELERATION will not be set automatically until the second
316 # pass (which is not strictly guaranteed to occur), so putting this
317 # check here among logically-related tests is inefficient, but the
318 # potential loss is likely zero.
319 if(GMX_CPU_ACCELERATION STREQUAL "AVX_256"
320         AND CMAKE_COMPILER_IS_GNUCC
321         AND (C_COMPILER_VERSION VERSION_EQUAL "4.6.1"
322             OR CXX_COMPILER_VERSION VERSION_EQUAL "4.6.1"))
323     message(FATAL_ERROR "gcc 4.6.1 has buggy support for AVX, and GROMACS mdrun will not work. If you want simulation performance, use a more recent compiler. Otherwise, use GMX_CPU_ACCELERATION=SSE4.1")
324     # See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49002
325 endif()
326
327 if (CMAKE_C_COMPILER_ID STREQUAL "PGI")
328     message(WARNING "All tested PGI compiler versions (up to 12.9.0) generate binaries which produce incorrect results, or even fail to compile Gromacs. Highly recommended to use a different compiler. If you choose to use PGI, make sure to run the regressiontests.")
329 endif()
330
331 if(CMAKE_C_COMPILER_ID MATCHES "Intel" AND C_COMPILER_VERSION VERSION_LESS "12.0.0")
332     message(WARNING "Intel compilers before 12.0.0 are not routinely tested, so there may be problems. Version 11.1 with SSE4.1 is known to produce incorrect results. It is highly recommended to use a more up-to-date compiler. If you choose to use this version, make sure you run the regressiontests.")
333 endif()
334
335 set(PKG_CFLAGS "")
336 if(GMX_DOUBLE)
337     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
338 endif(GMX_DOUBLE)
339 if(GMX_SOFTWARE_INVSQRT)
340   set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
341 endif(GMX_SOFTWARE_INVSQRT)
342
343
344
345 ########################################################################
346 # Basic system tests (standard libraries, headers, functions, types)   #
347 ########################################################################
348 include(CheckIncludeFiles)
349 check_include_files(string.h     HAVE_STRING_H)
350 check_include_files(math.h       HAVE_MATH_H)
351 check_include_files(limits.h     HAVE_LIMITS_H)
352 check_include_files(memory.h     HAVE_MEMORY_H)
353 check_include_files(unistd.h     HAVE_UNISTD_H)
354 check_include_files(direct.h     HAVE_DIRECT_H)
355 check_include_files(pwd.h        HAVE_PWD_H)
356 check_include_files(stdint.h     HAVE_STDINT_H)
357 check_include_files(stdlib.h     HAVE_STDLIB_H)
358 check_include_files(pthread.h    HAVE_PTHREAD_H)
359 check_include_files(dirent.h     HAVE_DIRENT_H)
360 check_include_files(inttypes.h   HAVE_INTTYPES_H)
361 check_include_files(regex.h      HAVE_REGEX_H)
362 check_include_files(sys/types.h  HAVE_SYS_TYPES_H)
363 check_include_files(sys/stat.h   HAVE_SYS_STAT_H)
364 check_include_files(sys/time.h   HAVE_SYS_TIME_H)
365 check_include_files(rpc/rpc.h    HAVE_RPC_RPC_H)
366 check_include_files("rpc/rpc.h;rpc/xdr.h"    HAVE_RPC_XDR_H)
367 check_include_files(io.h                 HAVE_IO_H)
368 check_include_files(sched.h      HAVE_SCHED_H)
369
370 include(CheckFunctionExists)
371 check_function_exists(strcasecmp        HAVE_STRCASECMP)
372 check_function_exists(strdup            HAVE_STRDUP)
373 check_function_exists(vprintf           HAVE_VPRINTF)
374 check_function_exists(memcmp            HAVE_MEMCMP)
375 check_function_exists(posix_memalign    HAVE_POSIX_MEMALIGN)
376 check_function_exists(memalign          HAVE_MEMALIGN)
377 check_function_exists(_aligned_malloc   HAVE__ALIGNED_MALLOC)
378 check_function_exists(gettimeofday      HAVE_GETTIMEOFDAY)
379 check_function_exists(isnan             HAVE_ISNAN)
380 check_function_exists(_isnan            HAVE__ISNAN)
381 check_function_exists(fsync             HAVE_FSYNC)
382 check_function_exists(_fileno           HAVE__FILENO)
383 check_function_exists(fileno            HAVE_FILENO)
384 check_function_exists(_commit           HAVE__COMMIT)
385 check_function_exists(sigaction         HAVE_SIGACTION)
386 check_function_exists(sysconf           HAVE_SYSCONF)
387 check_function_exists(sched_setaffinity HAVE_SCHED_SETAFFINITY)
388 check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
389 check_function_exists(rsqrt             HAVE_RSQRT)
390 check_function_exists(rsqrtf            HAVE_RSQRTF)
391 check_function_exists(sqrtf             HAVE_SQRTF)
392
393 include(CheckLibraryExists)
394 check_library_exists(m sqrt "" HAVE_LIBM)
395 check_library_exists(m cbrt "" HAVE_CBRT)
396
397
398 include(CheckTypeSize)
399
400 check_type_size("bool"          SIZEOF_BOOL) # will also set HAVE_BOOL
401 check_type_size("int"           SIZEOF_INT) 
402 check_type_size("long int"      SIZEOF_LONG_INT) 
403 check_type_size("long long int" SIZEOF_LONG_LONG_INT) 
404 check_type_size("off_t"         SIZEOF_OFF_T)
405 check_type_size("void *"        SIZEOF_VOIDP)
406
407 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
408     set(GMX_64_BIT TRUE)
409 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
410     set(GMX_64_BIT FALSE)
411 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
412
413 # Check for some basic types that we *need*, so set these to int if they are not present 
414 check_type_size(uid_t uid_t)
415 if(NOT uid_t)
416   set(uid_t int)
417 else(NOT uid_t)
418   set(uid_t 0)
419 endif(NOT uid_t)
420
421 check_type_size(gid_t gid_t)
422 if(NOT gid_t)
423   set(gid_t 1)
424 else(NOT gid_t)
425   set(gid_t 0)
426 endif(NOT gid_t)
427
428 check_type_size(size_t size_t)
429 if(NOT size_t)
430   set(size_t int)
431 else(NOT size_t)
432   set(size_t 0)
433 endif(NOT size_t)
434
435 check_type_size(off_t off_t)
436 if(NOT off_t)
437   set(off_t int)
438 else(NOT off_t)
439   set(off_t 0)
440 endif(NOT off_t)
441
442 include(TestBigEndian)
443 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
444
445
446 if(APPLE OR CYGWIN OR ${CMAKE_SYSTEM_NAME} MATCHES "Linux|.*BSD|GNU")
447     # Maybe Solaris should be here? Patch this if you know!
448     SET(SHARED_LIBS_DEFAULT ON)
449 elseif(WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "BlueGene")
450     # Support for shared libs on native Windows is a bit new. Its
451     # default might change later if/when we sort things out. Also,
452     # Cray should go here. What variable value can detect it?
453     SET(SHARED_LIBS_DEFAULT OFF)
454 else()
455     message(STATUS "Defaulting to building static libraries")
456     SET(SHARED_LIBS_DEFAULT OFF)
457 endif()
458
459 # Management of GROMACS options for specific toolchains should go
460 # here. Because the initial settings for some of the main options have
461 # already happened, but things like library detection and MPI compiler
462 # feature detection have not, the docstrings for any over-rides of
463 # GROMACS defaults or user settings will make sense. Also, any
464 # toolchain-related reasons for choosing whether to detect various
465 # things can be sorted out now, before the detection takes place.
466 if(${CMAKE_SYSTEM_NAME} MATCHES BlueGene)
467     include(gmxManageBlueGene)
468 endif()
469
470 if(UNIX AND GMX_PREFER_STATIC_LIBS AND SHARED_LIBS_DEFAULT)
471     if(BUILD_SHARED_LIBS)
472         # Warn the user about the combination. But don't overwrite the request.
473         message(WARNING "Searching for static libraries requested, and building shared Gromacs libraries requested. This might cause problems linking later.")
474     elseif(NOT DEFINED BUILD_SHARED_LIBS)
475         # Change default to OFF. Don't warn if it's already off.
476         message(WARNING "Searching for static libraries requested, so the GROMACS libraries will also be built statically (BUILD_SHARED_LIBS=OFF)")
477         set(SHARED_LIBS_DEFAULT OFF)
478     endif()
479 endif()
480
481 # By now, all tool chains should have spoken up if they care about
482 # the setting of SHARED_LIBS_DEFAULT.
483 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic e.g. with MPI, or on some HPC systems)" ${SHARED_LIBS_DEFAULT})
484
485 ########################################################################
486 #Process MPI settings
487 ########################################################################
488 include(gmxManageMPI)
489
490 ########################################################################
491 # Find external packages                                               #
492 ########################################################################
493 if(UNIX AND GMX_PREFER_STATIC_LIBS)
494     # On Linux .a is the static library suffix, on Mac OS X .lib can also
495     # be used, so we'll add both to the preference list.
496     SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
497 endif()
498
499 IF( WIN32 AND NOT CYGWIN)
500   if (NOT BUILD_SHARED_LIBS)
501       option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
502       if(NOT GMX_PREFER_STATIC_LIBS)
503           message(WARNING "Shared system libraries requested, and static Gromacs libraries requested.")
504       endif()
505   else()
506       option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" OFF)
507       if(GMX_PREFER_STATIC_LIBS)
508           #this combination segfaults (illigal passing of file handles)
509           message(FATAL_ERROR "Static system libraries requested, and shared Gromacs libraries requested.")
510       endif()
511       add_definitions(-DUSE_VISIBILITY -DTMPI_USE_VISIBILITY)
512       set(PKG_CFLAGS "$PKG_CFLAGS -DUSE_VISIBILITY -DTMPI_USE_VISIBILITY")
513   endif()
514   mark_as_advanced(GMX_PREFER_STATIC_LIBS)
515
516   IF (GMX_PREFER_STATIC_LIBS)
517       #Only setting Debug and Release flags. Others configurations are current not used.
518       STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
519       STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
520       if(CMAKE_CXX_COMPILER_LOADED)
521           STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
522           STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
523       endif()
524   ENDIF()
525   IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
526     if(BUILD_SHARED_LIBS) #not sure why incremental building with shared libs doesn't work
527         STRING(REPLACE "/INCREMENTAL:YES" "" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
528     endif()
529   ENDIF()
530 ENDIF()
531
532 option(GMX_GSL "Add support for gsl" OFF)
533 if (GMX_GSL)
534   find_package(GSL)
535   set(PKG_GSL "")
536   if(GSL_FOUND)
537     include_directories(${GSL_INCLUDE_DIR})
538     set(PKG_GSL gsl)
539     set(HAVE_LIBGSL 1)
540   endif(GSL_FOUND)
541 endif (GMX_GSL)
542
543 option(GMX_X11 "Use X window system" OFF)
544 if (GMX_X11)
545     find_package(X11)
546     # X11 includes/libraries are only set in the ngmx subdirectory!
547     if(NOT X11_FOUND)
548         message(WARNING "X11 include files and/or libraries were not found. Will not build the GROMACS X11-binaries, such as ngmx")
549     endif()
550 endif(GMX_X11)
551
552 include(ThreadMPI)
553 set(THREAD_MPI_LIB thread_mpi)
554 # Enable core threading facilities
555 tmpi_enable_core("${CMAKE_SOURCE_DIR}/include")
556 # Enable tMPI C++ support
557 # tmpi_enable_cxx()
558 if(GMX_THREAD_MPI)
559     # enable MPI functions
560     tmpi_enable()
561     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
562     set(GMX_MPI 1)
563 endif(GMX_THREAD_MPI)
564 tmpi_get_source_list(THREAD_MPI_SRC)
565
566 if(GMX_GPU)
567     # now that we have detected the dependencies, do the second configure pass
568     gmx_gpu_setup()
569 endif(GMX_GPU)
570
571 if(CYGWIN)
572     set(GMX_CYGWIN 1)
573 endif(CYGWIN)
574
575 if(WIN32 AND NOT CYGWIN)
576     set(GMX_NATIVE_WINDOWS 1)
577 endif()
578
579 # only bother with finding git and using version.h if the source is a git repo
580 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
581     if(USE_VERSION_H)
582         # We need at least git v1.5.3 be able to parse git's date output. If not
583         # found or the version is too small, we can't generate version information.
584         find_package(Git)
585
586         # Find out the git version
587         if(GIT_FOUND AND NOT GIT_VERSION)
588           execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
589             OUTPUT_VARIABLE _exec_out
590             OUTPUT_STRIP_TRAILING_WHITESPACE)
591           string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
592           set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
593           mark_as_advanced(GIT_VERSION)
594         endif()
595
596         if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
597           message("No compatible git version found, won't be able to generate proper development version information.")
598           set(USE_VERSION_H OFF)
599         endif()
600     endif()
601 else()
602     set(USE_VERSION_H OFF)
603 endif()
604
605 ########################################################################
606 # Generate development version info for cache
607 ########################################################################
608 # set(GEN_VERSION_INFO_INTERNAL "ON")
609 # include(gmxGenerateVersionString)
610
611 ########################################################################
612 # Our own GROMACS tests
613 ########################################################################
614
615 add_definitions( -DHAVE_CONFIG_H )
616 include_directories(${CMAKE_BINARY_DIR}/src)
617 include_directories(${CMAKE_BINARY_DIR}/include)
618 include_directories(${CMAKE_SOURCE_DIR}/include)
619
620 include(gmxTestInlineASM)
621 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
622
623 include(gmxSetBuildInformation)
624 gmx_set_build_information()
625 # Turn on RDTSCP if:
626 # - the build system's CPU supports it
627 # - the acceleration is set to AVX as all AVX-capable CPUs support AVX (which
628 #   at this point means that the user set it).
629 # Note: it's better to not use the later set value of GMX_CPU_ACCELERATION because
630 # it reflects the system's capability of both compiling and running AVX code.
631 # TODO: After merge with 5.0 one could implement a cache variable dependency
632 # such that GMX_USE_RDTSCP can change if GMX_CPU_ACCELERATION is changed to AVX
633 # after the first cmake pass.
634 if (BUILD_CPU_FEATURES MATCHES "rdtscp" OR GMX_CPU_ACCELERATION MATCHES "AVX")
635     set(GMX_USE_RDTSCP_DEFAULT_VALUE ON)
636 else()
637     set(GMX_USE_RDTSCP_DEFAULT_VALUE OFF)
638 endif()
639 option(GMX_USE_RDTSCP "Use RDTSCP for better CPU-based timers (available on recent x86 CPUs; might need to be off when compiling for heterogeneous environments)" ${GMX_USE_RDTSCP_DEFAULT_VALUE})
640 mark_as_advanced(GMX_USE_RDTSCP)
641 if(GMX_USE_RDTSCP)
642     # The timestep counter headers do not include config.h
643     add_definitions(-DHAVE_RDTSCP)
644 endif()
645
646 include(gmxTestFloatFormat)
647 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754 
648                       GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
649                       GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
650
651 include(gmxTestLargeFiles)
652 gmx_test_large_files(GMX_LARGEFILES)
653
654 include(gmxTestSignal)
655 gmx_test_sigusr1(HAVE_SIGUSR1)
656
657 include(gmxTestInline)
658 gmx_test_inline(INLINE_KEYWORD)
659
660 include(gmxTestRestrict)
661 gmx_test_restrict(RESTRICT_KEYWORD)
662
663 include(gmxTestPipes)
664 gmx_test_pipes(HAVE_PIPES)
665
666 include(gmxTestIsfinite)
667 gmx_test_isfinite(HAVE_ISFINITE)
668 gmx_test__isfinite(HAVE__ISFINITE)
669 gmx_test__finite(HAVE__FINITE)
670
671 include(gmxTestXDR)
672 gmx_test_xdr(GMX_SYSTEM_XDR)
673 if(NOT GMX_SYSTEM_XDR)
674     set(GMX_INTERNAL_XDR 1)
675     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
676 endif(NOT GMX_SYSTEM_XDR)
677
678 # include avx test source, used if the AVX flags are set below
679 include(gmxTestAVXMaskload)
680
681 # Process nonbonded accelerated kernels settings
682 #
683 # Note that for the backward-compatible x86 SIMD architectures, the
684 # GMX_CPU_ACCELERATION determines the maximum level of the instruction
685 # set used (e.g. GMX_CPU_ACCLERATION=SSE4.1 implies
686 # SSE2). Accordingly, there are a set of CMake variables
687 # GMX_<arch>_<feature-set> that are exported to the C code to specify
688 # CPU features that should be used. This means that the logic for
689 # requiring such backward compatibility is all located here.
690 string(TOUPPER ${GMX_CPU_ACCELERATION} GMX_CPU_ACCELERATION)
691 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
692     # nothing to do
693 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
694
695     GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" ACCELERATION_C_FLAGS)
696     if(NOT GNU_SSE2_CFLAG AND GMX_NATIVE_WINDOWS)
697         GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" ACCELERATION_C_FLAGS)
698     endif(NOT GNU_SSE2_CFLAG AND GMX_NATIVE_WINDOWS)
699
700     if (CMAKE_CXX_COMPILER_LOADED)
701         GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" ACCELERATION_CXX_FLAGS)
702         if(NOT GNU_SSE2_CXXFLAG AND GMX_NATIVE_WINDOWS)
703             GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" ACCELERATION_CXX_FLAGS)
704         endif(NOT GNU_SSE2_CXXFLAG AND GMX_NATIVE_WINDOWS)
705     endif()
706
707     # We dont warn for lacking SSE2 flag support, since that is probably standard today.
708
709     # Only test the include after we have tried to add the correct flag for SSE2 support
710     check_include_file(emmintrin.h  HAVE_EMMINTRIN_H ${ACCELERATION_C_FLAGS})
711
712     if(NOT HAVE_EMMINTRIN_H)
713         message(FATAL_ERROR "Cannot find emmintrin.h, which is required for SSE2 intrinsics support.")
714     endif(NOT HAVE_EMMINTRIN_H)
715
716     set(GMX_CPU_ACCELERATION_X86_SSE2 1)
717     # The user should not be able to set this orthogonally to the acceleration
718     set(GMX_X86_SSE2 1)
719     if (NOT ACCELERATION_QUIETLY)
720       message(STATUS "Enabling SSE2 Gromacs acceleration")
721     endif()
722
723 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
724
725     GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" ACCELERATION_C_FLAGS)
726     if (NOT GNU_SSE4_CFLAG AND GMX_NATIVE_WINDOWS)
727         GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" ACCELERATION_C_FLAGS)
728     endif(NOT GNU_SSE4_CFLAG AND GMX_NATIVE_WINDOWS)
729     if (NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
730         # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
731         # intrinsics when SSE2 support is enabled, so we try that instead first.
732         if (GMX_NATIVE_WINDOWS)
733             GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" ACCELERATION_C_FLAGS)
734             message(WARNING "Neither SSE4.1 or SSE2 seems to be supported by your Windows compiler. Something is likely broken.")
735         else()
736             message(WARNING "No C SSE4.1 flag found. Consider a newer compiler, or use SSE2 for slightly lower performance")
737         endif()
738     endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
739
740     if (CMAKE_CXX_COMPILER_LOADED)
741         GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" ACCELERATION_CXX_FLAGS)
742         if (NOT GNU_SSE4_CXXFLAG AND GMX_NATIVE_WINDOWS)
743             GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" ACCELERATION_CXX_FLAGS)
744         endif(NOT GNU_SSE4_CXXFLAG AND GMX_NATIVE_WINDOWS)
745         if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG) 
746             message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or use SSE2 for slightly lower performance.")
747             # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
748             # intrinsics when SSE2 support is enabled, so we try that instead.
749             if (GMX_NATIVE_WINDOWS)
750                 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" ACCELERATION_CXX_FLAGS)
751             endif()
752         endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
753     endif()
754
755     # This must come after we have added the -msse4.1 flag on some platforms.
756     check_include_file(smmintrin.h  HAVE_SMMINTRIN_H ${ACCELERATION_C_FLAGS})
757
758     if(NOT HAVE_SMMINTRIN_H)
759         message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
760     endif(NOT HAVE_SMMINTRIN_H)
761
762     set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
763     # The user should not be able to set this orthogonally to the acceleration
764     set(GMX_X86_SSE4_1 1)
765     set(GMX_X86_SSE2   1)
766     if (NOT ACCELERATION_QUIETLY)
767       message(STATUS "Enabling SSE4.1 Gromacs acceleration")
768     endif()
769
770     if(CMAKE_C_COMPILER_ID MATCHES "Intel" AND C_COMPILER_VERSION VERSION_EQUAL "11.1")
771         message(FATAL_ERROR "You are using Intel compiler version 11.1, and that compiler is known to produce incorrect results with SSE4.1 acceleration. You need to use another compiler (e.g. icc 12 or newer) or different acceleration (probably slower simulations).")
772     endif()
773 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
774
775     # Set the AVX compiler flag for both these choices!
776
777     GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" ACCELERATION_C_FLAGS)
778     if (NOT GNU_AVX_CFLAG AND GMX_NATIVE_WINDOWS)
779         GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" ACCELERATION_C_FLAGS)
780     endif (NOT GNU_AVX_CFLAG AND GMX_NATIVE_WINDOWS)
781     if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
782         message(WARNING "No C AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance) giving the -DGMX_CPU_ACCELERATION=SSE4.1 to cmake.")
783     endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
784
785     if (CMAKE_CXX_COMPILER_LOADED)
786         GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" ACCELERATION_CXX_FLAGS)
787         if (NOT GNU_AVX_CXXFLAG AND GMX_NATIVE_WINDOWS)
788             GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" ACCELERATION_CXX_FLAGS)
789         endif (NOT GNU_AVX_CXXFLAG AND GMX_NATIVE_WINDOWS)
790         if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
791             message(WARNING "No C++ AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance) giving the -DGMX_CPU_ACCELERATION=SSE4.1 to cmake.")
792         endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
793     endif()
794
795     # Set the FMA4 flags (MSVC doesn't require any)
796     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
797         GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" ACCELERATION_C_FLAGS)
798         if (NOT GNU_FMA_CFLAG)
799             message(WARNING "No C FMA4 flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
800         endif(NOT GNU_FMA_CFLAG)
801         GMX_TEST_CFLAG(GNU_XOP_CFLAG "-mxop" ACCELERATION_C_FLAGS)
802         # No big deal if we do not have xop, so no point yelling warnings about it.
803         if (CMAKE_CXX_COMPILER_LOADED)
804             GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" ACCELERATION_CXX_FLAGS)
805             if (NOT GNU_FMA_CXXFLAG)
806                 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
807             endif (NOT GNU_FMA_CXXFLAG)
808             GMX_TEST_CXXFLAG(GNU_XOP_CXXFLAG "-mxop" ACCELERATION_CXX_FLAGS)
809             # No big deal if we do not have xop, so no point yelling warnings about it.
810         endif()
811     endif()
812
813     # Only test the header after we have tried to add the flag for AVX support
814     check_include_file(immintrin.h  HAVE_IMMINTRIN_H ${ACCELERATION_C_FLAGS})
815
816     if(NOT HAVE_IMMINTRIN_H)
817         message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
818     endif(NOT HAVE_IMMINTRIN_H)
819
820     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
821         try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
822             "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
823             COMPILE_DEFINITIONS "${ACCELERATION_C_FLAGS}")
824         if(NOT TEST_AVX)
825             message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
826         endif()
827     endif()
828
829     # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
830     check_include_file(x86intrin.h HAVE_X86INTRIN_H ${ACCELERATION_C_FLAGS})
831     check_include_file(intrin.h HAVE_INTRIN_H ${ACCELERATION_C_FLAGS})
832
833     # The user should not be able to set this orthogonally to the acceleration
834     set(GMX_X86_SSE4_1 1)
835     set(GMX_X86_SSE2   1)
836
837     # But just enable one of the choices internally...
838     if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
839         set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
840         set(GMX_X86_AVX_128_FMA 1)
841         if (NOT ACCELERATION_QUIETLY)
842           message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add)")
843         endif()
844
845         # We don't have the full compiler version string yet (BUILD_C_COMPILER),
846         # so we can't distinguish vanilla and Apple clang, but catering for AMD
847         # hackintoshes is not worth the effort.
848         if (APPLE AND ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
849             message(WARNING "Due to a known compiler bug, Clang up to version 3.2 (and Apple Clang up to version 4.1) produces incorrect code with AVX_128_FMA acceleration. As we can not work around this bug on OS X, you will have to select a different compiler or CPU acceleration.")
850         endif()
851
852         if (GMX_USE_CLANG_FMA_BUG_WORKAROUND)
853             # we assume that we have an external assembler that supports AVX
854             message(STATUS "Clang ${C_COMPILER_VERSION} detected, enabling FMA bug workaround")
855             set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -no-integrated-as")
856         endif()
857
858     else()
859         # If we are not doing AVX_128, it must be AVX_256...
860         set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
861         set(GMX_X86_AVX_256 1)
862         if (NOT ACCELERATION_QUIETLY)
863           message(STATUS "Enabling 256-bit AVX Gromacs acceleration")
864         endif()
865     endif()
866
867     # Unfortunately gcc-4.5.2 and gcc-4.6.0 has a bug where they use the wrong datatype for the formal
868     # parameter of the mask for maskload/maskstore arguments. Check if this is present, since we can work around it.
869     gmx_test_avx_gcc_maskload_bug(${ACCELERATION_C_FLAGS} GMX_X86_AVX_GCC_MASKLOAD_BUG)
870
871 elseif(${GMX_CPU_ACCELERATION} STREQUAL "IBM_QPX")
872     try_compile(TEST_QPX ${CMAKE_BINARY_DIR}
873         "${CMAKE_SOURCE_DIR}/cmake/TestQPX.c")
874
875     if (TEST_QPX)
876         message(WARNING "IBM QPX acceleration was selected. This will work, but SIMD-accelerated kernels are only available for the Verlet cut-off scheme. The plain C kernels that are used for the group cut-off scheme kernels will be slow, so please consider using the Verlet cut-off scheme.")
877         set(GMX_CPU_ACCELERATION_IBM_QPX 1)
878     else()
879         message(FATAL_ERROR "Cannot compile the requested IBM QPX intrinsics. If you are compiling for BlueGene/Q with the XL compilers, use 'cmake .. -DCMAKE_TOOLCHAIN_FILE=Platform/BlueGeneQ-static-XL-C' to set up the tool chain.")
880     endif()
881 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SPARC64_HPC_ACE")
882     set(GMX_CPU_ACCELERATION_SPARC64_HPC_ACE 1)
883 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
884     MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_CPU_ACCELERATION}. Pick one of None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, IBM_QPX, Sparc64_HPC_ACE")
885 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
886 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
887
888 # Process QM/MM Settings
889 string(TOUPPER ${GMX_QMMM_PROGRAM} GMX_QMMM_PROGRAM)
890 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
891     set(GMX_QMMM_GAUSSIAN 1)
892 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
893     set(GMX_QMMM_MOPAC 1)
894 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
895     set(GMX_QMMM_GAMESS 1)
896 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
897     set(GMX_QMMM_ORCA 1)
898 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
899     # nothing to do
900 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
901     MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
902 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
903
904 # Process FFT library settings
905 string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
906 set(PKG_FFT "")
907 set(PKG_FFT_LIBS "")
908 set(MKL_LIBRARIES_FORMAT_DESCRIPTION "Use full paths to library files, in the right order, and separated by semicolons.")
909 set(MKL_LIBRARIES "" CACHE STRING "List of libraries for linking to MKL. Only used with GMX_FFT_LIBRARY=mkl. ${MKL_LIBRARIES_FORMAT_DESCRIPTION}")
910 set(MKL_INCLUDE_DIR "" CACHE PATH "Path to mkl.h (non-inclusive). Only used with GMX_FFT_LIBRARY=mkl.")
911 mark_as_advanced(FORCE MKL_LIBRARIES)
912 mark_as_advanced(FORCE MKL_INCLUDE_DIR)
913 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
914     if(GMX_DOUBLE)
915         set(FFTW fftw)
916     else()
917         set(FFTW fftwf)
918     endif()
919
920     if(GMX_BUILD_OWN_FFTW)
921       add_subdirectory(src/contrib/fftw)
922     else()
923       find_package(FFTW COMPONENTS ${FFTW})
924     endif()
925
926     string(TOUPPER "${FFTW}" FFTW)
927     if(NOT ${FFTW}_FOUND)
928       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 (-DGMX_FFT_LIBRARY), enable the advanced option to let GROMACS build FFTW 3 for you (-DGMX_BUILD_OWN_FFTW=ON) , or use the really slow GROMACS built-in fftpack library (-DGMX_FFT_LIBRARY=fftpack).")
929     endif()
930
931     set(PKG_FFT "${${FFTW}_PKG}")
932     include_directories(${${FFTW}_INCLUDE_DIRS})
933     set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
934     set(GMX_FFT_FFTW3 1)
935
936     if ((${GMX_CPU_ACCELERATION} MATCHES "SSE" OR ${GMX_CPU_ACCELERATION} MATCHES "AVX") AND NOT ${FFTW}_HAVE_SIMD)
937       message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
938     endif()
939
940     if((${GMX_CPU_ACCELERATION} MATCHES "SSE" OR ${GMX_CPU_ACCELERATION} MATCHES "AVX") AND ${FFTW}_HAVE_AVX)
941         # If we're not doing CPU acceleration, we don't care about FFTW performance on x86 either
942         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.")
943     endif()
944
945     if(NOT "${GMX_FFT_LIBRARY}" STREQUAL "${GMX_FFT_LIBRARY_PREVIOUS_VALUE}")
946         MESSAGE(STATUS "Using external FFT library - FFTW3")
947     endif()
948 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
949     # Intel 11 and up makes life somewhat easy if you just want to use
950     # all their stuff. It's not easy if you only want some of their
951     # stuff...
952     if (CMAKE_C_COMPILER_ID MATCHES "Intel" AND C_COMPILER_VERSION VERSION_GREATER "11")
953         # The next line takes care of everything for MKL
954         if (WIN32)
955             set(FFT_LINKER_FLAGS "/Qmkl=sequential")
956         else()
957             set(FFT_LINKER_FLAGS "-mkl=sequential")
958         endif()
959         # Some versions of icc require this in order that mkl.h can be
960         # found at compile time.
961         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} ${FFT_LINKER_FLAGS}")
962
963         set(MKL_ERROR_MESSAGE "Make sure you have configured your compiler so that ${FFT_LINKER_FLAGS} will work.")
964     else()
965         # The user will have to provide the set of magic libraries in
966         # MKL_LIBRARIES, which we cache (non-advanced), so that they
967         # don't have to keep specifying it, and can easily see that
968         # CMake is still using that information.
969         set(MKL_LIBRARIES "${MKL_LIBRARIES}" CACHE STRING "User-specified libraries for linking to MKL")
970         mark_as_advanced(CLEAR MKL_LIBRARIES)
971         include_directories(${MKL_INCLUDE_DIR})
972         mark_as_advanced(CLEAR MKL_INCLUDE_DIR)
973         set(FFT_LIBRARIES "${MKL_LIBRARIES}")
974         set(MKL_ERROR_MESSAGE "The include path to mkl.h in MKL_INCLUDE_DIR, and the link libraries in MKL_LIBRARIES=${MKL_LIBRARIES} need to match what the MKL documentation says you need for your system. ${MKL_LIBRARIES_FORMAT_DESCRIPTION}")
975         # Convert the semi-colon separated list to a list of
976         # command-line linker arguments so that code using our
977         # pkgconfig setup can use it.
978         string(REGEX REPLACE ";" " " PKG_FFT_LIBS "${MKL_LIBRARIES}")
979     endif()
980
981     # Check MKL works. If we were in a non-global scope, we wouldn't
982     # have to play nicely.
983     set(old_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
984     set(CMAKE_REQUIRED_FLAGS "${FFT_LINKER_FLAGS}")
985     set(old_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
986     set(CMAKE_REQUIRED_LIBRARIES "${FFT_LIBRARIES}")
987
988     check_function_exists(DftiCreateDescriptor TEST_MKL)
989
990     set(CMAKE_REQUIRED_FLAGS "${old_CMAKE_REQUIRED_FLAGS}")
991     set(CMAKE_REQUIRED_LIBRARIES "${old_CMAKE_REQUIRED_LIBRARIES}")
992
993     if(NOT TEST_MKL)
994         # Hack to help the user vary MKL settings until they work.
995         # TODO Make this logic more useful.
996         unset(TEST_MKL CACHE)
997         message(FATAL_ERROR "Linking with MKL was requested, but was not successful. ${MKL_ERROR_MESSAGE}")
998     endif()
999
1000     # Set variables to signal that we have MKL available and should use it for FFTs.
1001     set(GMX_FFT_MKL 1)
1002     set(HAVE_LIBMKL 1)
1003
1004     if(NOT "${GMX_FFT_LIBRARY}" STREQUAL "${GMX_FFT_LIBRARY_PREVIOUS_VALUE}")
1005         MESSAGE(STATUS "Using external FFT library - Intel MKL")
1006     endif()
1007
1008 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
1009 #    MESSAGE(STATUS "Using external FFT library - AMD core math library")
1010 #    set(GMX_FFT_ACML 1)
1011 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
1012     set(GMX_FFT_FFTPACK 1)
1013     if(NOT "${GMX_FFT_LIBRARY}" STREQUAL "${GMX_FFT_LIBRARY_PREVIOUS_VALUE}")
1014         MESSAGE(STATUS "Using internal FFT library - fftpack")
1015     endif()
1016 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
1017     MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
1018 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
1019 set(GMX_FFT_LIBRARY_PREVIOUS_VALUE ${GMX_FFT_LIBRARY} CACHE INTERNAL "Previous value for GMX_FFT_LIBRARY, so that we can detect when it changes.")
1020
1021 # enable threaded fftw3 if we've found it 
1022 if(FFTW3_THREADS OR FFTW3F_THREADS)
1023     add_definitions(-DFFT5D_FFTW_THREADS)
1024 endif()
1025
1026 include(gmxManageLinearAlgebraLibraries)
1027
1028 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
1029
1030 if(GMX_LOAD_PLUGINS)
1031   if(CYGWIN OR NOT WIN32)
1032     # Native Windows does not have, nor need dlopen
1033     # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
1034     include(gmxTestdlopen)
1035     gmx_test_dlopen(HAVE_DLOPEN)
1036   endif()
1037
1038   # so, should we use plug-ins?
1039   if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1040     if(NOT VMD_QUIETLY)
1041       MESSAGE(STATUS
1042           "Found the ability to use plug-ins when building shared libaries, "
1043           "so will compile to use plug-ins (e.g. to read VMD-supported file "
1044           "formats).")
1045     endif()
1046     if(NOT GMX_VMD_PLUGIN_PATH)
1047       find_package(VMD)
1048     endif()
1049     set(GMX_USE_PLUGINS ON)
1050     list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1051     set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1052   else()
1053     set(PKG_DL_LIBS)
1054   endif()
1055 endif(GMX_LOAD_PLUGINS)
1056 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1057
1058 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1059     if(NOT CMAKE_CROSSCOMPILING)
1060         option(GMX_BUILD_MANPAGES "Build man pages" ON)
1061     else()
1062         message(STATUS "Building the man pages is not available when "
1063             "cross-compiling the developer version from git")
1064     endif()
1065 else()
1066     #make sure source package contains all man pages
1067     if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1068         message(FATAL_ERROR "Man pages are missing from source package.")
1069     endif()
1070 endif()
1071 mark_as_advanced(GMX_BUILD_MANPAGES)
1072
1073 # Math and thread libraries must often come after all others when linking...
1074 if(HAVE_LIBM)
1075     list(APPEND GMX_EXTRA_LIBRARIES m)
1076 endif(HAVE_LIBM)
1077 if (${CMAKE_SYSTEM_NAME} MATCHES "BlueGene")
1078     check_library_exists(mass_simd atan2f4 "" HAVE_MASS_SIMD)
1079     if(HAVE_MASS_SIMD)
1080         list(APPEND GMX_EXTRA_LIBRARIES mass_simd)
1081     else()
1082         message(FATAL_ERROR "Could not link to the SIMD version of the IBM MASS library. Please adjust your CMAKE_PREFIX_PATH to contain it")
1083     endif()
1084 endif()
1085
1086
1087 option(GMX_NACL "Configure for Native Client builds" OFF)
1088 if (GMX_NACL)
1089   list(APPEND GMX_EXTRA_LIBRARIES nosys)
1090   set(GMX_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lnosys")
1091   set(GMX_NO_NICE 1)
1092   set(GMX_NO_RENAME 1)
1093 endif()
1094 mark_as_advanced(GMX_NACL)
1095
1096 if(GMX_FAHCORE)
1097   set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING 
1098       "Path to swindirect.h")
1099   include_directories(${COREWRAP_INCLUDE_DIR})
1100   set_property(CACHE GMX_COOL_QUOTES PROPERTY VALUE OFF)
1101 endif(GMX_FAHCORE)
1102
1103 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1104 # these are set after everything else
1105 if (NOT GMX_SKIP_DEFAULT_CFLAGS)
1106     set(CMAKE_C_FLAGS "${ACCELERATION_C_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_C_FLAGS} ${CMAKE_C_FLAGS}")
1107     set(CMAKE_CXX_FLAGS "${ACCELERATION_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${CMAKE_CXX_FLAGS}")
1108     set(CMAKE_EXE_LINKER_FLAGS "${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
1109     set(CMAKE_SHARED_LINKER_FLAGS "${MPI_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
1110 else()
1111     message("Recommended flags which are not added because GMX_SKIP_DEFAULT_CFLAGS=yes:")
1112     message("CMAKE_C_FLAGS: ${ACCELERATION_C_FLAGS} ${MPI_COMPILE_FLAGS} ${EXTRA_C_FLAGS} ${GMXC_CFLAGS}")
1113     message("CMAKE_C_FLAGS_RELEASE: ${GMXC_CFLAGS_RELEASE}")
1114     message("CMAKE_C_FLAGS_DEBUG: ${GMXC_CFLAGS_DEBUG}")
1115     if(CMAKE_CXX_COMPILER_LOADED)
1116         message("CMAKE_CXX_FLAGS: ${ACCELERATION_CXX_FLAGS} ${MPI_COMPILE_FLAGS} ${GMXC_CXXFLAGS}")
1117         message("CMAKE_CXX_FLAGS_RELEASE: ${GMXC_CXXFLAGS_RELEASE}")
1118         message("CMAKE_CXX_FLAGS_DEBUG: ${GMXC_CXXFLAGS_DEBUG}")
1119     endif()
1120     message("CMAKE_EXE_LINKER_FLAGS: ${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS}")
1121     message("CMAKE_SHARED_LINKER_FLAGS: ${MPI_LINKER_FLAGS}")
1122 endif()
1123
1124 if(NOT GMX_OPENMP)
1125     #Unset all OpenMP flags in case OpenMP was disabled either by the user
1126     #or because it was only partially detected (e.g. only for C but not C++ compiler)
1127     unset(OpenMP_C_FLAGS CACHE) 
1128     unset(OpenMP_CXX_FLAGS CACHE)
1129     unset(OpenMP_LINKER_FLAGS CACHE)
1130     unset(OpenMP_SHARED_LINKER_FLAGS)
1131 endif()
1132 set(PKG_CFLAGS "${PKG_CFLAGS} ${OpenMP_C_FLAGS}")
1133
1134 ######################################
1135 # Output compiler and CFLAGS used
1136 ######################################
1137 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
1138 if (CMAKE_CXX_COMPILER_LOADED)
1139     get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
1140 endif ()
1141 if(GMX_GPU)
1142     get_cuda_compiler_info(CUDA_NVCC_COMPILER_INFO CUDA_NVCC_COMPILER_FLAGS)
1143 endif(GMX_GPU)
1144
1145
1146 ########################################################################
1147 # Specify install locations and which subdirectories to process        #
1148 ########################################################################
1149 if (GMX_USE_RELATIVE_INSTALL_PATH)
1150     set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1151     mark_as_advanced(GMX_INSTALL_PREFIX)
1152 else()
1153     set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1154 endif()
1155
1156 if ( NOT DEFINED GMXLIB )
1157     set(GMXLIB lib)
1158 endif()
1159 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1160 set(BIN_INSTALL_DIR  ${GMX_INSTALL_PREFIX}bin)
1161 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1162 set(MAN_INSTALL_DIR  ${GMX_INSTALL_PREFIX}share/man)
1163 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1164
1165 set(GMXLIBDIR        ${DATA_INSTALL_DIR}/top)
1166
1167 ########################################################################
1168 # Set up binary and library suffixing
1169 ########################################################################
1170 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
1171 set(GMX_LIBS_SUFFIX ""
1172   CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
1173 if (GMX_DEFAULT_SUFFIX)
1174   set(GMX_BINARY_SUFFIX "")
1175   set(GMX_LIBS_SUFFIX "")
1176   if (GMX_LIB_MPI)
1177     set(GMX_BINARY_SUFFIX "_mpi")
1178     set(GMX_LIBS_SUFFIX "_mpi")
1179   endif()
1180   if (GMX_DOUBLE)
1181     set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
1182     set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
1183   endif(GMX_DOUBLE)
1184   mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
1185   if (NOT SUFFIX_QUIETLY)
1186     message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
1187     message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
1188   endif (NOT SUFFIX_QUIETLY)
1189 else(GMX_DEFAULT_SUFFIX)
1190   mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
1191   if (NOT SUFFIX_QUIETLY)
1192     message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
1193     message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
1194   endif (NOT SUFFIX_QUIETLY)
1195 endif(GMX_DEFAULT_SUFFIX)
1196 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
1197
1198 ################################################################
1199 # Shared library settings
1200 ################################################################
1201 if((NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") OR ((CMAKE_SYSTEM_VERSION VERSION_GREATER 8.0) AND (NOT CMAKE_VERSION VERSION_LESS 2.8.12)))
1202     set(CMAKE_SKIP_BUILD_RPATH  FALSE)
1203     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1204     if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1205         set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1206     else()
1207         set(CMAKE_INSTALL_RPATH "@executable_path/../${GMXLIB}")
1208     endif()
1209     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1210     set(CMAKE_MACOSX_RPATH 1)
1211 else()
1212     # We are on Darwin/OSX, and cmake cannot handle proper RPATHs
1213     set(CMAKE_INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
1214 endif()
1215
1216 #COPYING file: Only necessary for binary distributions.
1217 #Simpler to always install.
1218 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1219
1220 add_subdirectory(share)
1221 add_subdirectory(include)
1222 add_subdirectory(src)
1223 add_subdirectory(scripts)
1224
1225 # Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
1226 # Don't bother the user after the first configure pass.
1227 if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT GMX_GPU_DETECTION_DONE)
1228     message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
1229     unset(CUDA_NOTFOUND_AUTO)
1230     unset(CUDA_NOTFOUND_MESSAGE)
1231 endif()
1232 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
1233
1234 #######################
1235 ## uninstall target
1236 #######################
1237     CONFIGURE_FILE(
1238                    "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1239                    "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1240                    IMMEDIATE @ONLY)
1241 ###########################
1242 ADD_CUSTOM_TARGET(uninstall
1243                   "${CMAKE_COMMAND}" -P 
1244                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1245 ###########################
1246
1247 ########################################################################
1248 # Tests                                                                #
1249 ########################################################################
1250
1251 include(CTest)
1252 mark_as_advanced(BUILD_TESTING)
1253 #gmxtests target builds all binaries required for running gmxtest
1254 add_custom_target(gmxtests DEPENDS grompp mdrun pdb2gmx gmxcheck editconf)
1255 IF(BUILD_TESTING)
1256     enable_testing()
1257     add_subdirectory(tests)
1258     if(REGRESSIONTEST_PATH)
1259         #check target builds all to run tests and the runs tests
1260         add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
1261         add_dependencies(check gmxtests)
1262     else()
1263         add_custom_target(check COMMAND ${CMAKE_COMMAND} -E echo "WARNING: No tests are run. Running the tests requires either of the cmake variables REGRESSIONTEST_PATH or REGRESSIONTEST_DOWNLOAD to be set.")
1264     endif()
1265 ENDIF()
1266