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-dev")
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 if(NOT CMAKE_BUILD_TYPE)
63 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
64 endif(NOT CMAKE_BUILD_TYPE)
68 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
69 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
71 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
72 set(CPACK_PACKAGE_VENDOR "gromacs.org")
73 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
74 if (NOT GMX_USE_RELATIVE_INSTALL_PATH)
75 set(CPACK_SET_DESTDIR "ON")
77 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
78 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
79 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
80 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
81 set(CPACK_SOURCE_IGNORE_FILES ".isreposource;.git;.gitignore")
82 set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_SOURCE_DIR}/CPackInit.cmake")
83 SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/man;man")
84 set(CPACK_PACKAGE_CONTACT "gmx-users@gromacs.org")
86 #must come after all cpack settings!
89 ########################################################################
90 # Check and warn if cache generated on a different host is being reused
91 ########################################################################
93 execute_process(COMMAND hostname
94 OUTPUT_VARIABLE TMP_HOSTNAME
95 OUTPUT_STRIP_TRAILING_WHITESPACE)
96 if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
98 The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
99 is being reused! This could lead to inconsitencies; therefore, it is
100 recommended to regenerate the cache!")
102 set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
103 "Hostname of the machine where the cache was generated.")
106 ########################################################################
107 # User input options - enable C++ - before any CXX flags are changed #
108 ########################################################################
109 option(GMX_GPU "Enable GPU acceleration" ON)
110 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
111 option(GMX_FORCE_CXX "Enable C++ compilation even if not necessary" OFF)
112 mark_as_advanced(GMX_FORCE_CXX)
113 if(GMX_GPU OR GMX_OPENMM OR GMX_FORCE_CXX)
117 ########################################################################
118 # Fix stupid flags on Windows
119 ########################################################################
120 SET(SHARED_LIBS_DEFAULT ON)
121 IF( WIN32 AND NOT CYGWIN)
122 option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
123 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
124 SET(SHARED_LIBS_DEFAULT OFF) #is currently not working on Windows
126 IF (GMX_PREFER_STATIC_LIBS)
127 #Only setting Debug and Release flags. Others configurations current not used.
128 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
129 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
130 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
131 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
132 if(CMAKE_CXX_COMPILER_LOADED)
133 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
134 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
135 STRING(REPLACE /MD /MT CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
136 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
140 #Workaround for cmake bug 13174. Replace deprecated options.
141 IF( CMAKE_C_COMPILER_ID MATCHES "Intel" )
142 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
143 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
145 IF( CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND CMAKE_CXX_COMPILER_LOADED)
146 STRING(REPLACE /GZ /RTC1 CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
147 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
148 SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "" FORCE)
150 STRING(REPLACE /GX /EHsc CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
151 SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} CACHE STRING "" FORCE)
156 ########################################################################
157 # User input options #
158 ########################################################################
159 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
160 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
161 option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
162 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
163 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
164 option(GMX_POWERPC_INVSQRT "Use PowerPC hardware 1/sqrt" OFF)
165 mark_as_advanced(GMX_POWERPC_INVSQRT)
166 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
167 mark_as_advanced(GMX_FAHCORE)
169 include(gmxDetectAcceleration)
170 if(NOT DEFINED GMX_CPU_ACCELERATION)
171 if(CMAKE_CROSSCOMPILING)
172 set(GMX_SUGGESTED_CPU_ACCELERATION "None")
173 else(CMAKE_CROSSCOMPILING)
174 gmx_detect_acceleration(GMX_SUGGESTED_CPU_ACCELERATION)
175 endif(CMAKE_CROSSCOMPILING)
176 endif(NOT DEFINED GMX_CPU_ACCELERATION)
178 set(GMX_CPU_ACCELERATION "@GMX_SUGGESTED_CPU_ACCELERATION@"
179 CACHE STRING "Accelerated CPU kernels. Pick one of: None, SSE2, SSE4.1, AVX_128_FMA, AVX_256, BlueGene, Power6, Fortran")
181 set(GMX_FFT_LIBRARY "fftw3"
182 CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
183 option(GMX_DISABLE_FFTW_MEASURE
184 "Do not optimize FFTW setups (not needed with SSE)" OFF)
185 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
186 set(GMX_QMMM_PROGRAM "none"
187 CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
188 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
189 mark_as_advanced(GMX_BROKEN_CALLOC)
190 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
191 mark_as_advanced(GMX_MPI_IN_PLACE)
192 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
193 mark_as_advanced(GMX_LOAD_PLUGINS)
195 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
197 option(USE_VERSION_H "Generate development version string/information" ON)
198 mark_as_advanced(USE_VERSION_H)
200 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)
203 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)
204 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
207 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
208 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
210 ######################################################################
212 # these need ot be done early (before further tests).
213 #####################################################################
215 # cmake/Check{C,CXX}CompilerFlag.cmake are lifted from CMake git next
216 # branch (proposed for v2.8.9) to be able to detect invalid options
217 # with the Intel Compilers.
218 # Remove these files from the source tree when a CMake version that
219 # includes the features in question becomes required.
220 include(CheckCCompilerFlag)
221 if(CMAKE_CXX_COMPILER_LOADED)
222 include(CheckCXXCompilerFlag)
225 # OpenMP check must come before other CFLAGS!
229 #- only set linker flag, if user didn't set them manual
230 #- cmake on windows doesn't support linker flags passed to target_link_libraries
231 # (cmake treats /openmp as \openmp library file) and no openmp linker flags are needed
232 if(NOT (WIN32 AND NOT CYGWIN))
233 if(CMAKE_COMPILER_IS_GNUCC AND GMX_PREFER_STATIC_OPENMP)
234 set(OpenMP_LINKER_FLAGS "-Wl,-static -lgomp -lrt -Wl,-Bdynamic -lpthread")
235 set(OpenMP_SHARED_LINKER_FLAGS "")
237 if(NOT DEFINED OpenMP_LINKER_FLAGS)
238 set(OpenMP_LINKER_FLAGS "${OpenMP_C_FLAGS}")
240 if(NOT DEFINED OpenMP_SHARED_LINKER_FLAGS)
241 set(OpenMP_SHARED_LINKER_FLAGS "${OpenMP_C_FLAGS}")
247 "Compiler not supporting OpenMP. This might hurt your performance a lot, "
248 "in particular with GPUs. Try using a different compiler (Intel is good on x86) "
249 "if you can - for now we are proceeding by turning off OpenMP.")
250 set(GMX_OPENMP OFF CACHE STRING "Compiler does not support OpenMP." FORCE)
258 include(gmxGetCompilerVersion)
259 get_compiler_version()
261 # gcc 4.4.x is buggy and crashes when compiling some files with O3 and OpenMP on.
262 # Detect here whether applying a workaround is needed and will apply it later
263 # on the affected files.
264 include(gmxGCC44O3BugWorkaround)
265 gmx_check_gcc44_bug_workaround_needed(GMX_USE_GCC44_BUG_WORKAROUND)
267 ########################################################################
268 # Set up binary and library suffixing
269 ########################################################################
270 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
271 set(GMX_LIBS_SUFFIX ""
272 CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
273 if (GMX_DEFAULT_SUFFIX)
274 set(GMX_BINARY_SUFFIX "")
275 set(GMX_LIBS_SUFFIX "")
277 set(GMX_BINARY_SUFFIX "_mpi")
278 set(GMX_LIBS_SUFFIX "_mpi")
281 set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
282 set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
285 set (GMX_BINARY_SUFFIX "-openmm")
286 set (GMX_LIBS_SUFFIX "_openmm")
288 mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
289 if (NOT SUFFIX_QUIETLY)
290 message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
291 message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
292 endif (NOT SUFFIX_QUIETLY)
293 else(GMX_DEFAULT_SUFFIX)
294 mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
295 if (NOT SUFFIX_QUIETLY)
296 message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
297 message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
298 endif (NOT SUFFIX_QUIETLY)
299 endif(GMX_DEFAULT_SUFFIX)
300 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
304 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
306 if(GMX_SOFTWARE_INVSQRT)
307 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
308 endif(GMX_SOFTWARE_INVSQRT)
309 if(GMX_POWERPC_INVSQRT)
310 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_POWERPC_INVSQRT")
311 endif(GMX_POWERPC_INVSQRT)
313 ########################################################################
314 #Process MPI settings
315 ########################################################################
316 include(gmxManageMPI)
318 #######################################################################
319 # Check for options incompatible with OpenMM build #
320 #######################################################################
322 # we'll use the built-in fft to avoid unnecessary dependencies
323 string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
324 if(NOT ${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
325 message(STATUS "No external FFT libraries needed for the OpenMM build, switching to fftpack!")
326 set(GMX_FFT_LIBRARY "fftpack" CACHE STRING
327 "No external FFT libraries needed for the OpenMM build, switching to fftpack!" FORCE)
330 message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
333 message(STATUS "Thread-MPI not compatible with OpenMM, disabled!")
334 set(GMX_THREAD_MPI OFF CACHE BOOL
335 "Thread-MPI not compatible with OpenMM build, disabled!" FORCE)
336 endif(GMX_THREAD_MPI)
338 message(STATUS "OpenMP multithreading not compatible with OpenMM, disabled")
339 set(GMX_OPENMP OFF CACHE BOOL
340 "OpenMP multithreading not compatible with OpenMM, disabled!" FORCE)
342 if(GMX_SOFTWARE_INVSQRT)
343 set(GMX_SOFTWARE_INVSQRT OFF CACHE STRING
344 "The OpenMM build does not need GROMACS software 1/sqrt!" FORCE)
345 endif(GMX_SOFTWARE_INVSQRT)
346 string(TOUPPER ${GMX_CPU_ACCELERATION} GMX_CPU_ACCELERATION)
347 if(NOT GMX_CPU_ACCELERATION STREQUAL "NONE")
348 message(STATUS "Switching off CPU-based acceleration, the OpenMM build does not support/need any!")
349 set(GMX_CPU_ACCELERATION "None" CACHE STRING
350 "Switching off CPU-based acceleration, the OpenMM build does not support/need any!" FORCE)
353 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
356 message(FATAL_ERROR "The OpenMM-build does not support double precision calculations!")
358 # mark as advanced the unused variables
359 mark_as_advanced(FORCE GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
360 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
362 mark_as_advanced(CLEAR GMX_CPU_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
363 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
367 ########################################################################
368 # Basic system tests (standard libraries, headers, functions, types) #
369 ########################################################################
370 include(CheckIncludeFiles)
371 check_include_files(string.h HAVE_STRING_H)
372 check_include_files(math.h HAVE_MATH_H)
373 check_include_files(limits.h HAVE_LIMITS_H)
374 check_include_files(memory.h HAVE_MEMORY_H)
375 check_include_files(unistd.h HAVE_UNISTD_H)
376 check_include_files(direct.h HAVE_DIRECT_H)
377 check_include_files(pwd.h HAVE_PWD_H)
378 check_include_files(stdint.h HAVE_STDINT_H)
379 check_include_files(stdlib.h HAVE_STDLIB_H)
380 check_include_files(pthread.h HAVE_PTHREAD_H)
381 check_include_files(dirent.h HAVE_DIRENT_H)
382 check_include_files(inttypes.h HAVE_INTTYPES_H)
383 check_include_files(regex.h HAVE_REGEX_H)
384 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
385 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
386 check_include_files(sys/time.h HAVE_SYS_TIME_H)
387 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
388 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
389 check_include_files(io.h HAVE_IO_H)
390 check_include_files(sched.h HAVE_SCHED_H)
392 include(CheckFunctionExists)
393 check_function_exists(strcasecmp HAVE_STRCASECMP)
394 check_function_exists(strdup HAVE_STRDUP)
395 check_function_exists(vprintf HAVE_VPRINTF)
396 check_function_exists(memcmp HAVE_MEMCMP)
397 check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
398 check_function_exists(memalign HAVE_MEMALIGN)
399 check_function_exists(_aligned_malloc HAVE__ALIGNED_MALLOC)
400 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
401 check_function_exists(isnan HAVE_ISNAN)
402 check_function_exists(_isnan HAVE__ISNAN)
403 check_function_exists(fsync HAVE_FSYNC)
404 check_function_exists(_fileno HAVE__FILENO)
405 check_function_exists(fileno HAVE_FILENO)
406 check_function_exists(_commit HAVE__COMMIT)
407 check_function_exists(lstat HAVE_LSTAT)
408 check_function_exists(sigaction HAVE_SIGACTION)
409 check_function_exists(sysconf HAVE_SYSCONF)
410 check_function_exists(sched_setaffinity HAVE_SCHED_SETAFFINITY)
411 check_function_exists(sched_getaffinity HAVE_SCHED_GETAFFINITY)
412 check_function_exists(rsqrt HAVE_RSQRT)
413 check_function_exists(rsqrtf HAVE_RSQRTF)
414 check_function_exists(sqrtf HAVE_SQRTF)
416 include(CheckLibraryExists)
417 check_library_exists(m sqrt "" HAVE_LIBM)
418 check_library_exists(m cbrt "" HAVE_CBRT)
421 include(CheckTypeSize)
423 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
424 check_type_size("int" SIZEOF_INT)
425 check_type_size("long int" SIZEOF_LONG_INT)
426 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
427 check_type_size("off_t" SIZEOF_OFF_T)
428 check_type_size("void *" SIZEOF_VOIDP)
430 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
432 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
433 set(GMX_64_BIT FALSE)
434 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
436 # Check for some basic types that we *need*, so set these to int if they are not present
437 check_type_size(uid_t uid_t)
444 check_type_size(gid_t gid_t)
451 check_type_size(size_t size_t)
458 check_type_size(off_t off_t)
465 include(TestBigEndian)
466 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
471 ########################################################################
472 # Find external packages #
473 ########################################################################
475 if(GMX_PREFER_STATIC_LIBS)
476 # On Linux .a is the static library suffix, on Mac OS X .lib can also
477 # be used, so we'll add both to the preference list.
478 SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.a" ${CMAKE_FIND_LIBRARY_SUFFIXES})
479 if(SHARED_LIBS_DEFAULT)
480 if(BUILD_SHARED_LIBS) #Warn the user about the combination. But don't overwrite the request.
481 message(WARNING "Static libraries requested, and shared Gromacs libraries requested.")
482 elseif(NOT DEFINED BUILD_SHARED_LIBS) #Change default to OFF. Don't warn if it's already off.
483 message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
484 set(SHARED_LIBS_DEFAULT OFF)
489 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
491 option(GMX_GSL "Add support for gsl" OFF)
496 include_directories(${GSL_INCLUDE_DIR})
502 option(GMX_X11 "Use X window system" OFF)
505 # X11 includes/libraries are only set in the ngmx subdirectory!
512 set(THREAD_MPI_LIB thread_mpi)
514 tmpi_get_source_list(THREAD_MPI_SRC)
515 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
518 tmpi_get_source_list(THREAD_MPI_SRC NOMPI)
519 endif(GMX_THREAD_MPI)
522 set(CUDA_BUILD_EMULATION OFF)
523 find_package(CUDA 3.1 REQUIRED)
524 add_definitions(-DGMX_OPENMM)
525 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
526 set(CUDA_VERBOSE_BUILD ON)
534 message(WARNING "GPU acceleration is not available in double precision, disabled!")
535 set(GMX_GPU OFF CACHE BOOL "Enable GPU acceleration" FORCE)
541 # We support CUDA >=v3.2 on *nix, but <= v4.1 doesn't work with MSVC
543 find_package(CUDA 4.1)
545 find_package(CUDA 3.2)
548 if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
549 message(FATAL_ERROR "
550 mdrun supports native GPU acceleration on NVIDIA hardware with compute
551 capability >=2.0. This requires the NVIDIA CUDA library, which was not
552 found; the location can be hinted by setting CUDA_TOOLKIT_ROOT_DIR.
554 CPU or GPU acceleration can be selected at runtime, but if you are
555 sure you can not make use of GPU acceleration, disable it by setting
556 the CMake variable GMX_GPU=OFF.")
561 In order to use GPU acceleration efficiently, mdrun requires OpenMP multithreding.
562 Without OpenMP only a single CPU core per GPU can be used which is suboptimal.
563 Note that with MPI multiple processes can be forced to use a single GPU, but this
564 typically inefficient.")
567 include(gmxManageNvccConfig)
569 # Check whether we can use atomic operations needed for polling wait for GPU
570 # (to avoid the cudaStreamSynchronize + ECC bug).
571 # With thread-MPI testing atomics has already been carried out, but without
572 # thread-MPI we need to invoke the atomics test independently.
573 if (NOT GMX_THREAD_MPI)
574 set(TEST_TMPI_ATOMICS_ONLY ON CACHE INTERNAL
575 "Test only the atomic operations of thread-MPI.")
579 # we need this linker flag in case if we have ld >= 2.22 (typically with gcc 4.5+),
580 # but it's too cumbersome to check the ld version and the flag should not hurt
581 if(CMAKE_COMPILER_IS_GNUCC)
582 set(GROMACS_LINKER_FLAGS "-Wl,--add-needed ${GROMACS_LINKER_FLAGS}")
585 # Annoyingly enough, FindCUDA leaves a few variables behind as non-advanced.
586 # We need to mark these advanced outside the conditional, otherwise, if the user
587 # tuns GMX_GPU=OFF after a failed cmake pass, these variables will be left behind.
588 mark_as_advanced(CUDA_BUILD_CUBIN CUDA_BUILD_EMULATION CUDA_SDK_ROOT_DIR CUDA_VERBOSE_BUILD)
591 find_library(ACCELERATE_FRAMEWORK Accelerate)
592 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
599 if(WIN32 AND NOT CYGWIN)
600 set(GMX_NATIVE_WINDOWS 1)
603 # only bother with finding git and using version.h if the source is a git repo
604 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
606 # We need at least git v1.5.3 be able to parse git's date output. If not
607 # found or the version is too small, we can't generate version information.
610 # Find out the git version
611 if(GIT_FOUND AND NOT GIT_VERSION)
612 execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
613 OUTPUT_VARIABLE _exec_out
614 OUTPUT_STRIP_TRAILING_WHITESPACE)
615 string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
616 set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
617 mark_as_advanced(GIT_VERSION)
620 if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.3")
621 message("No compatible git version found, won't be able to generate proper development version information.")
622 set(USE_VERSION_H OFF)
626 set(USE_VERSION_H OFF)
629 ########################################################################
630 # Generate development version info for cache
631 ########################################################################
632 # set(GEN_VERSION_INFO_INTERNAL "ON")
633 # include(gmxGenerateVersionString)
635 ########################################################################
636 # Our own GROMACS tests
637 ########################################################################
639 add_definitions( -DHAVE_CONFIG_H )
640 include_directories(${CMAKE_BINARY_DIR}/src)
641 include_directories(${CMAKE_BINARY_DIR}/include)
642 include_directories(${CMAKE_SOURCE_DIR}/include)
644 include(gmxTestInlineASM)
645 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
647 include(gmxSetBuildInformation)
648 gmx_set_build_information()
649 if(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
650 # The timestep counter headers do not include config.h
651 add_definitions(-DHAVE_RDTSCP)
652 endif(BUILD_CPU_FEATURES MATCHES "rdtscp" AND NOT GMX_DISTRIBUTABLE_BUILD)
654 include(gmxTestFloatFormat)
655 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
656 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
657 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
659 include(gmxTestLargeFiles)
660 gmx_test_large_files(GMX_LARGEFILES)
662 include(gmxTestSignal)
663 gmx_test_sigusr1(HAVE_SIGUSR1)
665 include(gmxTestInline)
666 gmx_test_inline(INLINE_KEYWORD)
668 include(gmxTestRestrict)
669 gmx_test_restrict(RESTRICT_KEYWORD)
671 include(gmxTestPipes)
672 gmx_test_pipes(HAVE_PIPES)
674 include(gmxTestIsfinite)
675 gmx_test_isfinite(HAVE_ISFINITE)
676 gmx_test__isfinite(HAVE__ISFINITE)
677 gmx_test__finite(HAVE__FINITE)
680 gmx_test_xdr(GMX_SYSTEM_XDR)
681 if(NOT GMX_SYSTEM_XDR)
682 set(GMX_INTERNAL_XDR 1)
683 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
684 endif(NOT GMX_SYSTEM_XDR)
686 # Process nonbonded accelerated kernels settings
687 string(TOUPPER ${GMX_CPU_ACCELERATION} ${GMX_CPU_ACCELERATION})
688 if(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
690 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE2")
692 GMX_TEST_CFLAG(GNU_SSE2_CFLAG "-msse2" GROMACS_C_FLAGS)
693 if(NOT GNU_SSE2_CFLAG)
694 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
695 endif(NOT GNU_SSE2_CFLAG)
697 if (CMAKE_CXX_COMPILER_LOADED)
698 GMX_TEST_CXXFLAG(GNU_SSE2_CXXFLAG "-msse2" GROMACS_CXX_FLAGS)
699 if(NOT GNU_SSE2_CXXFLAG)
700 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
701 endif(NOT GNU_SSE2_CXXFLAG)
704 # We dont warn for lacking SSE2 flag support, since that is probably standard today.
706 # Only test the include after we have tried to add the correct flag for SSE2 support
707 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${GROMACS_C_FLAGS})
709 if(NOT HAVE_EMMINTRIN_H)
710 message(FATAL_ERROR "Cannot find emmintrin.h, which is required for SSE2 intrinsics support.")
711 endif(NOT HAVE_EMMINTRIN_H)
713 set(GMX_CPU_ACCELERATION_X86_SSE2 1)
714 # The user should not be able to set this orthogonally to the acceleration
716 if (NOT ACCELERATION_QUIETLY)
717 message(STATUS "Enabling SSE2 Gromacs acceleration, and it will help compiler optimization.")
720 elseif(${GMX_CPU_ACCELERATION} STREQUAL "SSE4.1")
722 GMX_TEST_CFLAG(GNU_SSE4_CFLAG "-msse4.1" GROMACS_C_FLAGS)
723 if (NOT GNU_SSE4_CFLAG)
724 GMX_TEST_CFLAG(MSVC_SSE4_CFLAG "/arch:SSE4.1" GROMACS_C_FLAGS)
725 endif(NOT GNU_SSE4_CFLAG)
726 if (NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
727 message(WARNING "No C SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
728 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
729 # intrinsics when SSE2 support is enabled, so we try that instead.
730 GMX_TEST_CFLAG(MSVC_SSE2_CFLAG "/arch:SSE2" GROMACS_C_FLAGS)
731 endif(NOT GNU_SSE4_CFLAG AND NOT MSVC_SSE4_CFLAG)
733 if (CMAKE_CXX_COMPILER_LOADED)
734 GMX_TEST_CXXFLAG(GNU_SSE4_CXXFLAG "-msse4.1" GROMACS_CXX_FLAG)
735 if (NOT GNU_SSE4_CXXFLAG)
736 GMX_TEST_CXXFLAG(MSVC_SSE4_CXXFLAG "/arch:SSE4.1" GROMACS_CXX_FLAGS)
737 endif(NOT GNU_SSE4_CXXFLAG)
738 if (NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
739 message(WARNING "No C++ SSE4.1 flag found. Consider a newer compiler, or disable SSE4.1 for slightly lower performance.")
740 # Not surprising if we end up here! MSVC current does not support the SSE4.1 flag. However, it appears to accept SSE4.1
741 # intrinsics when SSE2 support is enabled, so we try that instead.
742 GMX_TEST_CXXFLAG(MSVC_SSE2_CXXFLAG "/arch:SSE2" GROMACS_CXX_FLAGS)
743 endif(NOT GNU_SSE4_CXXFLAG AND NOT MSVC_SSE4_CXXFLAG)
746 # This must come after we have added the -msse4.1 flag on some platforms.
747 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${GROMACS_C_FLAGS})
749 if(NOT HAVE_SMMINTRIN_H)
750 message(FATAL_ERROR "Cannot find smmintrin.h, which is required for SSE4.1 intrinsics support.")
751 endif(NOT HAVE_SMMINTRIN_H)
753 set(GMX_CPU_ACCELERATION_X86_SSE4_1 1)
754 # The user should not be able to set this orthogonally to the acceleration
755 set(GMX_X86_SSE4_1 1)
757 if (NOT ACCELERATION_QUIETLY)
758 message(STATUS "Enabling SSE4.1 Gromacs acceleration, and it will help compiler optimization.")
761 elseif(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" OR ${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
763 # Set the AVX compiler flag for both these choices!
765 GMX_TEST_CFLAG(GNU_AVX_CFLAG "-mavx" GROMACS_C_FLAGS)
766 if (NOT GNU_AVX_CFLAG)
767 GMX_TEST_CFLAG(MSVC_AVX_CFLAG "/arch:AVX" GROMACS_C_FLAGS)
768 endif (NOT GNU_AVX_CFLAG)
769 if (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
770 message(WARNING "No C AVX flag found. Consider a newer compiler, or disable AVX for much lower performance.")
771 endif (NOT GNU_AVX_CFLAG AND NOT MSVC_AVX_CFLAG)
773 if (CMAKE_CXX_COMPILER_LOADED)
774 GMX_TEST_CXXFLAG(GNU_AVX_CXXFLAG "-mavx" GROMACS_CXX_FLAGS)
775 if (NOT GNU_AVX_CXXFLAG)
776 GMX_TEST_CXXFLAG(MSVC_AVX_CXXFLAG "/arch:AVX" GROMACS_CXX_FLAGS)
777 endif (NOT GNU_AVX_CXXFLAG)
778 if (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
779 message(WARNING "No C++ AVX flag found. Consider a newer compiler, or disable AVX for much lower performance.")
780 endif (NOT GNU_AVX_CXXFLAG AND NOT MSVC_AVX_CXXFLAG)
783 # Set the FMA4 flags (MSVC doesn't require any)
784 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA" AND NOT MSVC)
785 GMX_TEST_CFLAG(GNU_FMA_CFLAG "-mfma4" GROMACS_C_FLAGS)
786 if (NOT GNU_FMA_CFLAG)
787 message(WARNING "No C FMA4 flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
788 endif(NOT GNU_FMA_CFLAG)
789 if (CMAKE_CXX_COMPILER_LOADED)
790 GMX_TEST_CXXFLAG(GNU_FMA_CXXFLAG "-mfma4" GROMACS_CXX_FLAGS)
791 if (NOT GNU_FMA_CXXFLAG)
792 message(WARNING "No C++ FMA flag found. Consider a newer compiler, or disable AVX_128_FMA for much lower performance.")
793 endif (NOT GNU_FMA_CXXFLAG)
797 # Only test the header after we have tried to add the flag for AVX support
798 check_include_file(immintrin.h HAVE_IMMINTRIN_H ${GROMACS_C_FLAGS})
800 if(NOT HAVE_IMMINTRIN_H)
801 message(FATAL_ERROR "Cannot find immintrin.h, which is required for AVX intrinsics support. Consider switching compiler.")
802 endif(NOT HAVE_IMMINTRIN_H)
804 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_256")
805 try_compile(TEST_AVX ${CMAKE_BINARY_DIR}
806 "${CMAKE_SOURCE_DIR}/cmake/TestAVX.c"
807 COMPILE_DEFINITIONS "${GROMACS_C_FLAGS}")
809 message(FATAL_ERROR "Cannot compile AVX intrinsics. Consider switching compiler.")
813 # GCC requires x86intrin.h for FMA support. MSVC 2010 requires intrin.h for FMA support.
814 check_include_file(x86intrin.h HAVE_X86INTRIN_H ${GROMACS_C_FLAGS})
815 check_include_file(intrin.h HAVE_INTRIN_H ${GROMACS_C_FLAGS})
817 # The user should not be able to set this orthogonally to the acceleration
818 set(GMX_X86_SSE4_1 1)
821 # But just enable one of the choices internally...
822 if(${GMX_CPU_ACCELERATION} STREQUAL "AVX_128_FMA")
823 set(GMX_CPU_ACCELERATION_X86_AVX_128_FMA 1)
824 set(GMX_X86_AVX_128_FMA 1)
825 if (NOT ACCELERATION_QUIETLY)
826 message(STATUS "Enabling 128-bit AVX Gromacs acceleration (with fused-multiply add), and it will help compiler optimization.")
829 # If we are not doing AVX_128, it must be AVX_256...
830 set(GMX_CPU_ACCELERATION_X86_AVX_256 1)
831 set(GMX_X86_AVX_256 1)
832 if (NOT ACCELERATION_QUIETLY)
833 message(STATUS "Enabling 256-bit AVX Gromacs acceleration, and it will help compiler optimization.")
837 elseif(${GMX_CPU_ACCELERATION} STREQUAL "FORTRAN")
839 # Fortran is temporarily disabled while we push in nbNxN kernels.
840 # We need to fake it a bit here to avoid jenkins build errors!
841 # add_definitions(-DGMX_FORTRAN)
843 elseif(${GMX_CPU_ACCELERATION} STREQUAL "BLUEGENE")
844 # GMX_CPU_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
845 if (NOT ACCELERATION_QUIETLY)
846 message(STATUS "Configuring for BlueGene")
849 if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
850 set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
851 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
852 endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
853 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
854 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on BlueGene" FORCE)
855 set(GMX_X11 OFF CACHE BOOL "X11 not compatible with BlueGene, disabled!" FORCE)
856 set(GMX_THREAD_MPI OFF CACHE BOOL "Thread-MPI not compatible with BlueGene, disabled!" FORCE)
857 set(GMX_MPI ON CACHE BOOL "Use MPI on BlueGene" FORCE)
858 # Access to /etc/passwd is not available on the back end of BlueGene,
859 # despite being detected by CMake. This can cause linker warnings
860 # about harmless things in src/gmxlib/string2.h.
862 # The automatic testing for endianness does not work for the BlueGene cross-compiler
863 set(GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP byte order (by default)" FORCE)
864 set(GMX_IEEE754_BIG_ENDIAN_WORD_ORDER 1 CACHE INTERNAL "BlueGene has big endian FP word order (by default)" FORCE)
865 elseif(${GMX_CPU_ACCELERATION} STREQUAL "POWER6")
867 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on Power6" FORCE)
868 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on Power6" FORCE)
869 else(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
870 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")
871 endif(${GMX_CPU_ACCELERATION} STREQUAL "NONE")
872 set(ACCELERATION_QUIETLY TRUE CACHE INTERNAL "")
874 if(GMX_FORTRAN OR GMX_POWER6)
876 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).")
877 endif(GMX_THREAD_MPI)
878 enable_language(Fortran)
879 include(FortranCInterface)
880 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
881 if(extra_under_score)
883 endif(extra_under_score)
885 set(prefix "${prefix} ##")
888 set(suffix "## ${suffix}")
890 set(extrasuffix "${suffix}${extrasuffix}")
894 # Don't know if this is needed, but it can't hurt
895 set(extrasuffix "## ${extrasuffix}")
900 set(F77_FUNCDEF "${prefix} NAME ${suffix}")
901 set(F77_FUNCDEF_ "${prefix} NAME ${extrasuffix}")
903 set(F77_FUNCDEF "${prefix} name ${suffix}")
904 set(F77_FUNCDEF_ "${prefix} name ${extrasuffix}")
906 else(GMX_FORTRAN OR GMX_POWER6)
907 set(F77_FUNCDEF "name ## _")
908 set(F77_FUNCDEF_ "name ## _")
909 endif(GMX_FORTRAN OR GMX_POWER6)
911 # Process QM/MM Settings
912 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
913 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
914 set(GMX_QMMM_GAUSSIAN 1)
915 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
916 set(GMX_QMMM_MOPAC 1)
917 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
918 set(GMX_QMMM_GAMESS 1)
919 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
921 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
923 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
924 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
925 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
927 # Process FFT library settings - if not OpenMM build
928 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
931 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
937 find_package(FFTW COMPONENTS ${FFTW})
938 string(TOUPPER "${FFTW}" FFTW)
939 set(PKG_FFT "${${FFTW}_PKG}")
940 include_directories(${${FFTW}_INCLUDE_DIRS})
941 set(FFT_LIBRARIES ${${FFTW}_LIBRARIES})
942 if(NOT ${FFTW}_FOUND)
943 MESSAGE(FATAL_ERROR "Cannot find FFTW3 (with correct precision - libfftw3f for single precision GROMACS or libfftw3 for double precision GROMACS). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
944 endif(NOT ${FFTW}_FOUND)
948 if (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD)
949 message(WARNING "The fftw library found is compiled without SIMD support, which makes it slow. Consider recompiling it or contact your admin")
950 endif (NOT ${GMX_CPU_ACCELERATION} STREQUAL "NONE" AND NOT ${FFTW}_HAVE_SIMD)
952 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
953 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
954 find_package(MKL REQUIRED)
955 include_directories(${MKL_INCLUDE_DIR})
956 set(FFT_LIBRARIES ${MKL_LIBRARIES})
957 set(PKG_FFT_LIBS ${MKL_LIBRARIES})
962 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
963 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
964 # set(GMX_FFT_ACML 1)
965 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
966 MESSAGE(STATUS "Using internal FFT library - fftpack")
967 set(GMX_FFT_FFTPACK 1)
968 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
969 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
970 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
972 # enable threaded fftw3 if we've found it
973 if(FFTW3_THREADS OR FFTW3F_THREADS)
974 add_definitions(-DFFT5D_FFTW_THREADS)
977 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
978 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
979 # MKL has BLAS/LAPACK routines
980 if(NOT HAVE_MKL AND NOT ACCELERATE_FRAMEWORK)
981 if(GMX_EXTERNAL_BLAS)
983 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
985 set(BLAS_FIND_QUIETLY ON)
988 list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
990 MESSAGE(STATUS "Using internal BLAS library")
991 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in" FORCE)
994 endif(GMX_EXTERNAL_BLAS)
995 if(GMX_EXTERNAL_LAPACK)
997 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
998 else(GMX_LAPACK_USER)
999 set(LAPACK_FIND_QUIETLY ON)
1000 find_package(LAPACK)
1002 list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
1004 MESSAGE(STATUS "Using internal LAPACK library")
1005 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in" FORCE)
1007 endif(GMX_LAPACK_USER)
1008 endif(GMX_EXTERNAL_LAPACK)
1010 mark_as_advanced(GMX_EXTERNAL_LAPACK)
1011 mark_as_advanced(GMX_EXTERNAL_BLAS)
1013 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
1015 if(GMX_LOAD_PLUGINS)
1016 if(CYGWIN OR NOT WIN32)
1017 # Native Windows does not have, nor need dlopen
1018 # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
1019 include(gmxTestdlopen)
1020 gmx_test_dlopen(HAVE_DLOPEN)
1023 # so, should we use plug-ins?
1024 if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
1027 "Found the ability to use plug-ins when building shared libaries, "
1028 "so will compile to use plug-ins (e.g. to read VMD-supported file "
1031 if(NOT GMX_VMD_PLUGIN_PATH)
1034 set(GMX_USE_PLUGINS ON)
1035 list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
1036 set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
1040 endif(GMX_LOAD_PLUGINS)
1041 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
1043 if(EXISTS "${CMAKE_SOURCE_DIR}/admin/.isreposource")
1044 if(NOT CMAKE_CROSSCOMPILING)
1045 option(GMX_BUILD_MANPAGES "Build man pages" ON)
1047 message(STATUS "Building the man pages is not available when "
1048 "cross-compiling the developer version from git")
1051 #make sure source package contains all man pages
1052 if(NOT EXISTS "${CMAKE_SOURCE_DIR}/man/man1/ngmx.1")
1053 message(FATAL_ERROR "Man pages are missing from source package.")
1056 mark_as_advanced(GMX_BUILD_MANPAGES)
1058 # Math and thread libraries must often come after all others when linking...
1060 list(APPEND GMX_EXTRA_LIBRARIES m)
1064 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
1065 "Path to swindirect.h")
1066 include_directories(${COREWRAP_INCLUDE_DIR})
1069 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
1070 # these are set after everything else
1071 if (NOT DEFINED GROMACS_C_FLAGS_SET)
1072 set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
1074 set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING
1075 "Flags used by the compiler during all build types" FORCE)
1076 if (CMAKE_CXX_COMPILER_LOADED)
1077 set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING
1078 "Flags used by the compiler during all build types" FORCE)
1080 set(CMAKE_EXE_LINKER_FLAGS
1081 "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}"
1082 CACHE STRING "Linker flags for creating executables" FORCE)
1083 set(CMAKE_SHARED_LINKER_FLAGS
1084 "${GROMACS_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}"
1085 CACHE STRING "Linker flags for creating shared libraries" FORCE)
1086 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
1089 #Unset all OpenMP flags in case OpenMP was disabled either by the user
1090 #or because it was only partially detected (e.g. only for C but not C++ compiler)
1091 unset(OpenMP_C_FLAGS CACHE)
1092 unset(OpenMP_CXX_FLAGS CACHE)
1093 unset(OpenMP_LINKER_FLAGS CACHE)
1094 unset(OpenMP_SHARED_LINKER_FLAGS)
1096 ######################################
1097 # Output compiler and CFLAGS used
1098 ######################################
1099 execute_process(COMMAND ${CMAKE_C_COMPILER} --version RESULT_VARIABLE TMP_RESULT OUTPUT_VARIABLE CC_VERSION ERROR_VARIABLE CC_VERSION)
1100 #try executing just the compiler command if that failed...
1102 execute_process(COMMAND ${CMAKE_C_COMPILER} RESULT_VARIABLE TMP_RESULT OUTPUT_VARIABLE CC_VERSION ERROR_VARIABLE CC_VERSION)
1104 string(LENGTH "${CC_VERSION}" len)
1106 string(REGEX MATCH "[^\n]+" CC_VERSION "${CC_VERSION}")
1109 set(BUILD_COMPILER "@CMAKE_C_COMPILER@ @CMAKE_C_COMPILER_ID@ @CC_VERSION@")
1110 set(BUILD_CFLAGS "@CMAKE_C_FLAGS@")
1111 if(CMAKE_BUILD_TYPE STREQUAL "Debug")
1112 set(BUILD_CFLAGS "@BUILD_CFLAGS@ @CMAKE_C_FLAGS_DEBUG@")
1113 elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
1114 set(BUILD_CFLAGS "@BUILD_CFLAGS@ @CMAKE_C_FLAGS_RELEASE@")
1115 elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
1116 set(BUILD_CFLAGS "@BUILD_CFLAGS@ @CMAKE_C_FLAGS_MINSIZEREL@")
1117 elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
1118 set(BUILD_CFLAGS "@BUILD_CFLAGS@ @CMAKE_C_FLAGS_RELWITHDEBINFO@")
1122 ########################################################################
1123 # Specify install locations and which subdirectories to process #
1124 ########################################################################
1125 if (GMX_USE_RELATIVE_INSTALL_PATH)
1126 set(GMX_INSTALL_PREFIX "" CACHE STRING "Prefix gets appended to CMAKE_INSTALL_PREFIX. For cpack it sets the root folder of the archive.")
1127 mark_as_advanced(GMX_INSTALL_PREFIX)
1129 set(GMX_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
1132 if ( NOT DEFINED GMXLIB )
1135 set(LIB_INSTALL_DIR "${GMX_INSTALL_PREFIX}${GMXLIB}")
1136 set(BIN_INSTALL_DIR ${GMX_INSTALL_PREFIX}bin)
1137 set(DATA_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/gromacs)
1138 set(MAN_INSTALL_DIR ${GMX_INSTALL_PREFIX}share/man)
1139 set(INCL_INSTALL_DIR ${GMX_INSTALL_PREFIX}include)
1141 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
1143 ##################################################################
1144 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
1145 ##################################################################
1146 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
1147 set(CMAKE_SKIP_BUILD_RPATH FALSE)
1148 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
1149 set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
1150 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
1153 #COPYING file: Only necessary for binary distributions.
1154 #Simpler to always install.
1155 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
1157 add_subdirectory(share)
1158 add_subdirectory(include)
1159 add_subdirectory(src)
1160 add_subdirectory(scripts)
1162 #######################
1164 #######################
1166 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
1167 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
1169 ###########################
1170 ADD_CUSTOM_TARGET(uninstall
1171 "${CMAKE_COMMAND}" -P
1172 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
1173 ###########################
1176 ########################################################################
1178 ########################################################################
1181 mark_as_advanced(BUILD_TESTING)
1184 add_subdirectory(tests)