1 cmake_minimum_required(VERSION 2.6.2)
4 set(PROJECT_VERSION "4.0.99-dev-20100305"
5 CACHE STRING "Gromacs version string")
7 # Cmake modules/macros are in a subdirectory to keep this file cleaner
8 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
10 ########################################################################
11 # User input options #
12 ########################################################################
13 option(GMX_DOUBLE "Use double precision" OFF)
14 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
15 option(GMX_THREADS "Build a parallel (threaded-based) version of GROMACS: (doesn't work yet!)" ON)
16 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
17 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
18 option(GMX_OPENMM "Accelerated execution on GPUs through the OpenMM library" OFF)
19 set(GMX_ACCELERATION "none"
20 CACHE STRING "Accelerated kernels. Pick one of: SSE, BlueGene, Power6, ia64, altivec")
22 set(GMX_FFT_LIBRARY "fftw3"
23 CACHE STRING "FFT library choices: fftw3,fftw2,mkl,fftpack[built-in]")
24 option(GMX_DISABLE_FFTW_MEASURE
25 "Do not optimize FFTW setups (not needed with SSE)" OFF)
26 set(GMX_QMMM_PROGRAM "none"
27 CACHE STRING "QM package choices: none,gaussian,mopac,gamess")
28 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
29 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI)" OFF)
30 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
31 option(GMX_DLOPEN "Compile with dlopen, needed to read VMD supported file formats" ON)
32 mark_as_advanced(GMX_MPI_IN_PLACE)
36 option(GMX_IA32_ASM "Add SSE assembly files for IA32" OFF)
37 option(GMX_X86_64_ASM "Add SSE assembly files for X86_64" OFF)
39 #######################################################################
40 # Check for options incompatible with OpenMM build #
41 #######################################################################
44 message(FATAL_ERROR "The OpenMM build is not compatible with MPI option!")
47 message(FATAL_ERROR "The OpenMM build is not compatible with threads option!")
49 # if(GMX_SOFTWARE_INVSQRT)
50 # message(WARNING "The OpenMM build cannot make use of gromacs software 1/sqrt!")
51 # set(GMX_SOFTWARE_INVSQRT OFF)
52 # endif(GMX_SOFTWARE_INVSQRT)
53 if(NOT GMX_ACCELERATION MATCHES "none")
54 message(WARNING "The OpenMM build does not support other acceleration modes!")
55 set(GMX_ACCELERATION "none")
58 message(FATAL_ERROR "The OpenMM build does not support other acceleration modes!")
63 ########################################################################
64 # Fix stupid flags on MSVC
65 ########################################################################
66 IF(CMAKE_GENERATOR MATCHES "Visual Studio")
67 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
68 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
69 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
70 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
71 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
73 set(GMX_EXTRA_LIBRARIES)
75 ########################################################################
77 ########################################################################
80 #message(FATAL_ERROR "Thread-based parallelization conflicts with MPI.")
81 set(GMX_THREADS OFF CACHE BOOL
82 "Thread-based parallelization conflicts with MPI." FORCE)
86 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
87 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
89 include_directories(${MPI_INCLUDE_PATH})
90 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
91 add_definitions( -DMPI ) #for FAHCORE
92 include(gmxTestMPI_IN_PLACE)
94 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
95 endif (GMX_MPI_IN_PLACE)
97 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
99 include(gmxTestCatamount)
100 gmx_test_catamount(GMX_CRAY_XT3)
108 ########################################################################
109 # Basic system tests (standard libraries, headers, functions, types) #
110 ########################################################################
111 include(CheckIncludeFiles)
112 check_include_files(string.h HAVE_STRING_H)
113 check_include_files(limits.h HAVE_LIMITS_H)
114 check_include_files(memory.h HAVE_MEMORY_H)
115 check_include_files(unistd.h HAVE_UNISTD_H)
116 check_include_files(pwd.h HAVE_PWD_H)
117 check_include_files(stdint.h HAVE_STDINT_H)
118 check_include_files(stdlib.h HAVE_STDLIB_H)
119 check_include_files(pthread.h HAVE_PTHREAD_H)
120 check_include_files(dirent.h HAVE_DIRENT_H)
121 check_include_files(inttypes.h HAVE_INTTYPES_H)
122 check_include_files(regex.h HAVE_REGEX_H)
123 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
124 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
125 check_include_files(sys/time.h HAVE_SYS_TIME_H)
126 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
127 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
129 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
130 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
131 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
132 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
134 include(CheckFunctionExists)
135 check_function_exists(strcasecmp HAVE_STRCASECMP)
136 check_function_exists(strdup HAVE_STRDUP)
137 check_function_exists(vprintf HAVE_VPRINTF)
138 check_function_exists(memcmp HAVE_MEMCMP)
139 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
140 check_function_exists(isnan HAVE_ISNAN)
141 check_function_exists(_isnan HAVE__ISNAN)
142 check_function_exists(isfinite HAVE_ISFINITE)
143 check_function_exists(_isfinite HAVE__ISFINITE)
144 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
146 include(CheckLibraryExists)
147 check_library_exists(m sqrt "" HAVE_LIBM)
149 include(CheckTypeSize)
150 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
151 check_type_size("int" SIZEOF_INT)
152 check_type_size("long int" SIZEOF_LONG_INT)
153 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
154 check_type_size("off_t" SIZEOF_OFF_T)
155 check_type_size("void *" SIZEOF_VOIDP)
157 # Check for some basic types that we *need*, so set these to int if they are not present
158 check_type_size(uid_t uid_t)
165 check_type_size(gid_t gid_t)
172 check_type_size(size_t size_t)
179 check_type_size(off_t off_t)
186 include(TestBigEndian)
187 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
191 ########################################################################
192 # Find external packages #
193 ########################################################################
195 find_package(LibXml2)
197 include_directories(${LIBXML2_INCLUDE_DIR})
198 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
203 # X11 includes/libraries are only set in the ngmx subdirectory!
210 set(THREAD_MPI_LIB thread_mpi)
212 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
213 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
214 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
219 set(CUDA_BUILD_EMULATION OFF)
220 find_package(CUDA 2.3 EXACT REQUIRED) # TODO what are we compatible with?
221 add_definitions(-DGMX_OPENMM)
222 if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
223 set(CUDA_VERBOSE_BUILD ON)
227 # "OpenMM_ROOT_DIR: ${OpenMM_ROOT_DIR}\n"
228 # "OpenMM_LIBRARIES: ${OpenMM_LIBRARIES}\n"
229 # "OpenMM_LIBRARY_DIR: ${OpenMM_LIBRARY_DIR}\n"
230 # "OpenMM_INCLUDE_DIR: ${OpenMM_INCLUDE_DIR}\n"
231 # "OpenMM_PLUGIN_DIR: ${OpenMM_PLUGIN_DIR}\n"
236 find_library(ACCELERATE_FRAMEWORK Accelerate)
237 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
240 ########################################################################
241 # Our own GROMACS tests
242 ########################################################################
247 add_definitions( -DHAVE_CONFIG_H )
248 include_directories(${CMAKE_BINARY_DIR}/src)
249 include_directories(${CMAKE_SOURCE_DIR}/include)
251 include(gmxCheckBuildUserTime)
252 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
254 include(gmxTestFloatFormat)
255 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
256 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
257 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
259 include(gmxTestLargeFiles)
260 gmx_test_large_files(GMX_LARGEFILES)
262 include(gmxTestSignal)
263 gmx_test_retsigtype(RETSIGTYPE)
265 include(gmxTestInline)
266 gmx_test_inline(INLINE_KEYWORD)
268 include(gmxTestPipes)
269 gmx_test_pipes(HAVE_PIPES)
271 include(gmxTestInlineASM)
272 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
273 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
276 gmx_test_xdr(GMX_SYSTEM_XDR)
277 if(NOT GMX_SYSTEM_XDR)
278 set(GMX_INTERNAL_XDR 1)
279 endif(NOT GMX_SYSTEM_XDR)
281 if(GMX_FORTRAN OR GMX_POWER6)
282 enable_language(Fortran)
283 include(FortranCInterface)
284 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
285 if(extra_under_score)
287 endif(extra_under_score)
290 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
291 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
293 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
294 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
296 else(GMX_FORTRAN OR GMX_POWER6)
297 set(F77_FUNCDEF "name ## _")
298 set(F77_FUNCDEF_ "name ## _")
299 endif(GMX_FORTRAN OR GMX_POWER6)
302 # Process nonbonded accelerated kernels settings
303 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
304 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
305 if(${GMX_ACCELERATION} STREQUAL "NONE")
307 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
311 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
314 endif(HAVE_XMMINTRIN_H)
317 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
318 set(GMX_X86_64_SSE 1)
319 else(GMX_X86_64_ASM) #only use intrinsic if not using the ASM loops
321 endif(GMX_X86_64_ASM)
322 endif(HAVE_EMMINTRIN_H)
323 # if(HAVE_PMMINTRIN_H)
325 # endif(HAVE_PMMINTRIN_H)
326 # if(HAVE_SMMINTRIN_H)
328 # endif(HAVE_SMMINTRIN_H)
330 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
332 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
334 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
336 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
338 set(DISABLE_WATERWATER_NLIST 1)
339 set(DISABLE_WATER_NLIST 1)
340 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
341 check_include_files(altivec.h HAVE_ALTIVEC_H)
343 set(GMX_PPC_ALTIVEC 1)
344 endif(HAVE_ALTIVEC_H)
345 else(${GMX_ACCELERATION} STREQUAL "NONE")
346 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
347 endif(${GMX_ACCELERATION} STREQUAL "NONE")
355 # Process QM/MM Settings
356 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
357 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
358 set(GMX_QMMM_GAUSSIAN 1)
359 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
360 set(GMX_QMMM_MOPAC 1)
361 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
362 set(GMX_QMMM_GAMESS 1)
363 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
365 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
366 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
367 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
369 # Process FFT library settings
370 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
371 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
372 # MESSAGE(STATUS "Using external FFT library - fftw3")
374 find_package(FFTW3 REQUIRED)
376 find_package(FFTW3F REQUIRED)
380 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
381 endif(NOT FFTW3_FOUND)
384 include_directories(${FFTW3_INCLUDE_DIR})
385 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
387 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
388 # MESSAGE(STATUS "Using external FFT library - fftw2")
390 find_package(FFTW2 REQUIRED)
392 find_package(FFTW2F REQUIRED)
396 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
397 endif(NOT FFTW2_FOUND)
398 include_directories(${FFTW2_INCLUDE_DIR})
399 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
401 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
402 set(FFTW2_NAME_DFFTW 1)
403 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
404 set(FFTW2_NAME_SFFTW 1)
405 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
406 set(FFTW2_NAME_FFTW 1)
407 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
410 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
411 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
412 find_package(MKL REQUIRED)
413 include_directories(${MKL_INCLUDE_DIR})
414 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
419 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
420 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
421 # set(GMX_FFT_ACML 1)
422 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
423 MESSAGE(STATUS "Using internal FFT library - fftpack")
424 set(GMX_FFT_FFTPACK 1)
425 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
426 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
427 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
429 # MKL has BLAS/LAPACK routines
430 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
431 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
432 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
433 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
434 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
435 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
436 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
438 # Math and thread libraries must often come after all others when linking...
440 list(APPEND GMX_EXTRA_LIBRARIES m)
446 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
447 "Path to swindirect.h")
448 include_directories(${COREWRAP_INCLUDE_DIR})
451 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
452 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
453 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
455 ########################################################################
456 # Specify install locations and which subdirectories to process #
457 ########################################################################
458 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
459 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
460 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
461 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
463 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
466 add_subdirectory(share)
467 add_subdirectory(include)
468 add_subdirectory(man)
470 add_subdirectory(src)