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!)" OFF)
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 ########################################################################
35 # Fix stupid flags on MSVC
36 ########################################################################
37 IF(CMAKE_GENERATOR MATCHES "Visual Studio")
38 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
39 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
40 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
41 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
42 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
44 set(GMX_EXTRA_LIBRARIES)
46 ########################################################################
48 ########################################################################
51 message(FATAL_ERROR "Thread-based parallelization conflicts with MPI.")
55 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
56 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
58 include_directories(${MPI_INCLUDE_PATH})
59 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
60 add_definitions( -DMPI ) #for FAHCORE
61 include(gmxTestMPI_IN_PLACE)
63 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
64 endif (GMX_MPI_IN_PLACE)
66 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
68 include(gmxTestCatamount)
69 gmx_test_catamount(GMX_CRAY_XT3)
77 ########################################################################
78 # Basic system tests (standard libraries, headers, functions, types) #
79 ########################################################################
80 include(CheckIncludeFiles)
81 check_include_files(string.h HAVE_STRING_H)
82 check_include_files(limits.h HAVE_LIMITS_H)
83 check_include_files(memory.h HAVE_MEMORY_H)
84 check_include_files(unistd.h HAVE_UNISTD_H)
85 check_include_files(pwd.h HAVE_PWD_H)
86 check_include_files(stdint.h HAVE_STDINT_H)
87 check_include_files(stdlib.h HAVE_STDLIB_H)
88 check_include_files(pthread.h HAVE_PTHREAD_H)
89 check_include_files(inttypes.h HAVE_INTTYPES_H)
90 check_include_files(regex.h HAVE_REGEX_H)
91 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
92 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
93 check_include_files(sys/time.h HAVE_SYS_TIME_H)
94 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
95 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
97 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
98 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
99 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
100 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
102 include(CheckFunctionExists)
103 check_function_exists(strcasecmp HAVE_STRCASECMP)
104 check_function_exists(strdup HAVE_STRDUP)
105 check_function_exists(vprintf HAVE_VPRINTF)
106 check_function_exists(memcmp HAVE_MEMCMP)
107 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
108 check_function_exists(isnan HAVE_ISNAN)
109 check_function_exists(_isnan HAVE__ISNAN)
110 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
112 include(CheckLibraryExists)
113 check_library_exists(m sqrt "" HAVE_LIBM)
115 include(CheckTypeSize)
116 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
117 check_type_size("int" SIZEOF_INT)
118 check_type_size("long int" SIZEOF_LONG_INT)
119 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
120 check_type_size("off_t" SIZEOF_OFF_T)
121 check_type_size("void *" SIZEOF_VOIDP)
123 # Check for some basic types that we *need*, so set these to int if they are not present
124 check_type_size(uid_t uid_t)
131 check_type_size(gid_t gid_t)
138 check_type_size(size_t size_t)
145 check_type_size(off_t off_t)
152 include(TestBigEndian)
153 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
157 ########################################################################
158 # Find external packages #
159 ########################################################################
161 find_package(LibXml2)
163 include_directories(${LIBXML2_INCLUDE_DIR})
164 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
169 # X11 includes/libraries are only set in the ngmx subdirectory!
176 set(THREAD_MPI_LIB thread_mpi)
178 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
179 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
180 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
186 find_library(ACCELERATE_FRAMEWORK Accelerate)
187 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
190 ########################################################################
191 # Our own GROMACS tests
192 ########################################################################
197 add_definitions( -DHAVE_CONFIG_H )
198 include_directories(${CMAKE_BINARY_DIR}/src)
199 include_directories(${CMAKE_SOURCE_DIR}/include)
201 include(gmxCheckBuildUserTime)
202 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
204 include(gmxTestFloatFormat)
205 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
206 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
207 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
209 include(gmxTestLargeFiles)
210 gmx_test_large_files(GMX_LARGEFILES)
212 include(gmxTestSignal)
213 gmx_test_retsigtype(RETSIGTYPE)
214 gmx_test_sigusr1(HAVE_SIGUSR1)
216 include(gmxTestInline)
217 gmx_test_inline(INLINE_KEYWORD)
219 include(gmxTestPipes)
220 gmx_test_pipes(HAVE_PIPES)
222 include(gmxTestInlineASM)
223 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
224 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
227 gmx_test_xdr(GMX_SYSTEM_XDR)
228 if(NOT GMX_SYSTEM_XDR)
229 set(GMX_INTERNAL_XDR 1)
230 endif(NOT GMX_SYSTEM_XDR)
232 if(GMX_FORTRAN OR GMX_POWER6)
233 enable_language(Fortran)
234 include(FortranCInterface)
235 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
236 if(extra_under_score)
238 endif(extra_under_score)
241 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
242 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
244 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
245 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
247 else(GMX_FORTRAN OR GMX_POWER6)
248 set(F77_FUNCDEF "name ## _")
249 set(F77_FUNCDEF_ "name ## _")
250 endif(GMX_FORTRAN OR GMX_POWER6)
253 # Process nonbonded accelerated kernels settings
254 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
255 if(${GMX_ACCELERATION} STREQUAL "NONE")
257 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
260 endif(HAVE_XMMINTRIN_H)
263 endif(HAVE_EMMINTRIN_H)
264 # if(HAVE_PMMINTRIN_H)
266 # endif(HAVE_PMMINTRIN_H)
267 # if(HAVE_SMMINTRIN_H)
269 # endif(HAVE_SMMINTRIN_H)
271 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
273 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
275 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
277 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
279 set(DISABLE_WATERWATER_NLIST 1)
280 set(DISABLE_WATER_NLIST 1)
281 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
282 check_include_files(altivec.h HAVE_ALTIVEC_H)
284 set(GMX_PPC_ALTIVEC 1)
285 endif(HAVE_ALTIVEC_H)
286 else(${GMX_ACCELERATION} STREQUAL "NONE")
287 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
288 endif(${GMX_ACCELERATION} STREQUAL "NONE")
296 # Process QM/MM Settings
297 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
298 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
299 set(GMX_QMMM_GAUSSIAN 1)
300 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
301 set(GMX_QMMM_MOPAC 1)
302 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
303 set(GMX_QMMM_GAMESS 1)
304 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
306 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
307 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
308 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
310 # Process FFT library settings
311 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
312 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
313 # MESSAGE(STATUS "Using external FFT library - fftw3")
315 find_package(FFTW3 REQUIRED)
317 find_package(FFTW3F REQUIRED)
321 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
322 endif(NOT FFTW3_FOUND)
325 include_directories(${FFTW3_INCLUDE_DIR})
326 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
328 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
329 # MESSAGE(STATUS "Using external FFT library - fftw2")
331 find_package(FFTW2 REQUIRED)
333 find_package(FFTW2F REQUIRED)
337 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
338 endif(NOT FFTW2_FOUND)
339 include_directories(${FFTW2_INCLUDE_DIR})
340 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
342 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
343 set(FFTW2_NAME_DFFTW 1)
344 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
345 set(FFTW2_NAME_SFFTW 1)
346 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
347 set(FFTW2_NAME_FFTW 1)
348 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
351 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
352 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
353 find_package(MKL REQUIRED)
354 include_directories(${MKL_INCLUDE_DIR})
355 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
360 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
361 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
362 # set(GMX_FFT_ACML 1)
363 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
364 MESSAGE(STATUS "Using internal FFT library - fftpack")
365 set(GMX_FFT_FFTPACK 1)
366 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
367 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
368 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
370 # MKL has BLAS/LAPACK routines
371 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
372 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
373 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
374 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
375 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
376 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
377 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
379 # Math and thread libraries must often come after all others when linking...
381 list(APPEND GMX_EXTRA_LIBRARIES m)
387 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
388 "Path to swindirect.h")
389 include_directories(${COREWRAP_INCLUDE_DIR})
392 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
393 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
394 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
396 ########################################################################
397 # Specify install locations and which subdirectories to process #
398 ########################################################################
399 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
400 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
401 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
402 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
404 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
407 add_subdirectory(share)
408 add_subdirectory(include)
409 add_subdirectory(man)
411 add_subdirectory(src)