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")
43 # override bugs on OS X where Cmake picks gcc (GNU) for C instead of system default cc (Clang).
45 set(CMAKE_C_COMPILER_INIT "cc")
50 mark_as_advanced(DART_ROOT)
52 # PROJECT_VERSION should have the following structure:
53 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
55 # The "-dev" suffix is important to keep because it makes possible to distinguish
56 # between a build from official release and a build from git release branch on a
57 # machine with no git.
59 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
60 set(PROJECT_VERSION "4.6-beta1")
61 set(CUSTOM_VERSION_STRING ""
62 CACHE STRING "Custom version string (if empty, use hard-coded default)")
63 mark_as_advanced(CUSTOM_VERSION_STRING)
64 if (CUSTOM_VERSION_STRING)
65 set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
66 endif (CUSTOM_VERSION_STRING)
68 # It is a bit irritating, but this has to be set separately for now!
69 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
70 SET(CPACK_PACKAGE_VERSION_MINOR "6")
71 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
73 # The numerical gromacs version. It is 40600 for 4.6.0.
74 # The #define GMX_VERSION in gmx_header_config_h is set to this value.
76 "${CPACK_PACKAGE_VERSION_MAJOR}*10000 + ${CPACK_PACKAGE_VERSION_MINOR}*100")
77 if(CPACK_PACKAGE_VERSION_PATCH)
79 "${NUM_VERSION} + ${CPACK_PACKAGE_VERSION_PATCH}")
82 # The API version tracks the numerical Gromacs version (for now).
83 # It is potentially different from the Gromacs version in the future, if
84 # the programs/libraries diverge from the presumably more stable API.
85 # The #define GMX_API_VERSION in version.h is set to this value to
86 # provide backward compatibility of software written against the Gromacs API.
87 set(API_VERSION ${NUM_VERSION})
89 # Cmake modules/macros are in a subdirectory to keep this file cleaner
90 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
92 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
93 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
96 include(gmxBuildTypeReference)
98 if(NOT CMAKE_BUILD_TYPE)
99 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference." FORCE)
100 endif(NOT CMAKE_BUILD_TYPE)
104 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
105 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
107 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
108 set(CPACK_PACKAGE_VENDOR "gromacs.org")
109 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
110 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
111 set(CPACK_SET_DESTDIR "ON")
113 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
114 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
115 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
116 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
117 set(CPACK_SOURCE_IGNORE_FILES "\\\\.isreposource$;\\\\.git/;\\\\.gitignore$")
118 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
119 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
120 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
122 #must come after all cpack settings!
125 ########################################################################
126 # Check and warn if cache generated on a different host is being reused
127 ########################################################################
129 execute_process(COMMAND hostname
130 OUTPUT_VARIABLE TMP_HOSTNAME
131 OUTPUT_STRIP_TRAILING_WHITESPACE)
132 if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
134 The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
135 is being reused! This could lead to inconsitencies; therefore, it is
136 recommended to regenerate the cache!")
138 set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
139 "Hostname of the machine where the cache was generated.")
142 ########################################################################
143 # User input options - enable C++ - before any CXX flags are changed #
144 ########################################################################
146 # decide on GPU settings based on user-settings and GPU/CUDA detection
147 include(gmxManageGPU)
149 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
150 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
151 mark_as_advanced(GMX_FORCE_CXX)
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 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
188 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
190 IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
191 STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
192 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
193 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
195 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
196 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
201 ########################################################################
202 # User input options #
203 ########################################################################
204 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
205 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
206 option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
207 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
208 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
209 option(GMX_POWERPC_INVSQRT "Use PowerPC hardware 1/sqrt" OFF)
210 mark_as_advanced(GMX_POWERPC_INVSQRT)
211 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
212 mark_as_advanced(GMX_FAHCORE)
214 include(gmxDetectAcceleration)
215 if(NOT DEFINED GMX_CPU_ACCELERATION)
216 if(CMAKE_CROSSCOMPILING)
217 set(GMX_SUGGESTED_CPU_ACCELERATION "None")
218 else(CMAKE_CROSSCOMPILING)
219 gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
220 endif(CMAKE_CROSSCOMPILING)
221 endif(NOT DEFINED GMX_CPU_ACCELERATION)
223 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
224 CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene, Power6, Fortran")
226 set(GMX_FFT_LIBRARY "fftw3"
227 CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
228 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)
229 mark_as_advanced(GMX_BUILD_OWN_FFTW)
230 option(GMX_DISABLE_FFTW_MEASURE
231 "Do not optimize FFTW setups (not needed with SSE)" OFF)
232 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
233 set(GMX_QMMM_PROGRAM "none"
234 CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
235 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
236 mark_as_advanced(GMX_BROKEN_CALLOC)
237 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
238 mark_as_advanced(GMX_MPI_IN_PLACE)
239 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
240 mark_as_advanced(GMX_LOAD_PLUGINS)
242 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
244 option(USE_VERSION_H "Generate development version string/information" ON)
245 mark_as_advanced(USE_VERSION_H)
247 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)
250 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)
251 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
254 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
255 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
257 ######################################################################
259 # These need to be done early (before further tests).
260 #####################################################################
262 # The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
263 # are used with permission from CMake v2.8.9 so that GROMACS can detect
264 # invalid options with the Intel Compilers.
265 # These files should be removed from the source tree when a CMake version that
266 # includes the features in question becomes required for building GROMACS.
267 include(CheckCCompilerFlag)
268 if(CMAKE_CXX_COMPILER_LOADED)
269 include(CheckCXXCompilerFlag)
272 # OpenMP check must come before other CFLAGS!
276 # CMake on Windows doesn't support linker flags passed to target_link_libraries
277 # (i.e. it treats /openmp as \openmp library file). Also, no OpenMP linker flags are needed.
278 if(NOT (WIN32 AND NOT CYGWIN))
279 if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
280 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
281 set(OpenMP_SHARED_LINKER_FLAGS "")
283 # Only set a linker flag if the user didn't set them manually
284 if(NOT DEFINED OpenMP_LINKER_FLAGS)
285 set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
287 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
288 set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
294 "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.")
295 set(GMX_OPENMP OFF CACHE STRING "Whether GROMACS will use OpenMP parallelism." FORCE)
303 include(gmxGetCompilerInfo)
304 get_compiler_version()
306 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
307 # Detect here whether applying a workaround is needed and will apply it later
308 # on the affected files.
309 include(gmxGCC44O3BugWorkaround)
310 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
312 # clang 3.0 is buggy for some unknown reason detected during adding
313 # the SSE2 group kernels for GROMACS 4.6. If we ever work out what
314 # that is, we should replace these tests with a compiler feature test,
315 # update GROMACS Redmine task #1039 and perhaps report a clang bug.
317 # In the meantime, until we require CMake 2.8.10 we cannot rely on it to detect
318 # the compiler version for us. So we need a manual check for clang 3.0.
319 include(gmxDetectClang30)
320 gmx_detect_clang_3_0(COMPILER_IS_CLANG_3_0)
321 if(COMPILER_IS_CLANG_3_0)
322 message(FATAL_ERROR "Your compiler is clang version 3.0, which is known to be buggy for GROMACS. Use a different compiler.")
325 ########################################################################
326 # Set up binary and library suffixing
327 ########################################################################
328 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
329 set(GMX_LIBS_SUFFIX ""
330 CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
331 if (GMX_DEFAULT_SUFFIX)
332 set(GMX_BINARY_SUFFIX "")
333 set(GMX_LIBS_SUFFIX "")
335 set(GMX_BINARY_SUFFIX "_mpi")
336 set(GMX_LIBS_SUFFIX "_mpi")
339 set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
340 set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
343 set (GMX_BINARY_SUFFIX "-openmm")
344 set (GMX_LIBS_SUFFIX "_openmm")
346 mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
347 if (NOT SUFFIX_QUIETLY)
348 message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
349 message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
350 endif (NOT SUFFIX_QUIETLY)
351 else(GMX_DEFAULT_SUFFIX)
352 mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
353 if (NOT SUFFIX_QUIETLY)
354 message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
355 message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
356 endif (NOT SUFFIX_QUIETLY)
357 endif(GMX_DEFAULT_SUFFIX)
358 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
362 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
364 if(GMX_SOFTWARE_INVSQRT)
365 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
366 endif(GMX_SOFTWARE_INVSQRT)
367 if(GMX_POWERPC_INVSQRT)
368 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_POWERPC_INVSQRT")
369 endif(GMX_POWERPC_INVSQRT)
371 ########################################################################
372 #Process MPI settings
373 ########################################################################
374 include(gmxManageMPI)
376 #######################################################################
377 # Check for options incompatible with OpenMM build #
378 #######################################################################
380 # we'll use the built-in fft to avoid unnecessary dependencies
381 string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
382 if(NOT ${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
383 message(STATUS "No external FFT libraries needed for the OpenMM build, switching to fftpack!")
384 set(GMX_FFT_LIBRARY "fftpack" CACHE STRING
385 "No external FFT libraries needed for the OpenMM build, switching to fftpack!" FORCE)
388 message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
391 message(STATUS "Thread-MPI not compatible with OpenMM, disabled!")
392 set(GMX_THREAD_MPI OFF CACHE BOOL
393 "Thread-MPI not compatible with OpenMM build, disabled!" FORCE)
394 endif(GMX_THREAD_MPI)
396 message(STATUS "OpenMP multithreading not compatible with OpenMM, disabled")
397 set(GMX_OPENMP OFF CACHE BOOL
398 "OpenMP multithreading not compatible with OpenMM, disabled!" FORCE)
400 if(GMX_SOFTWARE_INVSQRT)
401 set(GMX_SOFTWARE_INVSQRT OFF CACHE STRING
402 "The OpenMM build does not need GROMACS software 1/sqrt!" FORCE)
403 endif(GMX_SOFTWARE_INVSQRT)
404 string(TOUPPER ${GMX_CPU_ACCELERATION} GMX_CPU_ACCELERATION)
405 if(NOT GMX_CPU_ACCELERATION STREQUAL "NONE")
406 message(STATUS "Switching off CPU-based acceleration, the OpenMM build does not support/need any!")
407 set(GMX_CPU_ACCELERATION "None" CACHE STRING
408 "Switching off CPU-based acceleration, the OpenMM build does not support/need any!" FORCE)
411 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
414 message(FATAL_ERROR "The OpenMM-build does not support double precision calculations!")
416 # mark as advanced the unused variables
417 mark_as_advanced(FORCE GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
418 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
420 mark_as_advanced(CLEAR GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
421 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
425 ########################################################################
426 # Basic system tests (standard libraries, headers, functions, types) #
427 ########################################################################
428 include(CheckIncludeFiles)
429 check_include_files(string.h HAVE_STRING_H)
430 check_include_files(math.h HAVE_MATH_H)
431 check_include_files(limits.h HAVE_LIMITS_H)
432 check_include_files(memory.h HAVE_MEMORY_H)
433 check_include_files(unistd.h HAVE_UNISTD_H)
434 check_include_files(direct.h HAVE_DIRECT_H)
435 check_include_files(pwd.h HAVE_PWD_H)
436 check_include_files(stdint.h HAVE_STDINT_H)
437 check_include_files(stdlib.h HAVE_STDLIB_H)
438 check_include_files(pthread.h HAVE_PTHREAD_H)
439 check_include_files(dirent.h HAVE_DIRENT_H)
440 check_include_files(inttypes.h HAVE_INTTYPES_H)
441 check_include_files(regex.h HAVE_REGEX_H)
442 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
443 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
444 check_include_files(sys/time.h HAVE_SYS_TIME_H)
445 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
446 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
447 check_include_files(io.h HAVE_IO_H)
448 check_include_files(sched.h HAVE_SCHED_H)
450 include(CheckFunctionExists)
451 check_function_exists(strcasecmp HAVE_STRCASECMP)
452 check_function_exists(strdup HAVE_STRDUP)
453 check_function_exists(vprintf HAVE_VPRINTF)
454 check_function_exists(memcmp HAVE_MEMCMP)
455 check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
456 check_function_exists(memalign HAVE_MEMALIGN)
457 check_function_exists(_aligned_malloc HAVE__ALIGNED_MALLOC)
458 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
459 check_function_exists(isnan HAVE_ISNAN)
460 check_function_exists(_isnan HAVE__ISNAN)
461 check_function_exists(fsync HAVE_FSYNC)
462 check_function_exists(_fileno HAVE__FILENO)
463 check_function_exists(fileno HAVE_FILENO)
464 check_function_exists(_commit HAVE__COMMIT)
465 check_function_exists(sigaction HAVE_SIGACTION)
466 check_function_exists(sysconf HAVE_SYSCONF)
467 check_function_exists(sched_setaffinity HAVE_SCHED_SETAFFINITY)
468 check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
469 check_function_exists(rsqrt HAVE_RSQRT)
470 check_function_exists(rsqrtf HAVE_RSQRTF)
471 check_function_exists(sqrtf HAVE_SQRTF)
473 include(CheckLibraryExists)
474 check_library_exists(m sqrt "" HAVE_LIBM)
475 check_library_exists(m cbrt "" HAVE_CBRT)
478 include(CheckTypeSize)
480 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
481 check_type_size("int" SIZEOF_INT)
482 check_type_size("long int" SIZEOF_LONG_INT)
483 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
484 check_type_size("off_t" SIZEOF_OFF_T)
485 check_type_size("void *" SIZEOF_VOIDP)
487 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
489 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
490 set(GMX_64_BIT FALSE)
491 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
493 # Check for some basic types that we *need*, so set these to int if they are not present
494 check_type_size(uid_t uid_t)
501 check_type_size(gid_t gid_t)
508 check_type_size(size_t size_t)
515 check_type_size(off_t off_t)
522 include(TestBigEndian)
523 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
528 ########################################################################
529 # Find external packages #
530 ########################################################################
532 if(GMX_PREFER_STATIC_LIBS)
533 # On Linux .a is the static library suffix, on Mac OS X .lib can also
534 # be used, so we'll add both to the preference list.
535 SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
536 if(SHARED_LIBS_DEFAULT)
537 if(BUILD_SHARED_LIBS) #Warn the user about the combination. But don't overwrite the request.
538 message(WARNING "Static libraries requested, and shared Gromacs libraries requested.")
539 elseif(NOT DEFINED BUILD_SHARED_LIBS) #Change default to OFF. Don't warn if it's already off.
540 message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
541 set(SHARED_LIBS_DEFAULT OFF)
546 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
548 option(GMX_GSL "Add support for gsl" OFF)
553 include_directories(${GSL_INCLUDE_DIR})
559 option(GMX_X11 "Use X window system" OFF)
562 # X11 includes/libraries are only set in the ngmx subdirectory!
569 set(THREAD_MPI_LIB thread_mpi)
571 tmpi_get_source_list(THREAD_MPI_SRC)
572 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
575 tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
576 endif(GMX_THREAD_MPI)
579 set(CUDA_BUILD_EMULATION OFF)
580 find_package(CUDA 3.1 REQUIRED)
581 add_definitions(-DGMX_OPENMM)
582 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
583 set(CUDA_VERBOSE_BUILD ON)
589 # now that we have detected the dependencies, do the second configure pass
594 find_library(ACCELERATE_FRAMEWORK Accelerate)
595 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
602 if(WIN32 AND NOT CYGWIN)
603 set(GMX_NATIVE_WINDOWS 1)
606 # only bother with finding git and using version.h if the source is a git repo
607 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
609 # We need at least git v1.5.3 be able to parse git's date output. If not
610 # found or the version is too small, we can't generate version information.
613 # Find out the git version
614 if(GIT_FOUND AND NOT GIT_VERSION)
615 execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
616 OUTPUT_VARIABLE _exec_out
617 OUTPUT_STRIP_TRAILING_WHITESPACE)
618 string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
619 set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
620 mark_as_advanced(GIT_VERSION)
623 if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
624 message("No compatible git version found, won't be able to generate proper development version information.")
625 set(USE_VERSION_H OFF)
629 set(USE_VERSION_H OFF)
632 ########################################################################
633 # Generate development version info for cache
634 ########################################################################
635 # set(GEN_VERSION_INFO_INTERNAL "ON")
636 # include(gmxGenerateVersionString)
638 ########################################################################
639 # Our own GROMACS tests
640 ########################################################################
642 add_definitions( -DHAVE_CONFIG_H )
643 include_directories(${CMAKE_BINARY_DIR}/src)
644 include_directories(${CMAKE_BINARY_DIR}/include)
645 include_directories(${CMAKE_SOURCE_DIR}/include)
647 include(gmxTestInlineASM)
648 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
650 include(gmxSetBuildInformation)
651 gmx_set_build_information()
652 if(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
653 # The timestep counter headers do not include config.h
654 add_definitions(-DHAVE_RDTSCP)
655 endif(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
657 include(gmxTestFloatFormat)
658 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
659 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
660 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
662 include(gmxTestLargeFiles)
663 gmx_test_large_files(GMX_LARGEFILES)
665 include(gmxTestSignal)
666 gmx_test_sigusr1(HAVE_SIGUSR1)
668 include(gmxTestInline)
669 gmx_test_inline(INLINE_KEYWORD)
671 include(gmxTestRestrict)
672 gmx_test_restrict(RESTRICT_KEYWORD)
674 include(gmxTestPipes)
675 gmx_test_pipes(HAVE_PIPES)
677 include(gmxTestIsfinite)
678 gmx_test_isfinite(HAVE_ISFINITE)
679 gmx_test__isfinite(HAVE__ISFINITE)
680 gmx_test__finite(HAVE__FINITE)
683 gmx_test_xdr(GMX_SYSTEM_XDR)
684 if(NOT GMX_SYSTEM_XDR)
685 set(GMX_INTERNAL_XDR 1)
686 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
687 endif(NOT GMX_SYSTEM_XDR)
689 # Process nonbonded accelerated kernels settings
690 string(TOUPPER ${GMX_CPU_ACCELERATION} ${GMX_CPU_ACCELERATION})
691 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
693 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
695 GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" GROMACS_C_FLAGS)
696 if(NOT GNU_SSE2_CFLAG)
697 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
698 endif(NOT GNU_SSE2_CFLAG)
700 if (CMAKE_CXX_COMPILER_LOADED)
701 GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
702 if(NOT GNU_SSE2_CXXFLAG)
703 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
704 endif(NOT GNU_SSE2_CXXFLAG)
707 # We dont warn for lacking SSE2 flag support, since that is probably standard today.
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 ${GROMACS_C_FLAGS})
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)
716 set(GMX_CPU_ACCELERATION_X86_SSE2 1)
717 # The user should not be able to set this orthogonally to the acceleration
719 if (NOT ACCELERATION_QUIETLY)
720 message(STATUS "Enabling SSE2 Gromacs acceleration, and it will help compiler optimization.")
723 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
725 GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" GROMACS_C_FLAGS)
726 if (NOT GNU_SSE4_CFLAG)
727 GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" GROMACS_C_FLAGS)
728 endif(NOT GNU_SSE4_CFLAG)
729 if (NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
730 message(WARNING "No C SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
731 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
732 # intrinsics when SSE2 support is enabled, so we try that instead.
733 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
734 endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
736 if (CMAKE_CXX_COMPILER_LOADED)
737 GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
738 if (NOT GNU_SSE4_CXXFLAG)
739 GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
740 endif(NOT GNU_SSE4_CXXFLAG)
741 if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
742 message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
743 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
744 # intrinsics when SSE2 support is enabled, so we try that instead.
745 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
746 endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
749 # This must come after we have added the -msse4.1 flag on some platforms.
750 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
752 if(NOT HAVE_SMMINTRIN_H)
753 message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
754 endif(NOT HAVE_SMMINTRIN_H)
756 set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
757 # The user should not be able to set this orthogonally to the acceleration
758 set(GMX_X86_SSE4_1 1)
760 if (NOT ACCELERATION_QUIETLY)
761 message(STATUS "Enabling SSE4.1 Gromacs acceleration, and it will help compiler optimization.")
764 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
766 # Set the AVX compiler flag for both these choices!
768 GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" GROMACS_C_FLAGS)
769 if (NOT GNU_AVX_CFLAG)
770 GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" GROMACS_C_FLAGS)
771 endif (NOT GNU_AVX_CFLAG)
772 if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
773 message(WARNING "No C AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
774 endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
776 if (CMAKE_CXX_COMPILER_LOADED)
777 GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
778 if (NOT GNU_AVX_CXXFLAG)
779 GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
780 endif (NOT GNU_AVX_CXXFLAG)
781 if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
782 message(WARNING "No C++ AVX flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
783 endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
786 # Set the FMA4 flags (MSVC doesn't require any)
787 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
788 GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
789 if (NOT GNU_FMA_CFLAG)
790 message(WARNING "No C FMA4 flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
791 endif(NOT GNU_FMA_CFLAG)
792 GMX_TEST_CFLAG(GNU_XOP_CFLAG "-mxop" GROMACS_C_FLAGS)
793 # No big deal if we do not have xop, so no point yelling warnings about it.
794 if (CMAKE_CXX_COMPILER_LOADED)
795 GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
796 if (NOT GNU_FMA_CXXFLAG)
797 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or try SSE4.1 (lower performance).")
798 endif (NOT GNU_FMA_CXXFLAG)
799 GMX_TEST_CXXFLAG(GNU_XOP_CXXFLAG "-mxop" GROMACS_CXX_FLAGS)
800 # No big deal if we do not have xop, so no point yelling warnings about it.
804 # Only test the header after we have tried to add the flag for AVX support
805 check_include_file(immintrin.h HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
807 if(NOT HAVE_IMMINTRIN_H)
808 message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
809 endif(NOT HAVE_IMMINTRIN_H)
811 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
812 try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
813 "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
814 COMPILE_DEFINITIONS "${GROMACS_C_FLAGS}")
816 message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
820 # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
821 check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
822 check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
824 # The user should not be able to set this orthogonally to the acceleration
825 set(GMX_X86_SSE4_1 1)
828 # But just enable one of the choices internally...
829 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
830 set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
831 set(GMX_X86_AVX_128_FMA 1)
832 if (NOT ACCELERATION_QUIETLY)
833 message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add), and it will help compiler optimization.")
836 # If we are not doing AVX_128, it must be AVX_256...
837 set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
838 set(GMX_X86_AVX_256 1)
839 if (NOT ACCELERATION_QUIETLY)
840 message(STATUS "Enabling 256-bit AVX Gromacs acceleration, and it will help compiler optimization.")
844 elseif(${GMX_CPU_ACCELERATION} STREQUAL "FORTRAN")
846 # Fortran is temporarily disabled while we push in nbNxN kernels.
847 # We need to fake it a bit here to avoid jenkins build errors!
848 # add_definitions(-DGMX_FORTRAN)
850 elseif(${GMX_CPU_ACCELERATION} STREQUAL "BLUEGENE")
851 # GMX_CPU_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
852 if (NOT ACCELERATION_QUIETLY)
853 message(STATUS "Configuring for BlueGene")
856 if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
857 set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
858 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
859 endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
860 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
861 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware 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 elseif(${GMX_CPU_ACCELERATION} STREQUAL "POWER6")
874 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on Power6" FORCE)
875 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on Power6" FORCE)
876 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
877 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")
878 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
879 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
881 if(GMX_FORTRAN OR GMX_POWER6)
883 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).")
884 endif(GMX_THREAD_MPI)
885 enable_language(Fortran)
886 include(FortranCInterface)
887 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
888 if(extra_under_score)
890 endif(extra_under_score)
892 set(prefix "${prefix} ##")
895 set(suffix "## ${suffix}")
897 set(extrasuffix "${suffix}${extrasuffix}")
901 # Don't know if this is needed, but it can't hurt
902 set(extrasuffix "## ${extrasuffix}")
907 set(F77_FUNCDEF "${prefix} NAME ${suffix}")
908 set(F77_FUNCDEF_ "${prefix} NAME ${extrasuffix}")
910 set(F77_FUNCDEF "${prefix} name ${suffix}")
911 set(F77_FUNCDEF_ "${prefix} name ${extrasuffix}")
913 else(GMX_FORTRAN OR GMX_POWER6)
914 set(F77_FUNCDEF "name ## _")
915 set(F77_FUNCDEF_ "name ## _")
916 endif(GMX_FORTRAN OR GMX_POWER6)
918 # Process QM/MM Settings
919 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
920 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
921 set(GMX_QMMM_GAUSSIAN 1)
922 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
923 set(GMX_QMMM_MOPAC 1)
924 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
925 set(GMX_QMMM_GAMESS 1)
926 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
928 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
930 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
931 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
932 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
934 # Process FFT library settings - if not OpenMM build
935 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
938 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
945 if(GMX_BUILD_OWN_FFTW)
946 add_subdirectory(src/contrib/fftw)
948 find_package(FFTW COMPONENTS ${FFTW})
951 string(TOUPPER "${FFTW}" FFTW)
952 set(PKG_FFT "${${FFTW}_PKG}")
953 include_directories(${${FFTW}_INCLUDE_DIRS})
954 set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
955 if(NOT ${FFTW}_FOUND)
956 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.")
961 if (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD)
962 message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
965 if(NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND ${FFTW}_HAVE_AVX)
966 # If we're not doing CPU acceleration, we don't care about FFTW performance on x86 either
967 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.")
970 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
971 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
972 find_package(MKL REQUIRED)
973 include_directories(${MKL_INCLUDE_DIR})
974 set(FFT_LIBRARIES ${MKL_LIBRARIES})
975 set(PKG_FFT_LIBS ${MKL_LIBRARIES})
980 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
981 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
982 # set(GMX_FFT_ACML 1)
983 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
984 MESSAGE(STATUS "Using internal FFT library - fftpack")
985 set(GMX_FFT_FFTPACK 1)
986 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
987 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
988 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
990 # enable threaded fftw3 if we've found it
991 if(FFTW3_THREADS OR FFTW3F_THREADS)
992 add_definitions(-DFFT5D_FFTW_THREADS)
995 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
996 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
997 # MKL has BLAS/LAPACK routines
998 if(NOT HAVE_MKL AND NOT ACCELERATE_FRAMEWORK)
999 if(GMX_EXTERNAL_BLAS)
1001 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
1003 set(BLAS_FIND_QUIETLY ON)
1006 list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
1008 MESSAGE(STATUS "Using internal BLAS library")
1009 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in" FORCE)
1011 endif(GMX_BLAS_USER)
1012 endif(GMX_EXTERNAL_BLAS)
1013 if(GMX_EXTERNAL_LAPACK)
1014 if (GMX_LAPACK_USER)
1015 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
1016 else(GMX_LAPACK_USER)
1017 set(LAPACK_FIND_QUIETLY ON)
1018 find_package(LAPACK)
1020 list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
1022 MESSAGE(STATUS "Using internal LAPACK library")
1023 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in" FORCE)
1025 endif(GMX_LAPACK_USER)
1026 endif(GMX_EXTERNAL_LAPACK)
1028 mark_as_advanced(GMX_EXTERNAL_LAPACK)
1029 mark_as_advanced(GMX_EXTERNAL_BLAS)
1031 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
1033 if(GMX_LOAD_PLUGINS)
1034 if(CYGWIN OR NOT WIN32)
1035 # Native Windows does not have, nor need dlopen
1036 # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
1037 include(gmxTestdlopen)
1038 gmx_test_dlopen(HAVE_DLOPEN)
1041 # so, should we use plug-ins?
1042 if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1045 "Found the ability to use plug-ins when building shared libaries, "
1046 "so will compile to use plug-ins (e.g. to read VMD-supported file "
1049 if(NOT GMX_VMD_PLUGIN_PATH)
1052 set(GMX_USE_PLUGINS ON)
1053 list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1054 set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1058 endif(GMX_LOAD_PLUGINS)
1059 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1061 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1062 if(NOT CMAKE_CROSSCOMPILING)
1063 option(GMX_BUILD_MANPAGES "Build man pages" ON)
1065 message(STATUS "Building the man pages is not available when "
1066 "cross-compiling the developer version from git")
1069 #make sure source package contains all man pages
1070 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1071 message(FATAL_ERROR "Man pages are missing from source package.")
1074 mark_as_advanced(GMX_BUILD_MANPAGES)
1076 # Math and thread libraries must often come after all others when linking...
1078 list(APPEND GMX_EXTRA_LIBRARIES m)
1082 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
1083 "Path to swindirect.h")
1084 include_directories(${COREWRAP_INCLUDE_DIR})
1087 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1088 # these are set after everything else
1089 if (NOT DEFINED GROMACS_C_FLAGS_SET)
1090 set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
1092 set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING
1093 "Flags used by the compiler during all build types" FORCE)
1094 if (CMAKE_CXX_COMPILER_LOADED)
1095 set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING
1096 "Flags used by the compiler during all build types" FORCE)
1098 set(CMAKE_EXE_LINKER_FLAGS
1099 "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}"
1100 CACHE STRING "Linker flags for creating executables" FORCE)
1101 set(CMAKE_SHARED_LINKER_FLAGS
1102 "${GROMACS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}"
1103 CACHE STRING "Linker flags for creating shared libraries" FORCE)
1104 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
1107 #Unset all OpenMP flags in case OpenMP was disabled either by the user
1108 #or because it was only partially detected (e.g. only for C but not C++ compiler)
1109 unset(OpenMP_C_FLAGS CACHE)
1110 unset(OpenMP_CXX_FLAGS CACHE)
1111 unset(OpenMP_LINKER_FLAGS CACHE)
1112 unset(OpenMP_SHARED_LINKER_FLAGS)
1115 ######################################
1116 # Output compiler and CFLAGS used
1117 ######################################
1118 get_compiler_info(C BUILD_C_COMPILER BUILD_CFLAGS)
1119 if (CMAKE_CXX_COMPILER_LOADED)
1120 get_compiler_info(CXX BUILD_CXX_COMPILER BUILD_CXXFLAGS)
1123 ########################################################################
1124 # Specify install locations and which subdirectories to process #
1125 ########################################################################
1126 if (GMX_USE_RELATIVE_INSTALL_PATH)
1127 set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1128 mark_as_advanced(GMX_INSTALL_PREFIX)
1130 set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1133 if ( NOT DEFINED GMXLIB )
1136 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1137 set(BIN_INSTALL_DIR ${GMX_INSTALL_PREFIX}bin)
1138 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1139 set(MAN_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/man)
1140 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1142 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
1144 ##################################################################
1145 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
1146 ##################################################################
1147 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1148 set(CMAKE_SKIP_BUILD_RPATH FALSE)
1149 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1150 set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1151 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1154 #COPYING file: Only necessary for binary distributions.
1155 #Simpler to always install.
1156 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1158 add_subdirectory(share)
1159 add_subdirectory(include)
1160 add_subdirectory(src)
1161 add_subdirectory(scripts)
1163 # issue GPU acceleration/CUDA-related warning or error if GMX_GPU was set
1164 # Auto and NVIDIA GPUs were detected.
1165 if (CUDA_NOTFOUND_AUTO AND NOT GMX_GPU_DETECTION_DONE)
1166 message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
1167 unset(CUDA_NOTFOUND_AUTO)
1168 unset(CUDA_NOTFOUND_MESSAGE)
1170 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
1172 #######################
1174 #######################
1176 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1177 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1179 ###########################
1180 ADD_CUSTOM_TARGET(uninstall
1181 "${CMAKE_COMMAND}" -P
1182 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1183 ###########################
1185 ########################################################################
1187 ########################################################################
1190 mark_as_advanced(BUILD_TESTING)
1193 add_subdirectory(tests)