1 cmake_minimum_required(VERSION 2.8)
2 # Keep CMake suitably quiet on Cygwin
3 set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
5 # Allows CPack to act differently for normal tools and mdrun (e.g. because of MPI)
6 set(CPACK_COMPONENT_GROUP_TOOLS_DESCRIPTION "All GROMACS executable tools")
7 set(CPACK_COMPONENT_GROUP_MDRUN_DESCRIPTION "GROMACS executable for running simulations")
9 # override bugs on OS X where Cmake picks gcc (GNU) for C instead of system default cc (Clang).
11 set(CMAKE_C_COMPILER_INIT "cc")
16 mark_as_advanced(DART_ROOT)
18 # PROJECT_VERSION should have the following structure:
19 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
21 # The "-dev" suffix is important to keep because it makes possible to distinguish
22 # between a build from official release and a build from git release branch on a
23 # machine with no git.
25 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
26 set(PROJECT_VERSION "4.6-beta1")
27 set(CUSTOM_VERSION_STRING ""
28 CACHE STRING "Custom version string (if empty, use hard-coded default)")
29 mark_as_advanced(CUSTOM_VERSION_STRING)
30 if (CUSTOM_VERSION_STRING)
31 set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
32 endif (CUSTOM_VERSION_STRING)
34 # It is a bit irritating, but this has to be set separately for now!
35 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
36 SET(CPACK_PACKAGE_VERSION_MINOR "6")
37 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
39 # The numerical gromacs version. It is 40600 for 4.6.0.
40 # The #define GMX_VERSION in gmx_header_config_h is set to this value.
42 "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
43 if(CPACK_PACKAGE_VERSION_PATCH)
45 "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
48 # The API version tracks the numerical Gromacs version (for now).
49 # It is potentially different from the Gromacs version in the future, if
50 # the programs/libraries diverge from the presumably more stable API.
51 # The #define GMX_API_VERSION in version.h is set to this value to
52 # provide backward compatibility of software written against the Gromacs API.
53 set(API_VERSION ${NUM_VERSION})
55 # Cmake modules/macros are in a subdirectory to keep this file cleaner
56 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
58 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
59 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
62 include(gmxBuildTypeReference)
64 if(NOT CMAKE_BUILD_TYPE)
65 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
66 endif(NOT CMAKE_BUILD_TYPE)
70 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
71 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
73 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
74 set(CPACK_PACKAGE_VENDOR "gromacs.org")
75 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
76 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
77 set(CPACK_SET_DESTDIR "ON")
79 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
80 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
81 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
82 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
83 set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$")
84 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
85 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
86 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
88 #must come after all cpack settings!
91 ########################################################################
92 # Check and warn if cache generated on a different host is being reused
93 ########################################################################
95 execute_process(COMMAND hostname
96 OUTPUT_VARIABLE TMP_HOSTNAME
97 OUTPUT_STRIP_TRAILING_WHITESPACE)
98 if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
100 The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
101 is being reused! This could lead to inconsitencies; therefore, it is
102 recommended to regenerate the cache!")
104 set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
105 "Hostname of the machine where the cache was generated.")
108 ########################################################################
109 # User input options - enable C++ - before any CXX flags are changed #
110 ########################################################################
112 # decide on GPU settings based on user-settings and GPU/CUDA detection
113 include(gmxManageGPU)
115 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
116 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
117 mark_as_advanced(GMX_FORCE_CXX)
119 if(GMX_GPU OR GMX_OPENMM OR GMX_FORCE_CXX)
122 set(CMAKE_PREFIX_PATH "" CACHE STRING "Extra locations to search for external libraries and tools (give directory without lib, bin, or include)")
124 ########################################################################
125 # Fix stupid flags on Windows
126 ########################################################################
127 SET(SHARED_LIBS_DEFAULT ON)
128 IF( WIN32 AND NOT CYGWIN)
129 if (NOT BUILD_SHARED_LIBS)
130 option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
131 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
132 SET(SHARED_LIBS_DEFAULT OFF)
134 add_definitions(-DUSE_VISIBILITY -DTMPI_USE_VISIBILITY)
137 IF (GMX_PREFER_STATIC_LIBS)
138 #Only setting Debug and Release flags. Others configurations current not used.
139 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
140 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
141 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
142 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
143 if(CMAKE_CXX_COMPILER_LOADED)
144 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
145 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
146 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
147 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
151 #Workaround for cmake bug 13174. Replace deprecated options.
152 IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
153 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
154 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
156 IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
157 STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
158 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
159 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
161 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
162 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
167 ########################################################################
168 # User input options #
169 ########################################################################
170 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
171 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
172 option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
173 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
174 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
175 option(GMX_POWERPC_INVSQRT "Use PowerPC hardware 1/sqrt" OFF)
176 mark_as_advanced(GMX_POWERPC_INVSQRT)
177 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
178 mark_as_advanced(GMX_FAHCORE)
180 include(gmxDetectAcceleration)
181 if(NOT DEFINED GMX_CPU_ACCELERATION)
182 if(CMAKE_CROSSCOMPILING)
183 set(GMX_SUGGESTED_CPU_ACCELERATION "None")
184 else(CMAKE_CROSSCOMPILING)
185 gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
186 endif(CMAKE_CROSSCOMPILING)
187 endif(NOT DEFINED GMX_CPU_ACCELERATION)
189 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
190 CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene, Power6, Fortran")
192 set(GMX_FFT_LIBRARY "fftw3"
193 CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
194 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)
195 mark_as_advanced(GMX_BUILD_OWN_FFTW)
196 option(GMX_DISABLE_FFTW_MEASURE
197 "Do not optimize FFTW setups (not needed with SSE)" OFF)
198 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
199 set(GMX_QMMM_PROGRAM "none"
200 CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
201 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
202 mark_as_advanced(GMX_BROKEN_CALLOC)
203 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
204 mark_as_advanced(GMX_MPI_IN_PLACE)
205 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
206 mark_as_advanced(GMX_LOAD_PLUGINS)
208 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
210 option(USE_VERSION_H "Generate development version string/information" ON)
211 mark_as_advanced(USE_VERSION_H)
213 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)
216 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)
217 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
220 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
221 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
223 ######################################################################
225 # These need to be done early (before further tests).
226 #####################################################################
228 # The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
229 # are used with permission from CMake v2.8.9 so that GROMACS can detect
230 # invalid options with the Intel Compilers.
231 # These files should be removed from the source tree when a CMake version that
232 # includes the features in question becomes required for building GROMACS.
233 include(CheckCCompilerFlag)
234 if(CMAKE_CXX_COMPILER_LOADED)
235 include(CheckCXXCompilerFlag)
238 # OpenMP check must come before other CFLAGS!
242 # CMake on Windows doesn't support linker flags passed to target_link_libraries
243 # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed.
244 if(NOT (WIN32 AND NOT CYGWIN))
245 if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
246 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
247 set(OpenMP_SHARED_LINKER_FLAGS "")
249 # Only set a linker flag if the user didn't set them manually
250 if(NOT DEFINED OpenMP_LINKER_FLAGS)
251 set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
253 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
254 set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
260 "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.")
261 set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE)
269 include(gmxGetCompilerInfo)
270 get_compiler_version()
272 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
273 # Detect here whether applying a workaround is needed and will apply it later
274 # on the affected files.
275 include(gmxGCC44O3BugWorkaround)
276 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
278 # clang 3.0 is buggy for some unknown reason detected during adding
279 # the SSE2 group kernels for GROMACS 4.6. If we ever work out what
280 # that is, we should replace these tests with a compiler feature test,
281 # update GROMACS Redmine task #1039 and perhaps report a clang bug.
283 # In the meantime, until we require CMake 2.8.10 we cannot rely on it to detect
284 # the compiler version for us. So we need a manual check for clang 3.0.
285 include(gmxDetectClang30)
286 gmx_detect_clang_3_0(COMPILER_IS_CLANG_3_0)
287 if(COMPILER_IS_CLANG_3_0)
288 message(FATAL_ERROR "Your compiler is clang version 3.0, which is known to be buggy for GROMACS. Use a different compiler.")
291 ########################################################################
292 # Set up binary and library suffixing
293 ########################################################################
294 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
295 set(GMX_LIBS_SUFFIX ""
296 CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
297 if (GMX_DEFAULT_SUFFIX)
298 set(GMX_BINARY_SUFFIX "")
299 set(GMX_LIBS_SUFFIX "")
301 set(GMX_BINARY_SUFFIX "_mpi")
302 set(GMX_LIBS_SUFFIX "_mpi")
305 set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
306 set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
309 set (GMX_BINARY_SUFFIX "-openmm")
310 set (GMX_LIBS_SUFFIX "_openmm")
312 mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
313 if (NOT SUFFIX_QUIETLY)
314 message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
315 message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
316 endif (NOT SUFFIX_QUIETLY)
317 else(GMX_DEFAULT_SUFFIX)
318 mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
319 if (NOT SUFFIX_QUIETLY)
320 message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
321 message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
322 endif (NOT SUFFIX_QUIETLY)
323 endif(GMX_DEFAULT_SUFFIX)
324 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
328 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
330 if(GMX_SOFTWARE_INVSQRT)
331 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
332 endif(GMX_SOFTWARE_INVSQRT)
333 if(GMX_POWERPC_INVSQRT)
334 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_POWERPC_INVSQRT")
335 endif(GMX_POWERPC_INVSQRT)
337 ########################################################################
338 #Process MPI settings
339 ########################################################################
340 include(gmxManageMPI)
342 #######################################################################
343 # Check for options incompatible with OpenMM build #
344 #######################################################################
346 # we'll use the built-in fft to avoid unnecessary dependencies
347 string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
348 if(NOT ${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
349 message(STATUS "No external FFT libraries needed for the OpenMM build, switching to fftpack!")
350 set(GMX_FFT_LIBRARY "fftpack" CACHE STRING
351 "No external FFT libraries needed for the OpenMM build, switching to fftpack!" FORCE)
354 message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
357 message(STATUS "Thread-MPI not compatible with OpenMM, disabled!")
358 set(GMX_THREAD_MPI OFF CACHE BOOL
359 "Thread-MPI not compatible with OpenMM build, disabled!" FORCE)
360 endif(GMX_THREAD_MPI)
362 message(STATUS "OpenMP multithreading not compatible with OpenMM, disabled")
363 set(GMX_OPENMP OFF CACHE BOOL
364 "OpenMP multithreading not compatible with OpenMM, disabled!" FORCE)
366 if(GMX_SOFTWARE_INVSQRT)
367 set(GMX_SOFTWARE_INVSQRT OFF CACHE STRING
368 "The OpenMM build does not need GROMACS software 1/sqrt!" FORCE)
369 endif(GMX_SOFTWARE_INVSQRT)
370 string(TOUPPER ${GMX_CPU_ACCELERATION} GMX_CPU_ACCELERATION)
371 if(NOT GMX_CPU_ACCELERATION STREQUAL "NONE")
372 message(STATUS "Switching off CPU-based acceleration, the OpenMM build does not support/need any!")
373 set(GMX_CPU_ACCELERATION "None" CACHE STRING
374 "Switching off CPU-based acceleration, the OpenMM build does not support/need any!" FORCE)
377 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
380 message(FATAL_ERROR "The OpenMM-build does not support double precision calculations!")
382 # mark as advanced the unused variables
383 mark_as_advanced(FORCE GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
384 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
386 mark_as_advanced(CLEAR GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
387 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
391 ########################################################################
392 # Basic system tests (standard libraries, headers, functions, types) #
393 ########################################################################
394 include(CheckIncludeFiles)
395 check_include_files(string.h HAVE_STRING_H)
396 check_include_files(math.h HAVE_MATH_H)
397 check_include_files(limits.h HAVE_LIMITS_H)
398 check_include_files(memory.h HAVE_MEMORY_H)
399 check_include_files(unistd.h HAVE_UNISTD_H)
400 check_include_files(direct.h HAVE_DIRECT_H)
401 check_include_files(pwd.h HAVE_PWD_H)
402 check_include_files(stdint.h HAVE_STDINT_H)
403 check_include_files(stdlib.h HAVE_STDLIB_H)
404 check_include_files(pthread.h HAVE_PTHREAD_H)
405 check_include_files(dirent.h HAVE_DIRENT_H)
406 check_include_files(inttypes.h HAVE_INTTYPES_H)
407 check_include_files(regex.h HAVE_REGEX_H)
408 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
409 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
410 check_include_files(sys/time.h HAVE_SYS_TIME_H)
411 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
412 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
413 check_include_files(io.h HAVE_IO_H)
414 check_include_files(sched.h HAVE_SCHED_H)
416 include(CheckFunctionExists)
417 check_function_exists(strcasecmp HAVE_STRCASECMP)
418 check_function_exists(strdup HAVE_STRDUP)
419 check_function_exists(vprintf HAVE_VPRINTF)
420 check_function_exists(memcmp HAVE_MEMCMP)
421 check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
422 check_function_exists(memalign HAVE_MEMALIGN)
423 check_function_exists(_aligned_malloc HAVE__ALIGNED_MALLOC)
424 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
425 check_function_exists(isnan HAVE_ISNAN)
426 check_function_exists(_isnan HAVE__ISNAN)
427 check_function_exists(fsync HAVE_FSYNC)
428 check_function_exists(_fileno HAVE__FILENO)
429 check_function_exists(fileno HAVE_FILENO)
430 check_function_exists(_commit HAVE__COMMIT)
431 check_function_exists(sigaction HAVE_SIGACTION)
432 check_function_exists(sysconf HAVE_SYSCONF)
433 check_function_exists(sched_setaffinity HAVE_SCHED_SETAFFINITY)
434 check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
435 check_function_exists(rsqrt HAVE_RSQRT)
436 check_function_exists(rsqrtf HAVE_RSQRTF)
437 check_function_exists(sqrtf HAVE_SQRTF)
439 include(CheckLibraryExists)
440 check_library_exists(m sqrt "" HAVE_LIBM)
441 check_library_exists(m cbrt "" HAVE_CBRT)
444 include(CheckTypeSize)
446 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
447 check_type_size("int" SIZEOF_INT)
448 check_type_size("long int" SIZEOF_LONG_INT)
449 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
450 check_type_size("off_t" SIZEOF_OFF_T)
451 check_type_size("void *" SIZEOF_VOIDP)
453 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
455 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
456 set(GMX_64_BIT FALSE)
457 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
459 # Check for some basic types that we *need*, so set these to int if they are not present
460 check_type_size(uid_t uid_t)
467 check_type_size(gid_t gid_t)
474 check_type_size(size_t size_t)
481 check_type_size(off_t off_t)
488 include(TestBigEndian)
489 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
494 ########################################################################
495 # Find external packages #
496 ########################################################################
498 if(GMX_PREFER_STATIC_LIBS)
499 # On Linux .a is the static library suffix, on Mac OS X .lib can also
500 # be used, so we'll add both to the preference list.
501 SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
502 if(SHARED_LIBS_DEFAULT)
503 if(BUILD_SHARED_LIBS) #Warn the user about the combination. But don't overwrite the request.
504 message(WARNING "Static libraries requested, and shared Gromacs libraries requested.")
505 elseif(NOT DEFINED BUILD_SHARED_LIBS) #Change default to OFF. Don't warn if it's already off.
506 message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
507 set(SHARED_LIBS_DEFAULT OFF)
512 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
514 option(GMX_GSL "Add support for gsl" OFF)
519 include_directories(${GSL_INCLUDE_DIR})
525 option(GMX_X11 "Use X window system" OFF)
528 # X11 includes/libraries are only set in the ngmx subdirectory!
535 set(THREAD_MPI_LIB thread_mpi)
537 tmpi_get_source_list(THREAD_MPI_SRC)
538 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
541 tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
542 endif(GMX_THREAD_MPI)
545 set(CUDA_BUILD_EMULATION OFF)
546 find_package(CUDA 3.1 REQUIRED)
547 add_definitions(-DGMX_OPENMM)
548 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
549 set(CUDA_VERBOSE_BUILD ON)
555 # now that we have detected the dependencies, do the second configure pass
560 find_library(ACCELERATE_FRAMEWORK Accelerate)
561 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
568 if(WIN32 AND NOT CYGWIN)
569 set(GMX_NATIVE_WINDOWS 1)
572 # only bother with finding git and using version.h if the source is a git repo
573 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
575 # We need at least git v1.5.3 be able to parse git's date output. If not
576 # found or the version is too small, we can't generate version information.
579 # Find out the git version
580 if(GIT_FOUND AND NOT GIT_VERSION)
581 execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
582 OUTPUT_VARIABLE _exec_out
583 OUTPUT_STRIP_TRAILING_WHITESPACE)
584 string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
585 set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
586 mark_as_advanced(GIT_VERSION)
589 if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
590 message("No compatible git version found, won't be able to generate proper development version information.")
591 set(USE_VERSION_H OFF)
595 set(USE_VERSION_H OFF)
598 ########################################################################
599 # Generate development version info for cache
600 ########################################################################
601 # set(GEN_VERSION_INFO_INTERNAL "ON")
602 # include(gmxGenerateVersionString)
604 ########################################################################
605 # Our own GROMACS tests
606 ########################################################################
608 add_definitions( -DHAVE_CONFIG_H )
609 include_directories(${CMAKE_BINARY_DIR}/src)
610 include_directories(${CMAKE_BINARY_DIR}/include)
611 include_directories(${CMAKE_SOURCE_DIR}/include)
613 include(gmxTestInlineASM)
614 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
616 include(gmxSetBuildInformation)
617 gmx_set_build_information()
618 if(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
619 # The timestep counter headers do not include config.h
620 add_definitions(-DHAVE_RDTSCP)
621 endif(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
623 include(gmxTestFloatFormat)
624 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
625 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
626 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
628 include(gmxTestLargeFiles)
629 gmx_test_large_files(GMX_LARGEFILES)
631 include(gmxTestSignal)
632 gmx_test_sigusr1(HAVE_SIGUSR1)
634 include(gmxTestInline)
635 gmx_test_inline(INLINE_KEYWORD)
637 include(gmxTestRestrict)
638 gmx_test_restrict(RESTRICT_KEYWORD)
640 include(gmxTestPipes)
641 gmx_test_pipes(HAVE_PIPES)
643 include(gmxTestIsfinite)
644 gmx_test_isfinite(HAVE_ISFINITE)
645 gmx_test__isfinite(HAVE__ISFINITE)
646 gmx_test__finite(HAVE__FINITE)
649 gmx_test_xdr(GMX_SYSTEM_XDR)
650 if(NOT GMX_SYSTEM_XDR)
651 set(GMX_INTERNAL_XDR 1)
652 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
653 endif(NOT GMX_SYSTEM_XDR)
655 # Process nonbonded accelerated kernels settings
656 string(TOUPPER ${GMX_CPU_ACCELERATION} ${GMX_CPU_ACCELERATION})
657 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
659 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
661 GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" GROMACS_C_FLAGS)
662 if(NOT GNU_SSE2_CFLAG)
663 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
664 endif(NOT GNU_SSE2_CFLAG)
666 if (CMAKE_CXX_COMPILER_LOADED)
667 GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
668 if(NOT GNU_SSE2_CXXFLAG)
669 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
670 endif(NOT GNU_SSE2_CXXFLAG)
673 # We dont warn for lacking SSE2 flag support, since that is probably standard today.
675 # Only test the include after we have tried to add the correct flag for SSE2 support
676 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${GROMACS_C_FLAGS})
678 if(NOT HAVE_EMMINTRIN_H)
679 message(FATAL_ERROR "Cannot find emmintrin.h, which is required for SSE2 intrinsics support.")
680 endif(NOT HAVE_EMMINTRIN_H)
682 set(GMX_CPU_ACCELERATION_X86_SSE2 1)
683 # The user should not be able to set this orthogonally to the acceleration
685 if (NOT ACCELERATION_QUIETLY)
686 message(STATUS "Enabling SSE2 Gromacs acceleration, and it will help compiler optimization.")
689 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
691 GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" GROMACS_C_FLAGS)
692 if (NOT GNU_SSE4_CFLAG)
693 GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" GROMACS_C_FLAGS)
694 endif(NOT GNU_SSE4_CFLAG)
695 if (NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
696 message(WARNING "No C SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
697 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
698 # intrinsics when SSE2 support is enabled, so we try that instead.
699 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
700 endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
702 if (CMAKE_CXX_COMPILER_LOADED)
703 GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
704 if (NOT GNU_SSE4_CXXFLAG)
705 GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
706 endif(NOT GNU_SSE4_CXXFLAG)
707 if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
708 message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
709 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
710 # intrinsics when SSE2 support is enabled, so we try that instead.
711 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
712 endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
715 # This must come after we have added the -msse4.1 flag on some platforms.
716 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
718 if(NOT HAVE_SMMINTRIN_H)
719 message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
720 endif(NOT HAVE_SMMINTRIN_H)
722 set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
723 # The user should not be able to set this orthogonally to the acceleration
724 set(GMX_X86_SSE4_1 1)
726 if (NOT ACCELERATION_QUIETLY)
727 message(STATUS "Enabling SSE4.1 Gromacs acceleration, and it will help compiler optimization.")
730 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
732 # Set the AVX compiler flag for both these choices!
734 GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" GROMACS_C_FLAGS)
735 if (NOT GNU_AVX_CFLAG)
736 GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" GROMACS_C_FLAGS)
737 endif (NOT GNU_AVX_CFLAG)
738 if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
739 message(WARNING "No C AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
740 endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
742 if (CMAKE_CXX_COMPILER_LOADED)
743 GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
744 if (NOT GNU_AVX_CXXFLAG)
745 GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
746 endif (NOT GNU_AVX_CXXFLAG)
747 if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
748 message(WARNING "No C++ AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
749 endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
752 # Set the FMA4 flags (MSVC doesn't require any)
753 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
754 GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
755 if (NOT GNU_FMA_CFLAG)
756 message(WARNING "No C FMA4 flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
757 endif(NOT GNU_FMA_CFLAG)
758 GMX_TEST_CFLAG(GNU_XOP_CFLAG "-mxop" GROMACS_C_FLAGS)
759 # No big deal if we do not have xop, so no point yelling warnings about it.
760 if (CMAKE_CXX_COMPILER_LOADED)
761 GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
762 if (NOT GNU_FMA_CXXFLAG)
763 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
764 endif (NOT GNU_FMA_CXXFLAG)
765 GMX_TEST_CXXFLAG(GNU_XOP_CXXFLAG "-mxop" GROMACS_CXX_FLAGS)
766 # No big deal if we do not have xop, so no point yelling warnings about it.
770 # Only test the header after we have tried to add the flag for AVX support
771 check_include_file(immintrin.h HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
773 if(NOT HAVE_IMMINTRIN_H)
774 message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
775 endif(NOT HAVE_IMMINTRIN_H)
777 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
778 try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
779 "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
780 COMPILE_DEFINITIONS "${GROMACS_C_FLAGS}")
782 message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
786 # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
787 check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
788 check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
790 # The user should not be able to set this orthogonally to the acceleration
791 set(GMX_X86_SSE4_1 1)
794 # But just enable one of the choices internally...
795 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
796 set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
797 set(GMX_X86_AVX_128_FMA 1)
798 if (NOT ACCELERATION_QUIETLY)
799 message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add), and it will help compiler optimization.")
802 # If we are not doing AVX_128, it must be AVX_256...
803 set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
804 set(GMX_X86_AVX_256 1)
805 if (NOT ACCELERATION_QUIETLY)
806 message(STATUS "Enabling 256-bit AVX Gromacs acceleration, and it will help compiler optimization.")
810 elseif(${GMX_CPU_ACCELERATION} STREQUAL "FORTRAN")
812 # Fortran is temporarily disabled while we push in nbNxN kernels.
813 # We need to fake it a bit here to avoid jenkins build errors!
814 # add_definitions(-DGMX_FORTRAN)
816 elseif(${GMX_CPU_ACCELERATION} STREQUAL "BLUEGENE")
817 # GMX_CPU_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
818 if (NOT ACCELERATION_QUIETLY)
819 message(STATUS "Configuring for BlueGene")
822 if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
823 set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
824 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
825 endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
826 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
827 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on BlueGene" FORCE)
828 set(GMX_X11 OFF CACHE BOOL "X11 not compatible with BlueGene, disabled!" FORCE)
829 set(GMX_THREAD_MPI OFF CACHE BOOL "Thread-MPI not compatible with BlueGene, disabled!" FORCE)
830 set(GMX_MPI ON CACHE BOOL "Use MPI on BlueGene" FORCE)
831 # Access to /etc/passwd is not available on the back end of BlueGene,
832 # despite being detected by CMake. This can cause linker warnings
833 # about harmless things in src/gmxlib/string2.h.
835 # The automatic testing for endianness does not work for the BlueGene cross-compiler
836 set(GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP byte order (by default)" FORCE)
837 set(GMX_IEEE754_BIG_ENDIAN_WORD_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP word order (by default)" FORCE)
838 elseif(${GMX_CPU_ACCELERATION} STREQUAL "POWER6")
840 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on Power6" FORCE)
841 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on Power6" FORCE)
842 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
843 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_CPU_ACCELERATION}. Pick one of None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, Fortran, BlueGene, Power6")
844 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
845 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
847 if(GMX_FORTRAN OR GMX_POWER6)
849 message(FATAL_ERROR "FORTRAN/POWER6 is incompatible with thread-MPI and only provides a speed-up on certain IBM compilers. Disable FORTRAN (or threads if you really want to use FORTRAN kernels).")
850 endif(GMX_THREAD_MPI)
851 enable_language(Fortran)
852 include(FortranCInterface)
853 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
854 if(extra_under_score)
856 endif(extra_under_score)
858 set(prefix "${prefix} ##")
861 set(suffix "## ${suffix}")
863 set(extrasuffix "${suffix}${extrasuffix}")
867 # Don't know if this is needed, but it can't hurt
868 set(extrasuffix "## ${extrasuffix}")
873 set(F77_FUNCDEF "${prefix} NAME ${suffix}")
874 set(F77_FUNCDEF_ "${prefix} NAME ${extrasuffix}")
876 set(F77_FUNCDEF "${prefix} name ${suffix}")
877 set(F77_FUNCDEF_ "${prefix} name ${extrasuffix}")
879 else(GMX_FORTRAN OR GMX_POWER6)
880 set(F77_FUNCDEF "name ## _")
881 set(F77_FUNCDEF_ "name ## _")
882 endif(GMX_FORTRAN OR GMX_POWER6)
884 # Process QM/MM Settings
885 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
886 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
887 set(GMX_QMMM_GAUSSIAN 1)
888 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
889 set(GMX_QMMM_MOPAC 1)
890 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
891 set(GMX_QMMM_GAMESS 1)
892 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
894 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
896 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
897 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
898 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
900 # Process FFT library settings - if not OpenMM build
901 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
904 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
911 if(GMX_BUILD_OWN_FFTW)
912 add_subdirectory(src/contrib/fftw)
914 find_package(FFTW COMPONENTS ${FFTW})
917 string(TOUPPER "${FFTW}" FFTW)
918 set(PKG_FFT "${${FFTW}_PKG}")
919 include_directories(${${FFTW}_INCLUDE_DIRS})
920 set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
921 if(NOT ${FFTW}_FOUND)
922 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.")
927 if (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD)
928 message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
931 if(NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND ${FFTW}_HAVE_AVX)
932 # If we're not doing CPU acceleration, we don't care about FFTW performance on x86 either
933 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.")
936 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
937 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
938 find_package(MKL REQUIRED)
939 include_directories(${MKL_INCLUDE_DIR})
940 set(FFT_LIBRARIES ${MKL_LIBRARIES})
941 set(PKG_FFT_LIBS ${MKL_LIBRARIES})
946 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
947 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
948 # set(GMX_FFT_ACML 1)
949 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
950 MESSAGE(STATUS "Using internal FFT library - fftpack")
951 set(GMX_FFT_FFTPACK 1)
952 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
953 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
954 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
956 # enable threaded fftw3 if we've found it
957 if(FFTW3_THREADS OR FFTW3F_THREADS)
958 add_definitions(-DFFT5D_FFTW_THREADS)
961 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
962 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
963 # MKL has BLAS/LAPACK routines
964 if(NOT HAVE_MKL AND NOT ACCELERATE_FRAMEWORK)
965 if(GMX_EXTERNAL_BLAS)
967 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
969 set(BLAS_FIND_QUIETLY ON)
972 list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
974 MESSAGE(STATUS "Using internal BLAS library")
975 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in" FORCE)
978 endif(GMX_EXTERNAL_BLAS)
979 if(GMX_EXTERNAL_LAPACK)
981 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
982 else(GMX_LAPACK_USER)
983 set(LAPACK_FIND_QUIETLY ON)
986 list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
988 MESSAGE(STATUS "Using internal LAPACK library")
989 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in" FORCE)
991 endif(GMX_LAPACK_USER)
992 endif(GMX_EXTERNAL_LAPACK)
994 mark_as_advanced(GMX_EXTERNAL_LAPACK)
995 mark_as_advanced(GMX_EXTERNAL_BLAS)
997 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
1000 if(CYGWIN OR NOT WIN32)
1001 # Native Windows does not have, nor need dlopen
1002 # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
1003 include(gmxTestdlopen)
1004 gmx_test_dlopen(HAVE_DLOPEN)
1007 # so, should we use plug-ins?
1008 if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1011 "Found the ability to use plug-ins when building shared libaries, "
1012 "so will compile to use plug-ins (e.g. to read VMD-supported file "
1015 if(NOT GMX_VMD_PLUGIN_PATH)
1018 set(GMX_USE_PLUGINS ON)
1019 list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1020 set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1024 endif(GMX_LOAD_PLUGINS)
1025 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1027 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1028 if(NOT CMAKE_CROSSCOMPILING)
1029 option(GMX_BUILD_MANPAGES "Build man pages" ON)
1031 message(STATUS "Building the man pages is not available when "
1032 "cross-compiling the developer version from git")
1035 #make sure source package contains all man pages
1036 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1037 message(FATAL_ERROR "Man pages are missing from source package.")
1040 mark_as_advanced(GMX_BUILD_MANPAGES)
1042 # Math and thread libraries must often come after all others when linking...
1044 list(APPEND GMX_EXTRA_LIBRARIES m)
1048 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
1049 "Path to swindirect.h")
1050 include_directories(${COREWRAP_INCLUDE_DIR})
1053 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1054 # these are set after everything else
1055 if (NOT DEFINED GROMACS_C_FLAGS_SET)
1056 set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
1058 set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING
1059 "Flags used by the compiler during all build types" FORCE)
1060 if (CMAKE_CXX_COMPILER_LOADED)
1061 set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING
1062 "Flags used by the compiler during all build types" FORCE)
1064 set(CMAKE_EXE_LINKER_FLAGS
1065 "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}"
1066 CACHE STRING "Linker flags for creating executables" FORCE)
1067 set(CMAKE_SHARED_LINKER_FLAGS
1068 "${GROMACS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}"
1069 CACHE STRING "Linker flags for creating shared libraries" FORCE)
1070 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
1073 #Unset all OpenMP flags in case OpenMP was disabled either by the user
1074 #or because it was only partially detected (e.g. only for C but not C++ compiler)
1075 unset(OpenMP_C_FLAGS CACHE)
1076 unset(OpenMP_CXX_FLAGS CACHE)
1077 unset(OpenMP_LINKER_FLAGS CACHE)
1078 unset(OpenMP_SHARED_LINKER_FLAGS)
1081 ######################################
1082 # Output compiler and CFLAGS used
1083 ######################################
1084 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
1085 if (CMAKE_CXX_COMPILER_LOADED)
1086 get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
1089 ########################################################################
1090 # Specify install locations and which subdirectories to process #
1091 ########################################################################
1092 if (GMX_USE_RELATIVE_INSTALL_PATH)
1093 set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1094 mark_as_advanced(GMX_INSTALL_PREFIX)
1096 set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1099 if ( NOT DEFINED GMXLIB )
1102 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1103 set(BIN_INSTALL_DIR ${GMX_INSTALL_PREFIX}bin)
1104 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1105 set(MAN_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/man)
1106 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1108 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
1110 ##################################################################
1111 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
1112 ##################################################################
1113 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1114 set(CMAKE_SKIP_BUILD_RPATH FALSE)
1115 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1116 set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1117 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1120 #COPYING file: Only necessary for binary distributions.
1121 #Simpler to always install.
1122 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1124 add_subdirectory(share)
1125 add_subdirectory(include)
1126 add_subdirectory(src)
1127 add_subdirectory(scripts)
1129 # issue GPU acceleration/CUDA-related warning or error if GMX_GPU was set
1130 # Auto and NVIDIA GPUs were detected.
1131 if (CUDA_NOTFOUND_AUTO AND NOT GMX_GPU_DETECTION_DONE)
1132 message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
1133 unset(CUDA_NOTFOUND_AUTO)
1134 unset(CUDA_NOTFOUND_MESSAGE)
1136 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
1138 #######################
1140 #######################
1142 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1143 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1145 ###########################
1146 ADD_CUSTOM_TARGET(uninstall
1147 "${CMAKE_COMMAND}" -P
1148 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1149 ###########################
1151 ########################################################################
1153 ########################################################################
1156 mark_as_advanced(BUILD_TESTING)
1159 add_subdirectory(tests)