2 # This file is part of the GROMACS molecular simulation package.
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.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 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
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")
45 mark_as_advanced(DART_ROOT)
47 # PROJECT_VERSION should have the following structure:
48 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
50 # The "-dev" suffix is important to keep because it makes possible to distinguish
51 # between a build from official release and a build from git release branch on a
52 # machine with no git.
54 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
55 set(PROJECT_VERSION "4.6-beta3-dev")
56 set(CUSTOM_VERSION_STRING ""
57 CACHE STRING "Custom version string (if empty, use hard-coded default)")
58 mark_as_advanced(CUSTOM_VERSION_STRING)
59 if (CUSTOM_VERSION_STRING)
60 set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
61 endif (CUSTOM_VERSION_STRING)
63 # It is a bit irritating, but this has to be set separately for now!
64 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
65 SET(CPACK_PACKAGE_VERSION_MINOR "6")
66 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
68 # The numerical gromacs version. It is 40600 for 4.6.0.
69 # The #define GMX_VERSION in gmx_header_config_h is set to this value.
71 "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
72 if(CPACK_PACKAGE_VERSION_PATCH)
74 "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
77 # The API version tracks the numerical Gromacs version (for now).
78 # It is potentially different from the Gromacs version in the future, if
79 # the programs/libraries diverge from the presumably more stable API.
80 # The #define GMX_API_VERSION in version.h is set to this value to
81 # provide backward compatibility of software written against the Gromacs API.
82 set(API_VERSION ${NUM_VERSION})
84 # Cmake modules/macros are in a subdirectory to keep this file cleaner
85 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
87 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
88 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
91 include(gmxBuildTypeReference)
93 if(NOT CMAKE_BUILD_TYPE)
94 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
95 endif(NOT CMAKE_BUILD_TYPE)
99 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
100 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
102 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
103 set(CPACK_PACKAGE_VENDOR "gromacs.org")
104 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
105 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
106 set(CPACK_SET_DESTDIR "ON")
108 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
109 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
110 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
111 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
112 set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$")
113 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
114 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
115 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
117 #must come after all cpack settings!
120 ########################################################################
121 # Check and warn if cache generated on a different host is being reused
122 ########################################################################
124 execute_process(COMMAND hostname
125 OUTPUT_VARIABLE TMP_HOSTNAME
126 OUTPUT_STRIP_TRAILING_WHITESPACE)
127 if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
129 The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
130 is being reused! This could lead to inconsitencies; therefore, it is
131 recommended to regenerate the cache!")
133 set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
134 "Hostname of the machine where the cache was generated.")
137 ########################################################################
138 # User input options - enable C++ - before any CXX flags are changed #
139 ########################################################################
141 # decide on GPU settings based on user-settings and GPU/CUDA detection
142 include(gmxManageGPU)
144 # TODO: move OpenMM to contrib
145 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (not fully supported)" OFF)
146 mark_as_advanced(GMX_OPENMM)
148 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
149 mark_as_advanced(GMX_FORCE_CXX)
151 option(GMX_NO_QUOTES "Disable Gromacs cool quotes" OFF)
153 if(GMX_GPU OR GMX_OPENMM OR GMX_FORCE_CXX)
156 set(CMAKE_PREFIX_PATH "" CACHE STRING "Extra locations to search for external libraries and tools (give directory without lib, bin, or include)")
158 ########################################################################
159 # Fix stupid flags on Windows
160 ########################################################################
161 SET(SHARED_LIBS_DEFAULT ON)
162 IF( WIN32 AND NOT CYGWIN)
163 if (NOT BUILD_SHARED_LIBS)
164 option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
165 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
166 SET(SHARED_LIBS_DEFAULT OFF)
168 add_definitions(-DUSE_VISIBILITY -DTMPI_USE_VISIBILITY)
171 IF (GMX_PREFER_STATIC_LIBS)
172 #Only setting Debug and Release flags. Others configurations current not used.
173 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
174 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
175 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
176 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
177 if(CMAKE_CXX_COMPILER_LOADED)
178 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
179 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
180 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
181 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
185 #Workaround for cmake bug 13174. Replace deprecated options.
186 IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
187 if(BUILD_SHARED_LIBS)
188 STRING(REPLACE "/INCREMENTAL:YES" "" CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
189 SET(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} CACHE STRING "" FORCE)
191 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
192 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
194 IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
195 STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
196 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
197 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
199 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
200 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
205 ########################################################################
206 # User input options #
207 ########################################################################
208 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
209 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
210 option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
211 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
212 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
213 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
214 mark_as_advanced(GMX_FAHCORE)
216 include(gmxDetectAcceleration)
217 if(NOT DEFINED GMX_CPU_ACCELERATION)
218 if(CMAKE_CROSSCOMPILING)
219 set(GMX_SUGGESTED_CPU_ACCELERATION "None")
220 else(CMAKE_CROSSCOMPILING)
221 gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
222 endif(CMAKE_CROSSCOMPILING)
223 endif(NOT DEFINED GMX_CPU_ACCELERATION)
225 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
226 CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene")
228 set(GMX_FFT_LIBRARY "fftw3"
229 CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
230 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)
231 mark_as_advanced(GMX_BUILD_OWN_FFTW)
232 option(GMX_DISABLE_FFTW_MEASURE
233 "Do not optimize FFTW setups (not needed with SSE)" OFF)
234 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
235 set(GMX_QMMM_PROGRAM "none"
236 CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
237 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
238 mark_as_advanced(GMX_BROKEN_CALLOC)
239 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
240 mark_as_advanced(GMX_MPI_IN_PLACE)
241 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
242 mark_as_advanced(GMX_LOAD_PLUGINS)
244 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
246 option(USE_VERSION_H "Generate development version string/information" ON)
247 mark_as_advanced(USE_VERSION_H)
249 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)
252 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)
253 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
256 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
257 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
259 ######################################################################
261 # These need to be done early (before further tests).
262 #####################################################################
264 # The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
265 # are used with permission from CMake v2.8.9 so that GROMACS can detect
266 # invalid options with the Intel Compilers.
267 # These files should be removed from the source tree when a CMake version that
268 # includes the features in question becomes required for building GROMACS.
269 include(CheckCCompilerFlag)
270 if(CMAKE_CXX_COMPILER_LOADED)
271 include(CheckCXXCompilerFlag)
274 # OpenMP check must come before other CFLAGS!
278 # CMake on Windows doesn't support linker flags passed to target_link_libraries
279 # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed.
280 if(NOT (WIN32 AND NOT CYGWIN))
281 if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
282 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
283 set(OpenMP_SHARED_LINKER_FLAGS "")
285 # Only set a linker flag if the user didn't set them manually
286 if(NOT DEFINED OpenMP_LINKER_FLAGS)
287 set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
289 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
290 set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
296 "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.")
297 set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE)
305 include(gmxGetCompilerInfo)
306 get_compiler_version()
308 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
309 # Detect here whether applying a workaround is needed and will apply it later
310 # on the affected files.
311 include(gmxGCC44O3BugWorkaround)
312 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
314 # clang 3.0 is buggy for some unknown reason detected during adding
315 # the SSE2 group kernels for GROMACS 4.6. If we ever work out what
316 # that is, we should replace these tests with a compiler feature test,
317 # update GROMACS Redmine task #1039 and perhaps report a clang bug.
319 # In the meantime, until we require CMake 2.8.10 we cannot rely on it to detect
320 # the compiler version for us. So we need a manual check for clang 3.0.
321 include(gmxDetectClang30)
322 gmx_detect_clang_3_0(COMPILER_IS_CLANG_3_0)
323 if(COMPILER_IS_CLANG_3_0)
324 message(FATAL_ERROR "Your compiler is clang version 3.0, which is known to be buggy for GROMACS. Use a different compiler.")
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.")
331 ########################################################################
332 # Set up binary and library suffixing
333 ########################################################################
334 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
335 set(GMX_LIBS_SUFFIX ""
336 CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
337 if (GMX_DEFAULT_SUFFIX)
338 set(GMX_BINARY_SUFFIX "")
339 set(GMX_LIBS_SUFFIX "")
341 set(GMX_BINARY_SUFFIX "_mpi")
342 set(GMX_LIBS_SUFFIX "_mpi")
345 set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
346 set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
349 set (GMX_BINARY_SUFFIX "-openmm")
350 set (GMX_LIBS_SUFFIX "_openmm")
352 mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
353 if (NOT SUFFIX_QUIETLY)
354 message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
355 message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
356 endif (NOT SUFFIX_QUIETLY)
357 else(GMX_DEFAULT_SUFFIX)
358 mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
359 if (NOT SUFFIX_QUIETLY)
360 message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
361 message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
362 endif (NOT SUFFIX_QUIETLY)
363 endif(GMX_DEFAULT_SUFFIX)
364 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
368 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
370 if(GMX_SOFTWARE_INVSQRT)
371 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
372 endif(GMX_SOFTWARE_INVSQRT)
374 ########################################################################
375 #Process MPI settings
376 ########################################################################
377 include(gmxManageMPI)
379 #######################################################################
380 # Check for options incompatible with OpenMM build #
381 #######################################################################
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)
391 message(FATAL_ERROR "The OpenMM build is not compatible with 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)
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)
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)
414 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
417 message(FATAL_ERROR "The OpenMM-build does not support double precision calculations!")
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)
423 mark_as_advanced(CLEAR GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
424 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
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)
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)
476 include(CheckLibraryExists)
477 check_library_exists(m sqrt "" HAVE_LIBM)
478 check_library_exists(m cbrt "" HAVE_CBRT)
481 include(CheckTypeSize)
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)
490 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
492 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
493 set(GMX_64_BIT FALSE)
494 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
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)
504 check_type_size(gid_t gid_t)
511 check_type_size(size_t size_t)
518 check_type_size(off_t off_t)
525 include(TestBigEndian)
526 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
531 ########################################################################
532 # Find external packages #
533 ########################################################################
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)
549 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
551 option(GMX_GSL "Add support for gsl" OFF)
556 include_directories(${GSL_INCLUDE_DIR})
562 option(GMX_X11 "Use X window system" OFF)
565 # X11 includes/libraries are only set in the ngmx subdirectory!
572 set(THREAD_MPI_LIB thread_mpi)
574 tmpi_get_source_list(THREAD_MPI_SRC)
575 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
578 tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
579 endif(GMX_THREAD_MPI)
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)
592 # now that we have detected the dependencies, do the second configure pass
597 find_library(ACCELERATE_FRAMEWORK Accelerate)
598 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
605 if(WIN32 AND NOT CYGWIN)
606 set(GMX_NATIVE_WINDOWS 1)
609 # only bother with finding git and using version.h if the source is a git repo
610 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
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.
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)
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)
632 set(USE_VERSION_H OFF)
635 ########################################################################
636 # Generate development version info for cache
637 ########################################################################
638 # set(GEN_VERSION_INFO_INTERNAL "ON")
639 # include(gmxGenerateVersionString)
641 ########################################################################
642 # Our own GROMACS tests
643 ########################################################################
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)
650 include(gmxTestInlineASM)
651 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
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)
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)
665 include(gmxTestLargeFiles)
666 gmx_test_large_files(GMX_LARGEFILES)
668 include(gmxTestSignal)
669 gmx_test_sigusr1(HAVE_SIGUSR1)
671 include(gmxTestInline)
672 gmx_test_inline(INLINE_KEYWORD)
674 include(gmxTestRestrict)
675 gmx_test_restrict(RESTRICT_KEYWORD)
677 include(gmxTestPipes)
678 gmx_test_pipes(HAVE_PIPES)
680 include(gmxTestIsfinite)
681 gmx_test_isfinite(HAVE_ISFINITE)
682 gmx_test__isfinite(HAVE__ISFINITE)
683 gmx_test__finite(HAVE__FINITE)
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)
692 # Process nonbonded accelerated kernels settings
693 string(TOUPPER ${GMX_CPU_ACCELERATION} ${GMX_CPU_ACCELERATION})
694 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
696 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
698 GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" GROMACS_C_FLAGS)
699 if(NOT GNU_SSE2_CFLAG AND GMX_NATIVE_WINDOWS)
700 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
701 endif(NOT GNU_SSE2_CFLAG AND GMX_NATIVE_WINDOWS)
703 if (CMAKE_CXX_COMPILER_LOADED)
704 GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
705 if(NOT GNU_SSE2_CXXFLAG AND GMX_NATIVE_WINDOWS)
706 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
707 endif(NOT GNU_SSE2_CXXFLAG AND GMX_NATIVE_WINDOWS)
710 # We dont warn for lacking SSE2 flag support, since that is probably standard today.
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})
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)
719 set(GMX_CPU_ACCELERATION_X86_SSE2 1)
720 # The user should not be able to set this orthogonally to the acceleration
722 if (NOT ACCELERATION_QUIETLY)
723 message(STATUS "Enabling SSE2 Gromacs acceleration, and it will help compiler optimization.")
726 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
728 GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" GROMACS_C_FLAGS)
729 if (NOT GNU_SSE4_CFLAG AND GMX_NATIVE_WINDOWS)
730 GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" GROMACS_C_FLAGS)
731 endif(NOT GNU_SSE4_CFLAG AND GMX_NATIVE_WINDOWS)
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 use SSE2 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 if (GMX_NATIVE_WINDOWS)
737 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
739 endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
741 if (CMAKE_CXX_COMPILER_LOADED)
742 GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
743 if (NOT GNU_SSE4_CXXFLAG AND GMX_NATIVE_WINDOWS)
744 GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
745 endif(NOT GNU_SSE4_CXXFLAG AND GMX_NATIVE_WINDOWS)
746 if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
747 message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or use SSE2 for slightly lower performance.")
748 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
749 # intrinsics when SSE2 support is enabled, so we try that instead.
750 if (GMX_NATIVE_WINDOWS)
751 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
753 endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
756 # This must come after we have added the -msse4.1 flag on some platforms.
757 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
759 if(NOT HAVE_SMMINTRIN_H)
760 message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
761 endif(NOT HAVE_SMMINTRIN_H)
763 set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
764 # The user should not be able to set this orthogonally to the acceleration
765 set(GMX_X86_SSE4_1 1)
767 if (NOT ACCELERATION_QUIETLY)
768 message(STATUS "Enabling SSE4.1 Gromacs acceleration, and it will help compiler optimization.")
771 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
773 # Set the AVX compiler flag for both these choices!
775 GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" GROMACS_C_FLAGS)
776 if (NOT GNU_AVX_CFLAG AND GMX_NATIVE_WINDOWS)
777 GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" GROMACS_C_FLAGS)
778 endif (NOT GNU_AVX_CFLAG AND GMX_NATIVE_WINDOWS)
779 if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
780 message(WARNING "No C AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
781 endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
783 if (CMAKE_CXX_COMPILER_LOADED)
784 GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
785 if (NOT GNU_AVX_CXXFLAG AND GMX_NATIVE_WINDOWS)
786 GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
787 endif (NOT GNU_AVX_CXXFLAG AND GMX_NATIVE_WINDOWS)
788 if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
789 message(WARNING "No C++ AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
790 endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
793 # Set the FMA4 flags (MSVC doesn't require any)
794 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
795 GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
796 if (NOT GNU_FMA_CFLAG)
797 message(WARNING "No C FMA4 flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
798 endif(NOT GNU_FMA_CFLAG)
799 GMX_TEST_CFLAG(GNU_XOP_CFLAG "-mxop" GROMACS_C_FLAGS)
800 # No big deal if we do not have xop, so no point yelling warnings about it.
801 if (CMAKE_CXX_COMPILER_LOADED)
802 GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
803 if (NOT GNU_FMA_CXXFLAG)
804 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
805 endif (NOT GNU_FMA_CXXFLAG)
806 GMX_TEST_CXXFLAG(GNU_XOP_CXXFLAG "-mxop" GROMACS_CXX_FLAGS)
807 # No big deal if we do not have xop, so no point yelling warnings about it.
811 # Only test the header after we have tried to add the flag for AVX support
812 check_include_file(immintrin.h HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
814 if(NOT HAVE_IMMINTRIN_H)
815 message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
816 endif(NOT HAVE_IMMINTRIN_H)
818 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
819 try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
820 "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
821 COMPILE_DEFINITIONS "${GROMACS_C_FLAGS}")
823 message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
827 # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
828 check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
829 check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
831 # The user should not be able to set this orthogonally to the acceleration
832 set(GMX_X86_SSE4_1 1)
835 # But just enable one of the choices internally...
836 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
837 set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
838 set(GMX_X86_AVX_128_FMA 1)
839 if (NOT ACCELERATION_QUIETLY)
840 message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add), and it will help compiler optimization.")
843 # If we are not doing AVX_128, it must be AVX_256...
844 set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
845 set(GMX_X86_AVX_256 1)
846 if (NOT ACCELERATION_QUIETLY)
847 message(STATUS "Enabling 256-bit AVX Gromacs acceleration, and it will help compiler optimization.")
851 elseif(${GMX_CPU_ACCELERATION} STREQUAL "BLUEGENE")
852 # GMX_CPU_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
853 if (NOT ACCELERATION_QUIETLY)
854 message(STATUS "Configuring for BlueGene")
857 if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
858 set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
859 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
860 endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
861 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
862 set(GMX_X11 OFF CACHE BOOL "X11 not compatible with BlueGene, disabled!" FORCE)
863 set(GMX_THREAD_MPI OFF CACHE BOOL "Thread-MPI not compatible with BlueGene, disabled!" FORCE)
864 set(GMX_MPI ON CACHE BOOL "Use MPI on BlueGene" FORCE)
865 # Access to /etc/passwd is not available on the back end of BlueGene,
866 # despite being detected by CMake. This can cause linker warnings
867 # about harmless things in src/gmxlib/string2.h.
869 # The automatic testing for endianness does not work for the BlueGene cross-compiler
870 set(GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP byte order (by default)" FORCE)
871 set(GMX_IEEE754_BIG_ENDIAN_WORD_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP word order (by default)" FORCE)
872 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
873 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_CPU_ACCELERATION}. Pick one of None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene")
874 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
875 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
877 # Process QM/MM Settings
878 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
879 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
880 set(GMX_QMMM_GAUSSIAN 1)
881 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
882 set(GMX_QMMM_MOPAC 1)
883 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
884 set(GMX_QMMM_GAMESS 1)
885 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
887 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
889 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
890 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
891 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
893 # Process FFT library settings - if not OpenMM build
894 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
897 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
904 if(GMX_BUILD_OWN_FFTW)
905 add_subdirectory(src/contrib/fftw)
907 find_package(FFTW COMPONENTS ${FFTW})
910 string(TOUPPER "${FFTW}" FFTW)
911 set(PKG_FFT "${${FFTW}_PKG}")
912 include_directories(${${FFTW}_INCLUDE_DIRS})
913 set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
914 if(NOT ${FFTW}_FOUND)
915 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.")
920 if (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD)
921 message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
924 if(NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND ${FFTW}_HAVE_AVX)
925 # If we're not doing CPU acceleration, we don't care about FFTW performance on x86 either
926 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.")
929 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
930 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
931 find_package(MKL REQUIRED)
932 include_directories(${MKL_INCLUDE_DIR})
933 set(FFT_LIBRARIES ${MKL_LIBRARIES})
934 set(PKG_FFT_LIBS ${MKL_LIBRARIES})
939 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
940 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
941 # set(GMX_FFT_ACML 1)
942 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
943 MESSAGE(STATUS "Using internal FFT library - fftpack")
944 set(GMX_FFT_FFTPACK 1)
945 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
946 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
947 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
949 # enable threaded fftw3 if we've found it
950 if(FFTW3_THREADS OR FFTW3F_THREADS)
951 add_definitions(-DFFT5D_FFTW_THREADS)
954 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
955 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
956 # MKL has BLAS/LAPACK routines
957 if(NOT HAVE_MKL AND NOT ACCELERATE_FRAMEWORK)
958 if(GMX_EXTERNAL_BLAS)
960 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
962 set(BLAS_FIND_QUIETLY ON)
965 list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
967 MESSAGE(STATUS "Using internal BLAS library")
968 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in" FORCE)
971 endif(GMX_EXTERNAL_BLAS)
972 if(GMX_EXTERNAL_LAPACK)
974 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
975 else(GMX_LAPACK_USER)
976 set(LAPACK_FIND_QUIETLY ON)
979 list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
981 MESSAGE(STATUS "Using internal LAPACK library")
982 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in" FORCE)
984 endif(GMX_LAPACK_USER)
985 endif(GMX_EXTERNAL_LAPACK)
987 mark_as_advanced(GMX_EXTERNAL_LAPACK)
988 mark_as_advanced(GMX_EXTERNAL_BLAS)
990 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
993 if(CYGWIN OR NOT WIN32)
994 # Native Windows does not have, nor need dlopen
995 # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
996 include(gmxTestdlopen)
997 gmx_test_dlopen(HAVE_DLOPEN)
1000 # so, should we use plug-ins?
1001 if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1004 "Found the ability to use plug-ins when building shared libaries, "
1005 "so will compile to use plug-ins (e.g. to read VMD-supported file "
1008 if(NOT GMX_VMD_PLUGIN_PATH)
1011 set(GMX_USE_PLUGINS ON)
1012 list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1013 set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1017 endif(GMX_LOAD_PLUGINS)
1018 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1020 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1021 if(NOT CMAKE_CROSSCOMPILING)
1022 option(GMX_BUILD_MANPAGES "Build man pages" ON)
1024 message(STATUS "Building the man pages is not available when "
1025 "cross-compiling the developer version from git")
1028 #make sure source package contains all man pages
1029 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1030 message(FATAL_ERROR "Man pages are missing from source package.")
1033 mark_as_advanced(GMX_BUILD_MANPAGES)
1035 # Math and thread libraries must often come after all others when linking...
1037 list(APPEND GMX_EXTRA_LIBRARIES m)
1041 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
1042 "Path to swindirect.h")
1043 include_directories(${COREWRAP_INCLUDE_DIR})
1046 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1047 # these are set after everything else
1048 if (NOT DEFINED GROMACS_C_FLAGS_SET)
1049 set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
1051 set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING
1052 "Flags used by the compiler during all build types" FORCE)
1053 if (CMAKE_CXX_COMPILER_LOADED)
1054 set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING
1055 "Flags used by the compiler during all build types" FORCE)
1057 set(CMAKE_EXE_LINKER_FLAGS
1058 "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}"
1059 CACHE STRING "Linker flags for creating executables" FORCE)
1060 set(CMAKE_SHARED_LINKER_FLAGS
1061 "${GROMACS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}"
1062 CACHE STRING "Linker flags for creating shared libraries" FORCE)
1063 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
1066 #Unset all OpenMP flags in case OpenMP was disabled either by the user
1067 #or because it was only partially detected (e.g. only for C but not C++ compiler)
1068 unset(OpenMP_C_FLAGS CACHE)
1069 unset(OpenMP_CXX_FLAGS CACHE)
1070 unset(OpenMP_LINKER_FLAGS CACHE)
1071 unset(OpenMP_SHARED_LINKER_FLAGS)
1074 ######################################
1075 # Output compiler and CFLAGS used
1076 ######################################
1077 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
1078 if (CMAKE_CXX_COMPILER_LOADED)
1079 get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
1082 ########################################################################
1083 # Specify install locations and which subdirectories to process #
1084 ########################################################################
1085 if (GMX_USE_RELATIVE_INSTALL_PATH)
1086 set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1087 mark_as_advanced(GMX_INSTALL_PREFIX)
1089 set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1092 if ( NOT DEFINED GMXLIB )
1095 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1096 set(BIN_INSTALL_DIR ${GMX_INSTALL_PREFIX}bin)
1097 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1098 set(MAN_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/man)
1099 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1101 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
1103 ##################################################################
1104 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
1105 ##################################################################
1106 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1107 set(CMAKE_SKIP_BUILD_RPATH FALSE)
1108 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1109 set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1110 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1113 #COPYING file: Only necessary for binary distributions.
1114 #Simpler to always install.
1115 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1117 add_subdirectory(share)
1118 add_subdirectory(include)
1119 add_subdirectory(src)
1120 add_subdirectory(scripts)
1122 # Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
1123 # Don't bother the user after the first configure pass.
1124 if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT GMX_GPU_DETECTION_DONE)
1125 message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
1126 unset(CUDA_NOTFOUND_AUTO)
1127 unset(CUDA_NOTFOUND_MESSAGE)
1129 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
1131 #######################
1133 #######################
1135 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1136 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1138 ###########################
1139 ADD_CUSTOM_TARGET(uninstall
1140 "${CMAKE_COMMAND}" -P
1141 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1142 ###########################
1144 ########################################################################
1146 ########################################################################
1149 mark_as_advanced(BUILD_TESTING)
1152 add_subdirectory(tests)