1 cmake_minimum_required(VERSION 2.6)
5 # PROJECT_VERSION should have the following structure:
6 # VERSION[-dev-SUFFIX] where the VERSION can have any form and the suffix
7 set(PROJECT_VERSION "4.0.99-dev-20100315"
8 CACHE STRING "Gromacs version string")
10 # Cmake modules/macros are in a subdirectory to keep this file cleaner
11 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
13 ########################################################################
14 # User input options #
15 ########################################################################
16 option(GMX_DOUBLE "Use double precision" OFF)
17 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
18 option(GMX_THREADS "Build a parallel (threaded-based) version of GROMACS: (doesn't work yet!)" ON)
19 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
20 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
21 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library" OFF)
22 set(GMX_ACCELERATION "none"
23 CACHE STRING "Accelerated kernels. Pick one of: SSE, BlueGene, Power6, ia64, altivec")
25 set(GMX_FFT_LIBRARY "fftw3"
26 CACHE STRING "FFT library choices: fftw3,fftw2,mkl,fftpack[built-in]")
27 option(GMX_DISABLE_FFTW_MEASURE
28 "Do not optimize FFTW setups (not needed with SSE)" OFF)
29 set(GMX_QMMM_PROGRAM "none"
30 CACHE STRING "QM package choices: none,gaussian,mopac,gamess")
31 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
32 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI)" OFF)
33 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
34 option(GMX_DLOPEN "Compile with dlopen, needed to read VMD supported file formats" ON)
35 mark_as_advanced(GMX_MPI_IN_PLACE)
39 option(GMX_IA32_ASM "Add SSE assembly files for IA32" OFF)
40 option(GMX_X86_64_ASM "Add SSE assembly files for X86_64" OFF)
41 option(USE_VERSION_H "Generate development version string/information" ON)
43 #######################################################################
44 # Check for options incompatible with OpenMM build #
45 #######################################################################
47 cmake_minimum_required(VERSION 2.6.4)
48 # we'll use the built-in fft to avoid unnecessary dependencies
49 set (GMX_FFT_LIBRARY "fftpack")
51 message(FATAL_ERROR "The OpenMM build is not compatible with MPI!")
54 message(STATUS "Threads not compatible with OpenMM build, disabled")
57 if(GMX_SOFTWARE_INVSQRT)
58 set(GMX_SOFTWARE_INVSQRT OFF)
59 endif(GMX_SOFTWARE_INVSQRT)
60 if(NOT GMX_ACCELERATION MATCHES "none")
61 message(WARNING "The OpenMM build does not support other acceleration modes!")
62 set(GMX_ACCELERATION "none")
65 message(FATAL_ERROR "The OpenMM build does not support FAH build!")
70 ########################################################################
71 # Fix stupid flags on MSVC
72 ########################################################################
73 IF(CMAKE_GENERATOR MATCHES "Visual Studio")
74 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
75 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
76 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
77 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
78 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
80 set(GMX_EXTRA_LIBRARIES)
82 ########################################################################
84 ########################################################################
87 #message(FATAL_ERROR "Thread-based parallelization conflicts with MPI.")
88 set(GMX_THREADS OFF CACHE BOOL
89 "Thread-based parallelization conflicts with MPI." FORCE)
93 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
94 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
96 include_directories(${MPI_INCLUDE_PATH})
97 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
98 add_definitions( -DMPI ) #for FAHCORE
99 include(gmxTestMPI_IN_PLACE)
100 if (GMX_MPI_IN_PLACE)
101 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
102 endif (GMX_MPI_IN_PLACE)
104 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
106 include(gmxTestCatamount)
107 gmx_test_catamount(GMX_CRAY_XT3)
115 ########################################################################
116 # Basic system tests (standard libraries, headers, functions, types) #
117 ########################################################################
118 include(CheckIncludeFiles)
119 check_include_files(string.h HAVE_STRING_H)
120 check_include_files(limits.h HAVE_LIMITS_H)
121 check_include_files(memory.h HAVE_MEMORY_H)
122 check_include_files(unistd.h HAVE_UNISTD_H)
123 check_include_files(pwd.h HAVE_PWD_H)
124 check_include_files(stdint.h HAVE_STDINT_H)
125 check_include_files(stdlib.h HAVE_STDLIB_H)
126 check_include_files(pthread.h HAVE_PTHREAD_H)
127 check_include_files(dirent.h HAVE_DIRENT_H)
128 check_include_files(inttypes.h HAVE_INTTYPES_H)
129 check_include_files(regex.h HAVE_REGEX_H)
130 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
131 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
132 check_include_files(sys/time.h HAVE_SYS_TIME_H)
133 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
134 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
136 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
137 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
138 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
139 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
141 include(CheckFunctionExists)
142 check_function_exists(strcasecmp HAVE_STRCASECMP)
143 check_function_exists(strdup HAVE_STRDUP)
144 check_function_exists(vprintf HAVE_VPRINTF)
145 check_function_exists(memcmp HAVE_MEMCMP)
146 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
147 check_function_exists(isnan HAVE_ISNAN)
148 check_function_exists(_isnan HAVE__ISNAN)
149 check_function_exists(isfinite HAVE_ISFINITE)
150 check_function_exists(_isfinite HAVE__ISFINITE)
151 check_function_exists(fsync HAVE_FSYNC)
152 check_function_exists(fileno HAVE_FILENO)
153 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
155 include(CheckLibraryExists)
156 check_library_exists(m sqrt "" HAVE_LIBM)
158 include(CheckTypeSize)
159 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
160 check_type_size("int" SIZEOF_INT)
161 check_type_size("long int" SIZEOF_LONG_INT)
162 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
163 check_type_size("off_t" SIZEOF_OFF_T)
164 check_type_size("void *" SIZEOF_VOIDP)
166 # Check for some basic types that we *need*, so set these to int if they are not present
167 check_type_size(uid_t uid_t)
174 check_type_size(gid_t gid_t)
181 check_type_size(size_t size_t)
188 check_type_size(off_t off_t)
195 include(TestBigEndian)
196 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
200 ########################################################################
201 # Find external packages #
202 ########################################################################
204 find_package(LibXml2)
206 include_directories(${LIBXML2_INCLUDE_DIR})
207 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
212 # X11 includes/libraries are only set in the ngmx subdirectory!
219 set(THREAD_MPI_LIB thread_mpi)
221 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
222 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
223 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
228 set(CUDA_BUILD_EMULATION OFF)
229 find_package(CUDA 2.3 REQUIRED)
230 add_definitions(-DGMX_OPENMM)
231 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
232 set(CUDA_VERBOSE_BUILD ON)
238 find_library(ACCELERATE_FRAMEWORK Accelerate)
239 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
242 # only bother with finding git and using version.h if the source is a git repo
243 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
245 # We need at least git v1.5.1 be able to parse git's date output. If not
246 # fund or the version is too small, we can't generate version information.
247 find_package(Git 1.5.1)
248 if(NOT Git_FOUND OR Git_VERSION VERSION_LESS "1.5.1")
249 message("No compatible git version found, won't be able to generate proper development version information.")
253 set(USE_VERSION_H OFF)
256 ########################################################################
257 # Generate development version info for cache
258 ########################################################################
259 # set(GEN_VERSION_INFO_INTERNAL "ON")
260 # include(gmxGenerateVersionString)
262 ########################################################################
263 # Our own GROMACS tests
264 ########################################################################
269 add_definitions( -DHAVE_CONFIG_H )
270 include_directories(${CMAKE_BINARY_DIR}/src)
271 include_directories(${CMAKE_SOURCE_DIR}/include)
273 include(gmxCheckBuildUserTime)
274 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
276 include(gmxTestFloatFormat)
277 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
278 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
279 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
281 include(gmxTestLargeFiles)
282 gmx_test_large_files(GMX_LARGEFILES)
284 include(gmxTestSignal)
285 gmx_test_retsigtype(RETSIGTYPE)
287 include(gmxTestInline)
288 gmx_test_inline(INLINE_KEYWORD)
290 include(gmxTestPipes)
291 gmx_test_pipes(HAVE_PIPES)
293 include(gmxTestInlineASM)
294 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
295 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
299 gmx_test_xdr(GMX_SYSTEM_XDR)
300 if(NOT GMX_SYSTEM_XDR)
301 set(GMX_INTERNAL_XDR 1)
302 endif(NOT GMX_SYSTEM_XDR)
304 if(GMX_FORTRAN OR GMX_POWER6)
305 enable_language(Fortran)
306 include(FortranCInterface)
307 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
308 if(extra_under_score)
310 endif(extra_under_score)
313 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
314 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
316 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
317 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
319 else(GMX_FORTRAN OR GMX_POWER6)
320 set(F77_FUNCDEF "name ## _")
321 set(F77_FUNCDEF_ "name ## _")
322 endif(GMX_FORTRAN OR GMX_POWER6)
325 # Process nonbonded accelerated kernels settings
326 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
327 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
328 if(${GMX_ACCELERATION} STREQUAL "NONE")
330 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
333 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
335 else(GMX_IA32_ASM) #only use intrinsic if not using the ASM loops
338 endif(HAVE_XMMINTRIN_H)
341 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
342 set(GMX_X86_64_SSE 1)
343 else(GMX_X86_64_ASM) #only use intrinsic if not using the ASM loops
346 endif(NOT GMX_IA32_ASM)
347 endif(GMX_X86_64_ASM)
348 endif(HAVE_EMMINTRIN_H)
349 # if(HAVE_PMMINTRIN_H)
351 # endif(HAVE_PMMINTRIN_H)
352 # if(HAVE_SMMINTRIN_H)
354 # endif(HAVE_SMMINTRIN_H)
356 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
358 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
360 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
362 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
364 set(DISABLE_WATERWATER_NLIST 1)
365 set(DISABLE_WATER_NLIST 1)
366 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
367 check_include_files(altivec.h HAVE_ALTIVEC_H)
369 set(GMX_PPC_ALTIVEC 1)
370 endif(HAVE_ALTIVEC_H)
371 else(${GMX_ACCELERATION} STREQUAL "NONE")
372 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
373 endif(${GMX_ACCELERATION} STREQUAL "NONE")
381 # Process QM/MM Settings
382 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
383 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
384 set(GMX_QMMM_GAUSSIAN 1)
385 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
386 set(GMX_QMMM_MOPAC 1)
387 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
388 set(GMX_QMMM_GAMESS 1)
389 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
391 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
392 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
393 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
395 # Process FFT library settings - if not OpenMM build
396 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
397 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
398 # MESSAGE(STATUS "Using external FFT library - fftw3")
400 find_package(FFTW3 REQUIRED)
402 find_package(FFTW3F REQUIRED)
406 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
407 endif(NOT FFTW3_FOUND)
410 include_directories(${FFTW3_INCLUDE_DIR})
411 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
413 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
414 # MESSAGE(STATUS "Using external FFT library - fftw2")
416 find_package(FFTW2 REQUIRED)
418 find_package(FFTW2F REQUIRED)
422 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
423 endif(NOT FFTW2_FOUND)
424 include_directories(${FFTW2_INCLUDE_DIR})
425 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
427 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
428 set(FFTW2_NAME_DFFTW 1)
429 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
430 set(FFTW2_NAME_SFFTW 1)
431 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
432 set(FFTW2_NAME_FFTW 1)
433 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
436 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
437 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
438 find_package(MKL REQUIRED)
439 include_directories(${MKL_INCLUDE_DIR})
440 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
445 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
446 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
447 # set(GMX_FFT_ACML 1)
448 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
449 MESSAGE(STATUS "Using internal FFT library - fftpack")
450 set(GMX_FFT_FFTPACK 1)
451 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
452 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
453 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
455 # MKL has BLAS/LAPACK routines
456 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
457 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
458 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
459 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
460 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
461 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
462 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
464 # Math and thread libraries must often come after all others when linking...
466 list(APPEND GMX_EXTRA_LIBRARIES m)
472 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
473 "Path to swindirect.h")
474 include_directories(${COREWRAP_INCLUDE_DIR})
477 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
478 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
479 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
481 ########################################################################
482 # Specify install locations and which subdirectories to process #
483 ########################################################################
484 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
485 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
486 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
487 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
489 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
492 add_subdirectory(share)
493 add_subdirectory(include)
494 add_subdirectory(man)
496 add_subdirectory(src)