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 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.")
58 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
59 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
61 include_directories(${MPI_INCLUDE_PATH})
62 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
63 add_definitions( -DMPI ) #for FAHCORE
64 include(gmxTestMPI_IN_PLACE)
66 gmx_test_mpi_in_place(MPI_IN_PLACE_EXISTS)
67 endif (GMX_MPI_IN_PLACE)
69 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
71 include(gmxTestCatamount)
72 gmx_test_catamount(GMX_CRAY_XT3)
80 ########################################################################
81 # Basic system tests (standard libraries, headers, functions, types) #
82 ########################################################################
83 include(CheckIncludeFiles)
84 check_include_files(string.h HAVE_STRING_H)
85 check_include_files(limits.h HAVE_LIMITS_H)
86 check_include_files(memory.h HAVE_MEMORY_H)
87 check_include_files(unistd.h HAVE_UNISTD_H)
88 check_include_files(pwd.h HAVE_PWD_H)
89 check_include_files(stdint.h HAVE_STDINT_H)
90 check_include_files(stdlib.h HAVE_STDLIB_H)
91 check_include_files(pthread.h HAVE_PTHREAD_H)
92 check_include_files(inttypes.h HAVE_INTTYPES_H)
93 check_include_files(regex.h HAVE_REGEX_H)
94 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
95 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
96 check_include_files(sys/time.h HAVE_SYS_TIME_H)
97 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
98 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
100 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
101 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
102 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
103 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
105 include(CheckFunctionExists)
106 check_function_exists(strcasecmp HAVE_STRCASECMP)
107 check_function_exists(strdup HAVE_STRDUP)
108 check_function_exists(vprintf HAVE_VPRINTF)
109 check_function_exists(memcmp HAVE_MEMCMP)
110 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
111 check_function_exists(isnan HAVE_ISNAN)
112 check_function_exists(_isnan HAVE__ISNAN)
113 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
115 include(CheckLibraryExists)
116 check_library_exists(m sqrt "" HAVE_LIBM)
118 include(CheckTypeSize)
119 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
120 check_type_size("int" SIZEOF_INT)
121 check_type_size("long int" SIZEOF_LONG_INT)
122 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
123 check_type_size("off_t" SIZEOF_OFF_T)
124 check_type_size("void *" SIZEOF_VOIDP)
126 # Check for some basic types that we *need*, so set these to int if they are not present
127 check_type_size(uid_t uid_t)
134 check_type_size(gid_t gid_t)
141 check_type_size(size_t size_t)
148 check_type_size(off_t off_t)
155 include(TestBigEndian)
156 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
160 ########################################################################
161 # Find external packages #
162 ########################################################################
164 find_package(LibXml2)
166 include_directories(${LIBXML2_INCLUDE_DIR})
167 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
172 # X11 includes/libraries are only set in the ngmx subdirectory!
179 set(THREAD_MPI_LIB thread_mpi)
181 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
182 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
183 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
189 find_library(ACCELERATE_FRAMEWORK Accelerate)
190 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
193 ########################################################################
194 # Our own GROMACS tests
195 ########################################################################
200 add_definitions( -DHAVE_CONFIG_H )
201 include_directories(${CMAKE_BINARY_DIR}/src)
202 include_directories(${CMAKE_SOURCE_DIR}/include)
204 include(gmxCheckBuildUserTime)
205 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
207 include(gmxTestFloatFormat)
208 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
209 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
210 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
212 include(gmxTestLargeFiles)
213 gmx_test_large_files(GMX_LARGEFILES)
215 include(gmxTestSignal)
216 gmx_test_retsigtype(RETSIGTYPE)
217 gmx_test_sigusr1(HAVE_SIGUSR1)
219 include(gmxTestInline)
220 gmx_test_inline(INLINE_KEYWORD)
222 include(gmxTestPipes)
223 gmx_test_pipes(HAVE_PIPES)
225 include(gmxTestInlineASM)
226 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
227 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
230 gmx_test_xdr(GMX_SYSTEM_XDR)
231 if(NOT GMX_SYSTEM_XDR)
232 set(GMX_INTERNAL_XDR 1)
233 endif(NOT GMX_SYSTEM_XDR)
235 if(GMX_FORTRAN OR GMX_POWER6)
236 enable_language(Fortran)
237 include(FortranCInterface)
238 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
239 if(extra_under_score)
241 endif(extra_under_score)
244 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
245 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
247 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
248 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
250 else(GMX_FORTRAN OR GMX_POWER6)
251 set(F77_FUNCDEF "name ## _")
252 set(F77_FUNCDEF_ "name ## _")
253 endif(GMX_FORTRAN OR GMX_POWER6)
256 # Process nonbonded accelerated kernels settings
257 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
258 if(${GMX_ACCELERATION} STREQUAL "NONE")
260 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
264 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
265 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
268 endif(HAVE_XMMINTRIN_H)
271 option(GMX_ASM_USEASM-ATT "Use ATT-style assembly" ON)
272 option(GMX_ASM_USECCOMPILER "Use C compiler for assembly" ON)
273 set(GMX_X86_64_SSE 1)
274 else(GMX_X86_64_ASM) #only use intrinsic if not using the ASM loops
276 endif(GMX_X86_64_ASM)
277 endif(HAVE_EMMINTRIN_H)
278 # if(HAVE_PMMINTRIN_H)
280 # endif(HAVE_PMMINTRIN_H)
281 # if(HAVE_SMMINTRIN_H)
283 # endif(HAVE_SMMINTRIN_H)
285 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
287 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
289 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
291 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
293 set(DISABLE_WATERWATER_NLIST 1)
294 set(DISABLE_WATER_NLIST 1)
295 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
296 check_include_files(altivec.h HAVE_ALTIVEC_H)
298 set(GMX_PPC_ALTIVEC 1)
299 endif(HAVE_ALTIVEC_H)
300 else(${GMX_ACCELERATION} STREQUAL "NONE")
301 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
302 endif(${GMX_ACCELERATION} STREQUAL "NONE")
310 # Process QM/MM Settings
311 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
312 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
313 set(GMX_QMMM_GAUSSIAN 1)
314 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
315 set(GMX_QMMM_MOPAC 1)
316 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
317 set(GMX_QMMM_GAMESS 1)
318 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
320 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
321 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
322 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
324 # Process FFT library settings
325 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
326 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
327 # MESSAGE(STATUS "Using external FFT library - fftw3")
329 find_package(FFTW3 REQUIRED)
331 find_package(FFTW3F REQUIRED)
335 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
336 endif(NOT FFTW3_FOUND)
339 include_directories(${FFTW3_INCLUDE_DIR})
340 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
342 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
343 # MESSAGE(STATUS "Using external FFT library - fftw2")
345 find_package(FFTW2 REQUIRED)
347 find_package(FFTW2F REQUIRED)
351 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
352 endif(NOT FFTW2_FOUND)
353 include_directories(${FFTW2_INCLUDE_DIR})
354 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
356 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
357 set(FFTW2_NAME_DFFTW 1)
358 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
359 set(FFTW2_NAME_SFFTW 1)
360 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
361 set(FFTW2_NAME_FFTW 1)
362 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
365 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
366 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
367 find_package(MKL REQUIRED)
368 include_directories(${MKL_INCLUDE_DIR})
369 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
374 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
375 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
376 # set(GMX_FFT_ACML 1)
377 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
378 MESSAGE(STATUS "Using internal FFT library - fftpack")
379 set(GMX_FFT_FFTPACK 1)
380 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
381 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
382 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
384 # MKL has BLAS/LAPACK routines
385 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
386 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
387 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
388 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
389 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
390 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
391 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
393 # Math and thread libraries must often come after all others when linking...
395 list(APPEND GMX_EXTRA_LIBRARIES m)
401 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
402 "Path to swindirect.h")
403 include_directories(${COREWRAP_INCLUDE_DIR})
406 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
407 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
408 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
410 ########################################################################
411 # Specify install locations and which subdirectories to process #
412 ########################################################################
413 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
414 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
415 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
416 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
418 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
421 add_subdirectory(share)
422 add_subdirectory(include)
423 add_subdirectory(man)
425 add_subdirectory(src)