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)
181 find_library(ACCELERATE_FRAMEWORK Accelerate)
182 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
185 ########################################################################
186 # Our own GROMACS tests
187 ########################################################################
192 add_definitions( -DHAVE_CONFIG_H )
193 include_directories(${CMAKE_BINARY_DIR}/src)
194 include_directories(${CMAKE_SOURCE_DIR}/include)
196 include(gmxCheckBuildUserTime)
197 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
199 include(gmxTestFloatFormat)
200 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
201 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
202 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
204 include(gmxTestLargeFiles)
205 gmx_test_large_files(GMX_LARGEFILES)
207 include(gmxTestSignal)
208 gmx_test_retsigtype(RETSIGTYPE)
209 gmx_test_sigusr1(HAVE_SIGUSR1)
211 include(gmxTestInline)
212 gmx_test_inline(INLINE_KEYWORD)
214 include(gmxTestPipes)
215 gmx_test_pipes(HAVE_PIPES)
217 include(gmxTestInlineASM)
218 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
219 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
222 gmx_test_xdr(GMX_SYSTEM_XDR)
223 if(NOT GMX_SYSTEM_XDR)
224 set(GMX_INTERNAL_XDR 1)
225 endif(NOT GMX_SYSTEM_XDR)
227 if(GMX_FORTRAN OR GMX_POWER6)
228 enable_language(Fortran)
229 include(FortranCInterface)
230 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
231 if(extra_under_score)
233 endif(extra_under_score)
236 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
237 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
239 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
240 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
242 else(GMX_FORTRAN OR GMX_POWER6)
243 set(F77_FUNCDEF "name ## _")
244 set(F77_FUNCDEF_ "name ## _")
245 endif(GMX_FORTRAN OR GMX_POWER6)
248 # Process nonbonded accelerated kernels settings
249 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
250 if(${GMX_ACCELERATION} STREQUAL "NONE")
252 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
255 endif(HAVE_XMMINTRIN_H)
258 endif(HAVE_EMMINTRIN_H)
259 # if(HAVE_PMMINTRIN_H)
261 # endif(HAVE_PMMINTRIN_H)
262 # if(HAVE_SMMINTRIN_H)
264 # endif(HAVE_SMMINTRIN_H)
266 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
268 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
270 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
272 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
274 set(DISABLE_WATERWATER_NLIST 1)
275 set(DISABLE_WATER_NLIST 1)
276 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
277 check_include_files(altivec.h HAVE_ALTIVEC_H)
279 set(GMX_PPC_ALTIVEC 1)
280 endif(HAVE_ALTIVEC_H)
281 else(${GMX_ACCELERATION} STREQUAL "NONE")
282 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
283 endif(${GMX_ACCELERATION} STREQUAL "NONE")
291 # Process QM/MM Settings
292 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
293 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
294 set(GMX_QMMM_GAUSSIAN 1)
295 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
296 set(GMX_QMMM_MOPAC 1)
297 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
298 set(GMX_QMMM_GAMESS 1)
299 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
301 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
302 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
303 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
305 # Process FFT library settings
306 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
307 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
308 # MESSAGE(STATUS "Using external FFT library - fftw3")
310 find_package(FFTW3 REQUIRED)
312 find_package(FFTW3F REQUIRED)
316 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
317 endif(NOT FFTW3_FOUND)
320 include_directories(${FFTW3_INCLUDE_DIR})
321 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
323 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
324 # MESSAGE(STATUS "Using external FFT library - fftw2")
326 find_package(FFTW2 REQUIRED)
328 find_package(FFTW2F REQUIRED)
332 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
333 endif(NOT FFTW2_FOUND)
334 include_directories(${FFTW2_INCLUDE_DIR})
335 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
337 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
338 set(FFTW2_NAME_DFFTW 1)
339 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
340 set(FFTW2_NAME_SFFTW 1)
341 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
342 set(FFTW2_NAME_FFTW 1)
343 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
346 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
347 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
348 find_package(MKL REQUIRED)
349 include_directories(${MKL_INCLUDE_DIR})
350 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
355 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
356 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
357 # set(GMX_FFT_ACML 1)
358 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
359 MESSAGE(STATUS "Using internal FFT library - fftpack")
360 set(GMX_FFT_FFTPACK 1)
361 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
362 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
363 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
365 # MKL has BLAS/LAPACK routines
366 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
367 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
368 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
369 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
370 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
371 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
372 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
374 # Math and thread libraries must often come after all others when linking...
376 list(APPEND GMX_EXTRA_LIBRARIES m)
382 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
383 "Path to swindirect.h")
384 include_directories(${COREWRAP_INCLUDE_DIR})
387 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
388 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
389 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
391 ########################################################################
392 # Specify install locations and which subdirectories to process #
393 ########################################################################
394 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
395 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
396 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
397 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
399 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
402 add_subdirectory(share)
403 add_subdirectory(include)
404 add_subdirectory(man)
406 add_subdirectory(src)