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 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
153 include(CheckLibraryExists)
154 check_library_exists(m sqrt "" HAVE_LIBM)
156 include(CheckTypeSize)
157 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
158 check_type_size("int" SIZEOF_INT)
159 check_type_size("long int" SIZEOF_LONG_INT)
160 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
161 check_type_size("off_t" SIZEOF_OFF_T)
162 check_type_size("void *" SIZEOF_VOIDP)
164 # Check for some basic types that we *need*, so set these to int if they are not present
165 check_type_size(uid_t uid_t)
172 check_type_size(gid_t gid_t)
179 check_type_size(size_t size_t)
186 check_type_size(off_t off_t)
193 include(TestBigEndian)
194 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
198 ########################################################################
199 # Find external packages #
200 ########################################################################
202 find_package(LibXml2)
204 include_directories(${LIBXML2_INCLUDE_DIR})
205 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
210 # X11 includes/libraries are only set in the ngmx subdirectory!
217 set(THREAD_MPI_LIB thread_mpi)
219 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
220 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
221 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
226 set(CUDA_BUILD_EMULATION OFF)
227 find_package(CUDA 2.3 REQUIRED)
228 add_definitions(-DGMX_OPENMM)
229 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
230 set(CUDA_VERBOSE_BUILD ON)
236 find_library(ACCELERATE_FRAMEWORK Accelerate)
237 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
240 # only bother with finding git and using version.h if the source is a git repo
241 if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
243 # We need at least git v1.5.1 be able to parse git's date output. If not
244 # fund or the version is too small, we can't generate version information.
245 find_package(Git 1.5.1)
246 if(NOT Git_FOUND OR Git_VERSION VERSION_LESS "1.5.1")
247 message("No compatible git version found, won't be able to generate proper development version information.")
251 set(USE_VERSION_H OFF)
254 ########################################################################
255 # Generate development version info for cache
256 ########################################################################
257 # set(GEN_VERSION_INFO_INTERNAL "ON")
258 # include(gmxGenerateVersionString)
260 ########################################################################
261 # Our own GROMACS tests
262 ########################################################################
267 add_definitions( -DHAVE_CONFIG_H )
268 include_directories(${CMAKE_BINARY_DIR}/src)
269 include_directories(${CMAKE_SOURCE_DIR}/include)
271 include(gmxCheckBuildUserTime)
272 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
274 include(gmxTestFloatFormat)
275 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
276 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
277 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
279 include(gmxTestLargeFiles)
280 gmx_test_large_files(GMX_LARGEFILES)
282 include(gmxTestSignal)
283 gmx_test_retsigtype(RETSIGTYPE)
285 include(gmxTestInline)
286 gmx_test_inline(INLINE_KEYWORD)
288 include(gmxTestPipes)
289 gmx_test_pipes(HAVE_PIPES)
291 include(gmxTestInlineASM)
292 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
293 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
296 gmx_test_xdr(GMX_SYSTEM_XDR)
297 if(NOT GMX_SYSTEM_XDR)
298 set(GMX_INTERNAL_XDR 1)
299 endif(NOT GMX_SYSTEM_XDR)
301 if(GMX_FORTRAN OR GMX_POWER6)
302 enable_language(Fortran)
303 include(FortranCInterface)
304 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
305 if(extra_under_score)
307 endif(extra_under_score)
310 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
311 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
313 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
314 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
316 else(GMX_FORTRAN OR GMX_POWER6)
317 set(F77_FUNCDEF "name ## _")
318 set(F77_FUNCDEF_ "name ## _")
319 endif(GMX_FORTRAN OR GMX_POWER6)
322 # Process nonbonded accelerated kernels settings
323 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
324 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
325 if(${GMX_ACCELERATION} STREQUAL "NONE")
327 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
330 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
332 else(GMX_IA32_ASM) #only use intrinsic if not using the ASM loops
335 endif(HAVE_XMMINTRIN_H)
338 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
339 set(GMX_X86_64_SSE 1)
340 else(GMX_X86_64_ASM) #only use intrinsic if not using the ASM loops
343 endif(NOT GMX_IA32_ASM)
344 endif(GMX_X86_64_ASM)
345 endif(HAVE_EMMINTRIN_H)
346 # if(HAVE_PMMINTRIN_H)
348 # endif(HAVE_PMMINTRIN_H)
349 # if(HAVE_SMMINTRIN_H)
351 # endif(HAVE_SMMINTRIN_H)
353 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
355 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
357 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
359 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
361 set(DISABLE_WATERWATER_NLIST 1)
362 set(DISABLE_WATER_NLIST 1)
363 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
364 check_include_files(altivec.h HAVE_ALTIVEC_H)
366 set(GMX_PPC_ALTIVEC 1)
367 endif(HAVE_ALTIVEC_H)
368 else(${GMX_ACCELERATION} STREQUAL "NONE")
369 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
370 endif(${GMX_ACCELERATION} STREQUAL "NONE")
378 # Process QM/MM Settings
379 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
380 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
381 set(GMX_QMMM_GAUSSIAN 1)
382 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
383 set(GMX_QMMM_MOPAC 1)
384 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
385 set(GMX_QMMM_GAMESS 1)
386 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
388 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
389 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
390 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
392 # Process FFT library settings - if not OpenMM build
393 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
394 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
395 # MESSAGE(STATUS "Using external FFT library - fftw3")
397 find_package(FFTW3 REQUIRED)
399 find_package(FFTW3F REQUIRED)
403 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
404 endif(NOT FFTW3_FOUND)
407 include_directories(${FFTW3_INCLUDE_DIR})
408 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
410 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
411 # MESSAGE(STATUS "Using external FFT library - fftw2")
413 find_package(FFTW2 REQUIRED)
415 find_package(FFTW2F REQUIRED)
419 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
420 endif(NOT FFTW2_FOUND)
421 include_directories(${FFTW2_INCLUDE_DIR})
422 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
424 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
425 set(FFTW2_NAME_DFFTW 1)
426 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
427 set(FFTW2_NAME_SFFTW 1)
428 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
429 set(FFTW2_NAME_FFTW 1)
430 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
433 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
434 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
435 find_package(MKL REQUIRED)
436 include_directories(${MKL_INCLUDE_DIR})
437 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
442 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
443 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
444 # set(GMX_FFT_ACML 1)
445 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
446 MESSAGE(STATUS "Using internal FFT library - fftpack")
447 set(GMX_FFT_FFTPACK 1)
448 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
449 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
450 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
452 # MKL has BLAS/LAPACK routines
453 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
454 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
455 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
456 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
457 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
458 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
459 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
461 # Math and thread libraries must often come after all others when linking...
463 list(APPEND GMX_EXTRA_LIBRARIES m)
469 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
470 "Path to swindirect.h")
471 include_directories(${COREWRAP_INCLUDE_DIR})
474 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
475 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
476 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
478 ########################################################################
479 # Specify install locations and which subdirectories to process #
480 ########################################################################
481 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
482 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
483 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
484 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
486 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
489 add_subdirectory(share)
490 add_subdirectory(include)
491 add_subdirectory(man)
493 add_subdirectory(src)