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
7 mark_as_advanced(DART_ROOT)
9 # PROJECT_VERSION should have the following structure:
10 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
12 # The "-dev" suffix is important to keep because it makes possible to distinguish
13 # between a build from official release and a build from git release branch on a
14 # machine with no git.
16 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
17 set(PROJECT_VERSION "4.6-dev")
18 set(CUSTOM_VERSION_STRING ""
19 CACHE STRING "Custom version string (if empty, use hard-coded default)")
20 mark_as_advanced(CUSTOM_VERSION_STRING)
21 if (CUSTOM_VERSION_STRING)
22 set(PROJECT_VERSION ${CUSTOM_VERSION_STRING})
23 endif (CUSTOM_VERSION_STRING)
25 # It is a bit irritating, but this has to be set separately for now!
26 SET(CPACK_PACKAGE_VERSION_MAJOR "4")
27 SET(CPACK_PACKAGE_VERSION_MINOR "6")
28 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
31 # Cmake modules/macros are in a subdirectory to keep this file cleaner
32 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
34 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
35 set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
38 if(NOT CMAKE_BUILD_TYPE)
39 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
40 endif(NOT CMAKE_BUILD_TYPE)
44 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
45 set(CPACK_PACKAGE_VENDOR "gromacs.org")
46 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Gromacs - a toolkit for high-performance molecular simulation")
47 set(CPACK_SET_DESTDIR "ON")
48 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
49 set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/admin/InstallWelcome.txt")
50 # Its GPL/LGPL, so they do not have to agree to a license for mere usage, but some installers require this...
51 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/admin/InstallLicense.txt")
52 set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/admin/InstallInfo.txt")
54 #must come after all cpack settings!
57 ########################################################################
58 # Check and warn if cache generated on a different host is being reused
59 ########################################################################
61 execute_process(COMMAND hostname
62 OUTPUT_VARIABLE TMP_HOSTNAME
63 OUTPUT_STRIP_TRAILING_WHITESPACE)
64 if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
66 The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
67 is being reused! This could lead to inconsitencies; therefore, it is
68 recommended to regenerate the cache!")
70 set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
71 "Hostname of the machine where the cache was generated.")
74 ########################################################################
75 # Fix stupid flags on Windows
76 ########################################################################
77 SET(SHARED_LIBS_DEFAULT ON)
78 IF( (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "NMake") AND MSVC )
79 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
80 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
81 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
82 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
83 SET(SHARED_LIBS_DEFAULT OFF)
86 IF(CMAKE_GENERATOR MATCHES "NMake" AND CMAKE_C_COMPILER_ID MATCHES "Intel")
87 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
88 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
89 STRING(REPLACE /GZ /RTC1 CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
90 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
91 SET(SHARED_LIBS_DEFAULT OFF)
94 set(GMX_EXTRA_LIBRARIES)
96 ########################################################################
97 # User input options #
98 ########################################################################
99 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" OFF)
100 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
101 option(GMX_THREAD_MPI "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
102 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
103 mark_as_advanced(GMX_SOFTWARE_INVSQRT)
104 option(GMX_POWERPC_INVSQRT "Use PowerPC hardware 1/sqrt" OFF)
105 mark_as_advanced(GMX_POWERPC_INVSQRT)
106 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
107 mark_as_advanced(GMX_FAHCORE)
108 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library (rerun cmake after changing to see relevant options)" OFF)
109 set(GMX_ACCELERATION "auto"
110 CACHE STRING "Accelerated kernels. Pick one of: auto, none, SSE, BlueGene, Power6, ia64, altivec, fortran")
112 set(GMX_FFT_LIBRARY "fftw3"
113 CACHE STRING "FFT library choices: fftw3,mkl,fftpack[built-in]")
114 option(GMX_DISABLE_FFTW_MEASURE
115 "Do not optimize FFTW setups (not needed with SSE)" OFF)
116 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
117 set(GMX_QMMM_PROGRAM "none"
118 CACHE STRING "QM package choices: none,gaussian,mopac,gamess,orca")
119 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
120 mark_as_advanced(GMX_BROKEN_CALLOC)
121 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI, Windows)" ${SHARED_LIBS_DEFAULT})
122 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
123 mark_as_advanced(GMX_MPI_IN_PLACE)
124 option(GMX_LOAD_PLUGINS "Compile with plugin support, needed to read VMD supported file formats" ON)
125 mark_as_advanced(GMX_LOAD_PLUGINS)
128 option(GMX_IA32_ASM "Add SSE assembly files for IA32" OFF)
129 mark_as_advanced(GMX_IA32_ASM)
130 option(GMX_X86_64_ASM "Add SSE assembly files for X86_64" OFF)
131 mark_as_advanced(GMX_X86_64_ASM)
133 option(GMX_OPENMP "Enable OpenMP-based mutithreading. " ON)
135 option(USE_VERSION_H "Generate development version string/information" ON)
136 mark_as_advanced(USE_VERSION_H)
138 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)
140 if(UNIX AND NOT APPLE)
141 option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer \".a\" static archives (NOTE: this is enabled only for UNIX (excluding APPLE) platforms but it might not always work!" OFF)
142 mark_as_advanced(GMX_PREFER_STATIC_LIBS)
146 ######################################################################
148 # these need ot be done early (before further tests).
149 #####################################################################
151 # cmake/Check{C,CXX}CompilerFlag.cmake are lifted from CMake git next
152 # branch (proposed for v2.8.9) to be able to detect invalid options
153 # with the Intel Compilers.
154 # Remove these files from the source tree when a CMake version that
155 # includes the features in question becomes required.
156 include(CheckCCompilerFlag)
157 include(CheckCXXCompilerFlag)
163 ########################################################################
164 # Set up binary and library suffixing
165 ########################################################################
166 set(GMX_BINARY_SUFFIX "" CACHE STRING "Suffix for GROMACS binaries (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
167 set(GMX_LIBS_SUFFIX ""
168 CACHE STRING "Suffix for GROMACS libs (default: _d for double, _mpi for MPI, _mpi_d for MPI and double).")
169 if (GMX_DEFAULT_SUFFIX)
170 set(GMX_BINARY_SUFFIX "")
171 set(GMX_LIBS_SUFFIX "")
173 set(GMX_BINARY_SUFFIX "_mpi")
174 set(GMX_LIBS_SUFFIX "_mpi")
177 set (GMX_BINARY_SUFFIX "${GMX_BINARY_SUFFIX}_d")
178 set (GMX_LIBS_SUFFIX "${GMX_LIBS_SUFFIX}_d")
181 set (GMX_BINARY_SUFFIX "-gpu")
182 set (GMX_LIBS_SUFFIX "_gpu")
184 mark_as_advanced(FORCE GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
185 if (NOT SUFFIX_QUIETLY)
186 message(STATUS "Using default binary suffix: \"${GMX_BINARY_SUFFIX}\"")
187 message(STATUS "Using default library suffix: \"${GMX_LIBS_SUFFIX}\"")
188 endif (NOT SUFFIX_QUIETLY)
189 else(GMX_DEFAULT_SUFFIX)
190 mark_as_advanced(CLEAR GMX_BINARY_SUFFIX GMX_LIBS_SUFFIX)
191 if (NOT SUFFIX_QUIETLY)
192 message(STATUS "Using manually set binary suffix: \"${GMX_BINARY_SUFFIX}\"")
193 message(STATUS "Using manually set library suffix: \"${GMX_LIBS_SUFFIX}\"")
194 endif (NOT SUFFIX_QUIETLY)
195 endif(GMX_DEFAULT_SUFFIX)
196 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
200 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_DOUBLE")
202 if(GMX_SOFTWARE_INVSQRT)
203 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_SOFTWARE_INVSQRT")
204 endif(GMX_SOFTWARE_INVSQRT)
205 if(GMX_POWERPC_INVSQRT)
206 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_POWERPC_INVSQRT")
207 endif(GMX_POWERPC_INVSQRT)
209 ########################################################################
210 #Process MPI settings
211 ########################################################################
212 include(gmxManageMPI)
214 #######################################################################
215 # Check for options incompatible with OpenMM build #
216 #######################################################################
218 # we'll use the built-in fft to avoid unnecessary dependencies
219 string(TOUPPER ${GMX_FFT_LIBRARY} GMX_FFT_LIBRARY)
220 if(NOT ${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
221 message(STATUS "No external FFT libraries needed for the OpenMM build, switching to fftpack!")
222 set(GMX_FFT_LIBRARY "fftpack" CACHE STRING
223 "No external FFT libraries needed for the OpenMM build, switching to fftpack!" FORCE)
226 message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
229 message(STATUS "Thread-MPI not compatible with OpenMM, disabled!")
230 set(GMX_THREAD_MPI OFF CACHE BOOL
231 "Thread-MPI not compatible with OpenMM build, disabled!" FORCE)
232 endif(GMX_THREAD_MPI)
234 message(STATUS "OpenMP multithreading not compatible with OpenMM, disabled")
235 set(GMX_OPENMP OFF CACHE BOOL
236 "OpenMP multithreading not compatible with OpenMM, disabled!" FORCE)
238 if(GMX_SOFTWARE_INVSQRT)
239 set(GMX_SOFTWARE_INVSQRT OFF CACHE STRING
240 "The OpenMM build does not need GROMACS software 1/sqrt!" FORCE)
241 endif(GMX_SOFTWARE_INVSQRT)
242 string(TOUPPER ${GMX_ACCELERATION} GMX_ACCELERATION)
243 if(NOT GMX_ACCELERATION STREQUAL "NONE")
244 message(STATUS "Switching off CPU-based acceleration, the OpenMM build does not support/need any!")
245 set(GMX_ACCELERATION "none" CACHE STRING
246 "Switching off CPU-based acceleration, the OpenMM build does not support/need any!" FORCE)
249 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
252 message(FATAL_ERROR "The OpenMM-build does not support double precision calculations!")
254 # mark as advanced the unused variables
255 mark_as_advanced(FORCE GMX_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
256 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
258 mark_as_advanced(CLEAR GMX_ACCELERATION GMX_MPI GMX_FFT_LIBRARY
259 GMX_QMMM_PROGRAM GMX_THREAD_MPI GMX_DOUBLE)
263 ########################################################################
264 # Basic system tests (standard libraries, headers, functions, types) #
265 ########################################################################
266 include(CheckIncludeFiles)
267 check_include_files(string.h HAVE_STRING_H)
268 check_include_files(math.h HAVE_MATH_H)
269 check_include_files(limits.h HAVE_LIMITS_H)
270 check_include_files(memory.h HAVE_MEMORY_H)
271 check_include_files(unistd.h HAVE_UNISTD_H)
272 check_include_files(direct.h HAVE_DIRECT_H)
273 check_include_files(pwd.h HAVE_PWD_H)
274 check_include_files(stdint.h HAVE_STDINT_H)
275 check_include_files(stdlib.h HAVE_STDLIB_H)
276 check_include_files(pthread.h HAVE_PTHREAD_H)
277 check_include_files(dirent.h HAVE_DIRENT_H)
278 check_include_files(inttypes.h HAVE_INTTYPES_H)
279 check_include_files(regex.h HAVE_REGEX_H)
280 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
281 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
282 check_include_files(sys/time.h HAVE_SYS_TIME_H)
283 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
284 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
286 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
287 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
288 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
289 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
290 check_include_files(io.h HAVE_IO_H)
293 include(CheckFunctionExists)
294 check_function_exists(strcasecmp HAVE_STRCASECMP)
295 check_function_exists(strdup HAVE_STRDUP)
296 check_function_exists(vprintf HAVE_VPRINTF)
297 check_function_exists(memcmp HAVE_MEMCMP)
298 check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
299 check_function_exists(memalign HAVE_MEMALIGN)
300 check_function_exists(_aligned_malloc HAVE__ALIGNED_MALLOC)
301 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
302 check_function_exists(isnan HAVE_ISNAN)
303 check_function_exists(_isnan HAVE__ISNAN)
304 check_function_exists(fsync HAVE_FSYNC)
305 check_function_exists(_fileno HAVE__FILENO)
306 check_function_exists(fileno HAVE_FILENO)
307 check_function_exists(_commit HAVE__COMMIT)
308 check_function_exists(lstat HAVE_LSTAT)
309 check_function_exists(sigaction HAVE_SIGACTION)
311 include(CheckLibraryExists)
312 check_library_exists(m sqrt "" HAVE_LIBM)
313 check_library_exists(m cbrt "" HAVE_CBRT)
316 include(CheckTypeSize)
318 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
319 check_type_size("int" SIZEOF_INT)
320 check_type_size("long int" SIZEOF_LONG_INT)
321 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
322 check_type_size("off_t" SIZEOF_OFF_T)
323 check_type_size("void *" SIZEOF_VOIDP)
325 if (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
327 else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
328 set(GMX_64_BIT FALSE)
329 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
331 # Check for some basic types that we *need*, so set these to int if they are not present
332 check_type_size(uid_t uid_t)
339 check_type_size(gid_t gid_t)
346 check_type_size(size_t size_t)
353 check_type_size(off_t off_t)
360 include(TestBigEndian)
361 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
366 ########################################################################
367 # Find external packages #
368 ########################################################################
369 if(UNIX AND NOT APPLE)
370 if(GMX_PREFER_STATIC_LIBS)
371 SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
372 if(BUILD_SHARED_LIBS)
373 message(WARNING "Static libraries requested, the GROMACS libraries will also be build static (BUILD_SHARED_LIBS=OFF)")
374 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Enable shared libraries (can be problematic with MPI, Windows)" FORCE)
379 option(GMX_XML "Use libxml2 to parse xml files" ON)
381 find_package(LibXml2)
384 include_directories(${LIBXML2_INCLUDE_DIR})
385 set(PKG_XML libxml-2.0)
386 set(XML_LIBRARIES ${LIBXML2_LIBRARIES})
391 option(GMX_GSL "Add support for gsl" OFF)
396 include_directories(${GSL_INCLUDE_DIR})
402 option(GMX_X11 "Use X window system" OFF)
405 # X11 includes/libraries are only set in the ngmx subdirectory!
412 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
414 set(THREAD_MPI_LIB thread_mpi)
416 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
417 endif(GMX_THREAD_MPI)
420 set(CUDA_BUILD_EMULATION OFF)
421 find_package(CUDA 3.1 REQUIRED)
422 add_definitions(-DGMX_OPENMM)
423 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
424 set(CUDA_VERBOSE_BUILD ON)
430 find_package(OpenMP REQUIRED)
431 set(GROMACS_C_FLAGS "${OpenMP_C_FLAGS} ${GROMACS_C_FLAGS}")
432 set(GROMACS_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${GROMACS_CXX_FLAGS}")
433 add_definitions(-DGMX_OPENMP)
437 find_library(ACCELERATE_FRAMEWORK Accelerate)
438 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
445 if(WIN32 AND NOT CYGWIN)
446 set(GMX_NATIVE_WINDOWS 1)
449 # only bother with finding git and using version.h if the source is a git repo
450 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
452 # We need at least git v1.5.1 be able to parse git's date output. If not
453 # found or the version is too small, we can't generate version information.
456 # Find out the git version
457 if(GIT_FOUND AND NOT GIT_VERSION)
458 execute_process(COMMAND ${GIT_EXECUTABLE} "--version"
459 OUTPUT_VARIABLE _exec_out
460 OUTPUT_STRIP_TRAILING_WHITESPACE)
461 string(REGEX REPLACE "git version (.*)" "\\1" GIT_VERSION ${_exec_out})
462 set(GIT_VERSION ${GIT_VERSION} CACHE STRING "Git version")
463 mark_as_advanced(GIT_VERSION)
466 if(NOT GIT_FOUND OR GIT_VERSION VERSION_LESS "1.5.1")
467 message("No compatible git version found, won't be able to generate proper development version information.")
468 set(USE_VERSION_H OFF)
472 set(USE_VERSION_H OFF)
475 ########################################################################
476 # Generate development version info for cache
477 ########################################################################
478 # set(GEN_VERSION_INFO_INTERNAL "ON")
479 # include(gmxGenerateVersionString)
481 ########################################################################
482 # Our own GROMACS tests
483 ########################################################################
485 add_definitions( -DHAVE_CONFIG_H )
486 include_directories(${CMAKE_BINARY_DIR}/src)
487 include_directories(${CMAKE_BINARY_DIR}/include)
488 include_directories(${CMAKE_SOURCE_DIR}/include)
490 include(gmxCheckBuildUserTime)
491 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
493 include(gmxTestFloatFormat)
494 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
495 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
496 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
498 include(gmxTestLargeFiles)
499 gmx_test_large_files(GMX_LARGEFILES)
500 check_function_exists(fseeko HAVE_FSEEKO)
502 include(gmxTestSignal)
503 gmx_test_sigusr1(HAVE_SIGUSR1)
505 include(gmxTestInline)
506 gmx_test_inline(INLINE_KEYWORD)
508 include(gmxTestRestrict)
509 gmx_test_inline(RESTRICT_KEYWORD)
511 include(gmxTestPipes)
512 gmx_test_pipes(HAVE_PIPES)
514 include(gmxTestIsfinite)
515 gmx_test_isfinite(HAVE_ISFINITE)
516 gmx_test__isfinite(HAVE__ISFINITE)
517 gmx_test__finite(HAVE__FINITE)
519 include(gmxTestInlineASM)
520 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
521 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
523 # turn on SSE if supported with reasonable defaults.
524 if (${GMX_ACCELERATION} STREQUAL "auto" AND NOT GMX_OPENMM)
525 if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86|x64|x86_64|AMD64|amd64)" OR CYGWIN)
527 set(GMX_ACCELERATION "SSE" CACHE STRING "Accelerated kernels. Pick one of: auto, none, SSE, BlueGene, Power6, ia64, altivec, fortran" FORCE)
529 # Determine the assembler/compiler to use
531 set(GMX_ACCELERATION "none" CACHE STRING "Accelerated kernels. Pick one of: auto, none, SSE, BlueGene, Power6, ia64, altivec, fortran" FORCE)
533 endif (${GMX_ACCELERATION} STREQUAL "auto" AND NOT GMX_OPENMM)
536 gmx_test_xdr(GMX_SYSTEM_XDR)
537 if(NOT GMX_SYSTEM_XDR)
538 set(GMX_INTERNAL_XDR 1)
539 set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_INTERNAL_XDR")
540 endif(NOT GMX_SYSTEM_XDR)
542 # Process nonbonded accelerated kernels settings
543 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
544 if(${GMX_ACCELERATION} STREQUAL "NONE")
546 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
549 set(GMX_X86_64_ASM ON CACHE BOOL "Add SSE assembly files for x86_64" FORCE)
551 set(GMX_IA32_ASM ON CACHE BOOL "Add SSE assembly files for i386" FORCE)
554 if(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES NMake )
555 option(GMX_ASM_USEASM_NASM "Use Nasm for assembly instead of compiler (necessary on windows)" ON)
557 option(GMX_ASM_USEASM_NASM "Use Nasm for assembly instead of compiler (necessary on windows)" OFF)
559 mark_as_advanced(GMX_ASM_USEASM_NASM)
562 # for 32-bit compiles, we might need to turn on sse
563 CHECK_C_COMPILER_FLAG("-msse2" XFLAGS_SSE)
565 set(GROMACS_C_FLAGS "-msse2 ${GROMACS_C_FLAGS}")
567 CHECK_CXX_COMPILER_FLAG("-msse2" XXFLAGS_SSE)
569 set(GROMACS_CXX_FLAGS "-msse2 ${GROMACS_CXX_FLAGS}")
571 endif (NOT GMX_64_BIT)
579 elseif(GMX_X86_64_ASM)
581 set(GMX_X86_64_SSE2 1)
583 set(GMX_X86_64_SSE 1)
587 # if(HAVE_PMMINTRIN_H)
589 # endif(HAVE_PMMINTRIN_H)
590 # if(HAVE_SMMINTRIN_H)
592 # endif(HAVE_SMMINTRIN_H)
594 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
596 #these are switch on by default sometimes
598 set(GMX_GMX_X86_64_ASM 0)
599 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
600 # GMX_ACCELERATION=BlueGene should be set in the Toolchain-BlueGene?-???.cmake file
601 message(STATUS "Configuring for BlueGene")
603 if (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
604 set(SHARED_LIBS_DEFAULT OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
605 set(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared libraries not compatible with BlueGene/L, disabled!" FORCE)
606 endif (${CMAKE_SYSTEM_NAME} STREQUAL "BlueGeneL")
607 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on BlueGene" FORCE)
608 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on BlueGene" FORCE)
609 set(GMX_X11 OFF CACHE BOOL "X11 not compatible with BlueGene, disabled!" FORCE)
610 set(GMX_THREAD_MPI OFF CACHE BOOL "Thread-MPI not compatible with BlueGene, disabled!" FORCE)
611 set(GMX_MPI ON CACHE BOOL "Use MPI on BlueGene" FORCE)
612 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
614 set(GMX_SOFTWARE_INVSQRT OFF CACHE BOOL "Do not use software reciprocal square root on Power6" FORCE)
615 set(GMX_POWERPC_INVSQRT ON CACHE BOOL "Use hardware reciprocal square root on Power6" FORCE)
616 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
618 set(DISABLE_WATERWATER_NLIST 1)
619 set(DISABLE_WATER_NLIST 1)
620 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
621 check_include_files(altivec.h HAVE_ALTIVEC_H)
623 set(GMX_PPC_ALTIVEC 1)
624 endif(HAVE_ALTIVEC_H)
625 else(${GMX_ACCELERATION} STREQUAL "NONE")
626 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of auto, none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
627 endif(${GMX_ACCELERATION} STREQUAL "NONE")
629 if(GMX_FORTRAN OR GMX_POWER6)
631 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).")
632 endif(GMX_THREAD_MPI)
633 enable_language(Fortran)
634 include(FortranCInterface)
635 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
636 if(extra_under_score)
638 endif(extra_under_score)
640 set(prefix "${prefix} ##")
643 set(suffix "## ${suffix}")
645 set(extrasuffix "${suffix}${extrasuffix}")
649 # Don't know if this is needed, but it can't hurt
650 set(extrasuffix "## ${extrasuffix}")
655 set(F77_FUNCDEF "${prefix} NAME ${suffix}")
656 set(F77_FUNCDEF_ "${prefix} NAME ${extrasuffix}")
658 set(F77_FUNCDEF "${prefix} name ${suffix}")
659 set(F77_FUNCDEF_ "${prefix} name ${extrasuffix}")
661 else(GMX_FORTRAN OR GMX_POWER6)
662 set(F77_FUNCDEF "name ## _")
663 set(F77_FUNCDEF_ "name ## _")
664 endif(GMX_FORTRAN OR GMX_POWER6)
666 # Process QM/MM Settings
667 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
668 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
669 set(GMX_QMMM_GAUSSIAN 1)
670 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
671 set(GMX_QMMM_MOPAC 1)
672 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
673 set(GMX_QMMM_GAMESS 1)
674 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
676 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
678 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
679 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, Orca, None")
680 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
682 # Process FFT library settings - if not OpenMM build
683 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
686 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
688 find_package(FFTW 3 COMPONENTS fftw)
690 find_package(FFTW 3 COMPONENTS fftwf)
693 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)!")
694 endif(NOT FFTW_FOUND)
695 include_directories(${FFTW_INCLUDE_DIRS})
696 set(FFT_LIBRARIES ${FFTW_LIBRARIES})
697 set(PKG_FFT "${FFTW_PKG}")
701 if (${GMX_ACCELERATION} STREQUAL "SSE" AND NOT FFTW_HAVE_SSE)
702 message(WARNING "The fftw library found is compiled without SSE support, which makes it slow. Consider recompiling it or contact your admin")
703 endif (${GMX_ACCELERATION} STREQUAL "SSE" AND NOT FFTW_HAVE_SSE)
705 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
706 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
707 find_package(MKL REQUIRED)
708 include_directories(${MKL_INCLUDE_DIR})
709 set(FFT_LIBRARIES ${MKL_LIBRARIES})
710 set(PKG_FFT_LIBS ${MKL_LIBRARIES})
715 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
716 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
717 # set(GMX_FFT_ACML 1)
718 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
719 MESSAGE(STATUS "Using internal FFT library - fftpack")
720 set(GMX_FFT_FFTPACK 1)
721 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
722 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, mkl, fftpack")
723 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
725 # MKL has BLAS/LAPACK routines
726 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
727 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
728 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
729 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
730 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external BLAS instead of built-in")
731 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
732 if(GMX_EXTERNAL_BLAS)
733 #FindBLAS needs Fortran
734 enable_language(Fortran)
736 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_BLAS_USER})
738 find_package(BLAS REQUIRED)
739 list(APPEND GMX_EXTRA_LIBRARIES ${BLAS_LIBRARIES})
741 endif(GMX_EXTERNAL_BLAS)
742 if(GMX_EXTERNAL_LAPACK)
743 #FindLAPACK needs Fortran
744 enable_language(Fortran)
746 list(APPEND GMX_EXTRA_LIBRARIES ${GMX_LAPACK_USER})
747 else(GMX_LAPACK_USER)
748 find_package(LAPACK REQUIRED)
749 list(APPEND GMX_EXTRA_LIBRARIES ${LAPACK_LIBRARIES})
750 endif(GMX_LAPACK_USER)
751 endif(GMX_EXTERNAL_LAPACK)
752 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
753 mark_as_advanced(GMX_EXTERNAL_LAPACK)
754 mark_as_advanced(GMX_EXTERNAL_BLAS)
756 set(GMX_USE_PLUGINS OFF CACHE INTERNAL "Whether GROMACS will really try to compile support for VMD plugins")
757 set(GMX_VMD_PLUGIN_PATH)
758 mark_as_advanced(GMX_VMD_PLUGIN_PATH)
761 if(CYGWIN OR NOT WIN32)
762 # Native Windows does not have, nor need dlopen
763 # Note that WIN32 is set with Cygwin, but Cygwin needs dlopen to use plug-ins
764 include(gmxTestdlopen)
765 gmx_test_dlopen(HAVE_DLOPEN)
770 # Test for unsuitable versions of VMD
772 if(VMD_FOUND AND NOT GMX_VMD_PLUGIN_PATH)
773 message(STATUS "Checking for suitable VMD version")
774 exec_program(${VMD_EXECUTABLE}
776 OUTPUT_VARIABLE VMD_HELP
777 RETURN_VALUE VMD_EXEC_RETURN)
779 if(VMD_EXEC_RETURN EQUAL 0)
780 # This is the accepted idiom for subexpression matching, unfortunately
781 string(REGEX REPLACE ".*VMD for .*, version ([0-9]+\\.[0-9]*\\.?[0-9]*).*" "\\1" VMD_VERSION ${VMD_HELP})
782 string(REGEX REPLACE ".*VMD for (.*), version .*" "\\1" VMD_ARCH ${VMD_HELP})
784 if(VMD_VERSION VERSION_LESS "1.8")
785 MESSAGE(WARNING "Found VMD version ${VMD_VERSION}, but GROMACS needs at least 1.8")
786 unset(VMD_EXECUTABLE)
789 message(STATUS "VMD version ${VMD_VERSION} is suitable")
790 if(DEFINED ENV{VMDDIR})
791 # This permits GROMACS to avoid hard-coding a fall-back
792 # path that it can tell right now would be useless.
793 set(GMX_VMD_PLUGIN_PATH "$ENV{VMDDIR}/plugins/${VMD_ARCH}/molfile" CACHE PATH "Path to VMD plugins for molfile I/O")
795 set(GMX_VMD_PLUGIN_PATH "/usr/local/lib/vmd/plugins/*/molfile" CACHE PATH "Path to VMD plugins for molfile I/O")
806 # so, should we use plug-ins?
807 if((WIN32 AND NOT CYGWIN) OR (HAVE_DLOPEN AND BUILD_SHARED_LIBS))
809 MESSAGE(STATUS "Found the ability to use plug-ins when building shared libaries, so will compile to use plug-ins (e.g. to read VMD-supported file formats).")
810 endif(NOT VMD_QUIETLY)
811 set(GMX_USE_PLUGINS ON)
812 list(APPEND GMX_EXTRA_LIBRARIES ${CMAKE_DL_LIBS}) # magic cross-platform pre-set variable for dlopen library
813 set(PKG_DL_LIBS "-l${CMAKE_DL_LIBS}")
817 endif(GMX_LOAD_PLUGINS)
818 set(VMD_QUIETLY TRUE CACHE INTERNAL "")
820 # Math and thread libraries must often come after all others when linking...
822 list(APPEND GMX_EXTRA_LIBRARIES m)
826 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
827 "Path to swindirect.h")
828 include_directories(${COREWRAP_INCLUDE_DIR})
831 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
832 # these are set after everything else
833 if (NOT DEFINED GROMACS_C_FLAGS_SET)
834 set(GROMACS_C_FLAGS_SET true CACHE INTERNAL "Whether to reset the C flags"
836 set(CMAKE_C_FLAGS "${GROMACS_C_FLAGS} ${CMAKE_C_FLAGS}" CACHE STRING
837 "Flags used by the compiler during all build types" FORCE)
838 set(CMAKE_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" CACHE STRING
839 "Flags used by the compiler during all build types" FORCE)
840 set(CMAKE_EXE_LINKER_FLAGS
841 "${GROMACS_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}"
842 CACHE STRING "Linker flags" FORCE)
843 endif (NOT DEFINED GROMACS_C_FLAGS_SET)
845 ########################################################################
846 # Specify install locations and which subdirectories to process #
847 ########################################################################
848 if ( DEFINED GMXLIB )
849 set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${GMXLIB}")
851 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
853 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
854 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
855 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
856 set(INCL_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
858 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
860 ##################################################################
861 # Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
862 ##################################################################
863 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
864 set(CMAKE_SKIP_BUILD_RPATH FALSE)
865 set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
866 set(CMAKE_INSTALL_RPATH "${LIB_INSTALL_DIR}")
867 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
870 add_subdirectory(share)
871 add_subdirectory(include)
872 add_subdirectory(man)
873 add_subdirectory(src)
874 add_subdirectory(scripts)
876 #######################
878 #######################
880 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
881 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
883 ###########################
884 ADD_CUSTOM_TARGET(uninstall
885 "${CMAKE_COMMAND}" -P
886 "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
887 ###########################
890 ########################################################################
892 ########################################################################
895 mark_as_advanced(BUILD_TESTING)
898 add_subdirectory(tests)