1 cmake_minimum_required(VERSION 2.6)
3 set(PROJECT_VERSION "4.0.99_development_20090605"
4 CACHE STRING "Gromacs version string")
6 # Cmake modules/macros are in a subdirectory to keep this file cleaner
7 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
9 ########################################################################
10 # User input options #
11 ########################################################################
12 option(GMX_DOUBLE "Use double precision" OFF)
13 option(GMX_MPI "Build a parallel (message-passing) version of GROMACS" OFF)
14 option(GMX_THREADS "Build a parallel (threaded-based) version of GROMACS: (doesn't work yet!)" ON)
15 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
16 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
17 set(GMX_ACCELERATION "none"
18 CACHE STRING "Accelerated kernels. Pick one of: SSE, BlueGene, Power6, ia64, altivec")
20 set(GMX_FFT_LIBRARY "fftw3"
21 CACHE STRING "FFT library choices: fftw3,fftw2,mkl,fftpack[built-in]")
22 option(GMX_DISABLE_FFTW_MEASURE
23 "Do not optimize FFTW setups (not needed with SSE)" OFF)
24 set(GMX_QMMM_PROGRAM "none"
25 CACHE STRING "QM package choices: none,gaussian,mopac,gamess")
26 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
27 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI)" OFF)
28 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" ON)
29 option(GMX_DLOPEN "Compile with dlopen, needed to read VMD supported file formats" ON)
30 mark_as_advanced(GMX_MPI_IN_PLACE)
34 option(GMX_IA32_ASM "Add SSE assembly files for IA32" OFF)
35 option(GMX_X86_64_ASM "Add SSE assembly files for X86_64" OFF)
37 ########################################################################
38 # Fix stupid flags on MSVC
39 ########################################################################
40 IF(CMAKE_GENERATOR MATCHES "Visual Studio")
41 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
42 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
43 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
44 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
45 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
47 set(GMX_EXTRA_LIBRARIES)
49 ########################################################################
51 ########################################################################
54 #message(FATAL_ERROR "Thread-based parallelization conflicts with MPI.")
55 set(GMX_THREADS OFF CACHE BOOL
56 "Thread-based parallelization conflicts with MPI." FORCE)
60 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
61 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
63 include_directories(${MPI_INCLUDE_PATH})
64 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
65 add_definitions( -DMPI ) #for FAHCORE
66 include(gmxTestMPI_IN_PLACE)
68 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
69 endif (GMX_MPI_IN_PLACE)
71 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
73 include(gmxTestCatamount)
74 gmx_test_catamount(GMX_CRAY_XT3)
82 ########################################################################
83 # Basic system tests (standard libraries, headers, functions, types) #
84 ########################################################################
85 include(CheckIncludeFiles)
86 check_include_files(string.h HAVE_STRING_H)
87 check_include_files(limits.h HAVE_LIMITS_H)
88 check_include_files(memory.h HAVE_MEMORY_H)
89 check_include_files(unistd.h HAVE_UNISTD_H)
90 check_include_files(pwd.h HAVE_PWD_H)
91 check_include_files(stdint.h HAVE_STDINT_H)
92 check_include_files(stdlib.h HAVE_STDLIB_H)
93 check_include_files(pthread.h HAVE_PTHREAD_H)
94 check_include_files(dirent.h HAVE_DIRENT_H)
95 check_include_files(inttypes.h HAVE_INTTYPES_H)
96 check_include_files(regex.h HAVE_REGEX_H)
97 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
98 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
99 check_include_files(sys/time.h HAVE_SYS_TIME_H)
100 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
101 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
103 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
104 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
105 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
106 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
108 include(CheckFunctionExists)
109 check_function_exists(strcasecmp HAVE_STRCASECMP)
110 check_function_exists(strdup HAVE_STRDUP)
111 check_function_exists(vprintf HAVE_VPRINTF)
112 check_function_exists(memcmp HAVE_MEMCMP)
113 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
114 check_function_exists(isnan HAVE_ISNAN)
115 check_function_exists(_isnan HAVE__ISNAN)
116 check_function_exists(isfinite HAVE_ISFINITE)
117 check_function_exists(_isfinite HAVE__ISFINITE)
118 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
120 include(CheckLibraryExists)
121 check_library_exists(m sqrt "" HAVE_LIBM)
123 include(CheckTypeSize)
124 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
125 check_type_size("int" SIZEOF_INT)
126 check_type_size("long int" SIZEOF_LONG_INT)
127 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
128 check_type_size("off_t" SIZEOF_OFF_T)
129 check_type_size("void *" SIZEOF_VOIDP)
131 # Check for some basic types that we *need*, so set these to int if they are not present
132 check_type_size(uid_t uid_t)
139 check_type_size(gid_t gid_t)
146 check_type_size(size_t size_t)
153 check_type_size(off_t off_t)
160 include(TestBigEndian)
161 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
165 ########################################################################
166 # Find external packages #
167 ########################################################################
169 find_package(LibXml2)
171 include_directories(${LIBXML2_INCLUDE_DIR})
172 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
177 # X11 includes/libraries are only set in the ngmx subdirectory!
184 set(THREAD_MPI_LIB thread_mpi)
186 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
187 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
188 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
194 find_library(ACCELERATE_FRAMEWORK Accelerate)
195 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
198 ########################################################################
199 # Our own GROMACS tests
200 ########################################################################
205 add_definitions( -DHAVE_CONFIG_H )
206 include_directories(${CMAKE_BINARY_DIR}/src)
207 include_directories(${CMAKE_SOURCE_DIR}/include)
209 include(gmxCheckBuildUserTime)
210 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
212 include(gmxTestFloatFormat)
213 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
214 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
215 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
217 include(gmxTestLargeFiles)
218 gmx_test_large_files(GMX_LARGEFILES)
220 include(gmxTestSignal)
221 gmx_test_retsigtype(RETSIGTYPE)
223 include(gmxTestInline)
224 gmx_test_inline(INLINE_KEYWORD)
226 include(gmxTestPipes)
227 gmx_test_pipes(HAVE_PIPES)
229 include(gmxTestInlineASM)
230 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
231 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
234 gmx_test_xdr(GMX_SYSTEM_XDR)
235 if(NOT GMX_SYSTEM_XDR)
236 set(GMX_INTERNAL_XDR 1)
237 endif(NOT GMX_SYSTEM_XDR)
239 if(GMX_FORTRAN OR GMX_POWER6)
240 enable_language(Fortran)
241 include(FortranCInterface)
242 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
243 if(extra_under_score)
245 endif(extra_under_score)
248 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
249 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
251 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
252 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
254 else(GMX_FORTRAN OR GMX_POWER6)
255 set(F77_FUNCDEF "name ## _")
256 set(F77_FUNCDEF_ "name ## _")
257 endif(GMX_FORTRAN OR GMX_POWER6)
260 # Process nonbonded accelerated kernels settings
261 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
262 if(${GMX_ACCELERATION} STREQUAL "NONE")
264 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
268 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
269 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
272 endif(HAVE_XMMINTRIN_H)
275 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
276 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
277 set(GMX_X86_64_SSE 1)
278 else(GMX_X86_64_ASM) #only use intrinsic if not using the ASM loops
280 endif(GMX_X86_64_ASM)
281 endif(HAVE_EMMINTRIN_H)
282 # if(HAVE_PMMINTRIN_H)
284 # endif(HAVE_PMMINTRIN_H)
285 # if(HAVE_SMMINTRIN_H)
287 # endif(HAVE_SMMINTRIN_H)
289 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
291 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
293 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
295 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
297 set(DISABLE_WATERWATER_NLIST 1)
298 set(DISABLE_WATER_NLIST 1)
299 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
300 check_include_files(altivec.h HAVE_ALTIVEC_H)
302 set(GMX_PPC_ALTIVEC 1)
303 endif(HAVE_ALTIVEC_H)
304 else(${GMX_ACCELERATION} STREQUAL "NONE")
305 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
306 endif(${GMX_ACCELERATION} STREQUAL "NONE")
314 # Process QM/MM Settings
315 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
316 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
317 set(GMX_QMMM_GAUSSIAN 1)
318 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
319 set(GMX_QMMM_MOPAC 1)
320 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
321 set(GMX_QMMM_GAMESS 1)
322 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
324 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
325 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
326 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
328 # Process FFT library settings
329 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
330 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
331 # MESSAGE(STATUS "Using external FFT library - fftw3")
333 find_package(FFTW3 REQUIRED)
335 find_package(FFTW3F REQUIRED)
339 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
340 endif(NOT FFTW3_FOUND)
343 include_directories(${FFTW3_INCLUDE_DIR})
344 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
346 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
347 # MESSAGE(STATUS "Using external FFT library - fftw2")
349 find_package(FFTW2 REQUIRED)
351 find_package(FFTW2F REQUIRED)
355 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
356 endif(NOT FFTW2_FOUND)
357 include_directories(${FFTW2_INCLUDE_DIR})
358 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
360 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
361 set(FFTW2_NAME_DFFTW 1)
362 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
363 set(FFTW2_NAME_SFFTW 1)
364 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
365 set(FFTW2_NAME_FFTW 1)
366 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
369 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
370 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
371 find_package(MKL REQUIRED)
372 include_directories(${MKL_INCLUDE_DIR})
373 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
378 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
379 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
380 # set(GMX_FFT_ACML 1)
381 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
382 MESSAGE(STATUS "Using internal FFT library - fftpack")
383 set(GMX_FFT_FFTPACK 1)
384 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
385 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
386 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
388 # MKL has BLAS/LAPACK routines
389 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
390 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
391 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
392 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
393 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
394 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
395 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
397 # Math and thread libraries must often come after all others when linking...
399 list(APPEND GMX_EXTRA_LIBRARIES m)
405 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
406 "Path to swindirect.h")
407 include_directories(${COREWRAP_INCLUDE_DIR})
410 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
411 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
412 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
414 ########################################################################
415 # Specify install locations and which subdirectories to process #
416 ########################################################################
417 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
418 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
419 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
420 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
422 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
425 add_subdirectory(share)
426 add_subdirectory(include)
427 add_subdirectory(man)
429 add_subdirectory(src)