1 cmake_minimum_required(VERSION 2.6)
4 set(PROJECT_VERSION "4.0.99_development_20090605"
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!)" OFF)
16 option(GMX_SOFTWARE_INVSQRT "Use GROMACS software 1/sqrt" ON)
17 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
18 set(GMX_ACCELERATION "none"
19 CACHE STRING "Accelerated kernels. Pick one of: SSE, BlueGene, Power6, ia64, altivec")
21 set(GMX_FFT_LIBRARY "fftw3"
22 CACHE STRING "FFT library choices: fftw3,fftw2,mkl,fftpack[built-in]")
23 option(GMX_DISABLE_FFTW_MEASURE
24 "Do not optimize FFTW setups (not needed with SSE)" OFF)
25 set(GMX_QMMM_PROGRAM "none"
26 CACHE STRING "QM package choices: none,gaussian,mopac,gamess")
27 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
28 option(BUILD_SHARED_LIBS "Enable shared libraries (can be problematic with MPI)" OFF)
29 option(GMX_MPI_IN_PLACE "Enable MPI_IN_PLACE for MPIs that have it defined" 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(sys/types.h HAVE_SYS_TYPES_H)
91 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
92 check_include_files(sys/time.h HAVE_SYS_TIME_H)
93 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
94 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
96 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
97 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
98 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
99 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
101 include(CheckFunctionExists)
102 check_function_exists(strcasecmp HAVE_STRCASECMP)
103 check_function_exists(strdup HAVE_STRDUP)
104 check_function_exists(vprintf HAVE_VPRINTF)
105 check_function_exists(memcmp HAVE_MEMCMP)
106 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
107 check_function_exists(isnan HAVE_ISNAN)
108 check_function_exists(_isnan HAVE__ISNAN)
109 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
111 include(CheckLibraryExists)
112 check_library_exists(m sqrt "" HAVE_LIBM)
114 include(CheckTypeSize)
115 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
116 check_type_size("int" SIZEOF_INT)
117 check_type_size("long int" SIZEOF_LONG_INT)
118 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
119 check_type_size("off_t" SIZEOF_OFF_T)
120 check_type_size("void *" SIZEOF_VOIDP)
122 # Check for some basic types that we *need*, so set these to int if they are not present
123 check_type_size(uid_t uid_t)
130 check_type_size(gid_t gid_t)
137 check_type_size(size_t size_t)
144 check_type_size(off_t off_t)
151 include(TestBigEndian)
152 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
156 ########################################################################
157 # Find external packages #
158 ########################################################################
160 find_package(LibXml2)
162 include_directories(${LIBXML2_INCLUDE_DIR})
163 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
168 # X11 includes/libraries are only set in the ngmx subdirectory!
175 set(THREAD_MPI_LIB thread_mpi)
177 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
178 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
179 message(FATAL_ERROR "FFTW2 can't be used with threads. Try fftw3 or mkl.")
185 find_library(ACCELERATE_FRAMEWORK Accelerate)
186 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
189 ########################################################################
190 # Our own GROMACS tests
191 ########################################################################
196 add_definitions( -DHAVE_CONFIG_H )
197 include_directories(${CMAKE_BINARY_DIR}/src)
198 include_directories(${CMAKE_SOURCE_DIR}/include)
200 include(gmxCheckBuildUserTime)
201 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
203 include(gmxTestFloatFormat)
204 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
205 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
206 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
208 include(gmxTestLargeFiles)
209 gmx_test_large_files(GMX_LARGEFILES)
211 include(gmxTestSignal)
212 gmx_test_retsigtype(RETSIGTYPE)
213 gmx_test_sigusr1(HAVE_SIGUSR1)
215 include(gmxTestInline)
216 gmx_test_inline(INLINE_KEYWORD)
218 include(gmxTestPipes)
219 gmx_test_pipes(HAVE_PIPES)
221 include(gmxTestInlineASM)
222 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
223 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
226 gmx_test_xdr(GMX_SYSTEM_XDR)
227 if(NOT GMX_SYSTEM_XDR)
228 set(GMX_INTERNAL_XDR 1)
229 endif(NOT GMX_SYSTEM_XDR)
231 if(GMX_FORTRAN OR GMX_POWER6)
232 enable_language(Fortran)
233 include(FortranCInterface)
234 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
235 if(extra_under_score)
237 endif(extra_under_score)
240 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
241 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
243 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
244 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
246 else(GMX_FORTRAN OR GMX_POWER6)
247 set(F77_FUNCDEF "name ## _")
248 set(F77_FUNCDEF_ "name ## _")
249 endif(GMX_FORTRAN OR GMX_POWER6)
252 # Process nonbonded accelerated kernels settings
253 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
254 if(${GMX_ACCELERATION} STREQUAL "NONE")
256 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
259 endif(HAVE_XMMINTRIN_H)
262 endif(HAVE_EMMINTRIN_H)
263 # if(HAVE_PMMINTRIN_H)
265 # endif(HAVE_PMMINTRIN_H)
266 # if(HAVE_SMMINTRIN_H)
268 # endif(HAVE_SMMINTRIN_H)
270 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
272 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
274 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
276 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
278 set(DISABLE_WATERWATER_NLIST 1)
279 set(DISABLE_WATER_NLIST 1)
280 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
281 check_include_files(altivec.h HAVE_ALTIVEC_H)
283 set(GMX_PPC_ALTIVEC 1)
284 endif(HAVE_ALTIVEC_H)
285 else(${GMX_ACCELERATION} STREQUAL "NONE")
286 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
287 endif(${GMX_ACCELERATION} STREQUAL "NONE")
295 # Process QM/MM Settings
296 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
297 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
298 set(GMX_QMMM_GAUSSIAN 1)
299 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
300 set(GMX_QMMM_MOPAC 1)
301 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
302 set(GMX_QMMM_GAMESS 1)
303 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
305 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
306 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
307 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
309 # Process FFT library settings
310 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
311 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
312 # MESSAGE(STATUS "Using external FFT library - fftw3")
314 find_package(FFTW3 REQUIRED)
316 find_package(FFTW3F REQUIRED)
320 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
321 endif(NOT FFTW3_FOUND)
324 include_directories(${FFTW3_INCLUDE_DIR})
325 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
327 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
328 # MESSAGE(STATUS "Using external FFT library - fftw2")
330 find_package(FFTW2 REQUIRED)
332 find_package(FFTW2F REQUIRED)
336 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
337 endif(NOT FFTW2_FOUND)
338 include_directories(${FFTW2_INCLUDE_DIR})
339 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
341 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
342 set(FFTW2_NAME_DFFTW 1)
343 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
344 set(FFTW2_NAME_SFFTW 1)
345 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
346 set(FFTW2_NAME_FFTW 1)
347 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
350 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
351 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
352 find_package(MKL REQUIRED)
353 include_directories(${MKL_INCLUDE_DIR})
354 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
359 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
360 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
361 # set(GMX_FFT_ACML 1)
362 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
363 MESSAGE(STATUS "Using internal FFT library - fftpack")
364 set(GMX_FFT_FFTPACK 1)
365 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
366 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
367 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
369 # MKL has BLAS/LAPACK routines
370 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
371 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
372 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
373 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
374 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
375 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
376 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
378 # Math and thread libraries must often come after all others when linking...
380 list(APPEND GMX_EXTRA_LIBRARIES m)
386 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
387 "Path to swindirect.h")
388 include_directories(${COREWRAP_INCLUDE_DIR})
391 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
392 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
393 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
395 ########################################################################
396 # Specify install locations and which subdirectories to process #
397 ########################################################################
398 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
399 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
400 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
401 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
403 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
406 add_subdirectory(share)
407 add_subdirectory(include)
408 add_subdirectory(man)
410 add_subdirectory(src)