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_THREADED "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)
32 ########################################################################
33 # Fix stupid flags on MSVC
34 ########################################################################
35 IF(CMAKE_GENERATOR MATCHES "Visual Studio")
36 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
37 SET(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
38 STRING(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
39 SET(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
40 ENDIF(CMAKE_GENERATOR MATCHES "Visual Studio")
42 set(GMX_EXTRA_LIBRARIES)
44 ########################################################################
46 ########################################################################
49 message(FATAL_ERROR "Thread-based parallelization conflicts with MPI.")
53 set(GROMACS_C_FLAGS ${GROMACS_FLAGS} ${MPI_COMPILE_FLAGS})
54 set(GROMACS_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} ${MPI_LINK_FLAGS})
55 include_directories(${MPI_INCLUDE_PATH})
56 list(APPEND GMX_EXTRA_LIBRARIES ${MPI_LIBRARIES})
57 add_definitions( -DMPI ) #for FAHCORE
59 message(FATAL_ERROR "MPI support requested, but no MPI compiler found.")
61 include(gmxTestCatamount)
62 gmx_test_catamount(GMX_CRAY_XT3)
70 ########################################################################
71 # Basic system tests (standard libraries, headers, functions, types) #
72 ########################################################################
73 include(CheckIncludeFiles)
74 check_include_files(string.h HAVE_STRING_H)
75 check_include_files(limits.h HAVE_LIMITS_H)
76 check_include_files(memory.h HAVE_MEMORY_H)
77 check_include_files(unistd.h HAVE_UNISTD_H)
78 check_include_files(pwd.h HAVE_PWD_H)
79 check_include_files(stdint.h HAVE_STDINT_H)
80 check_include_files(stdlib.h HAVE_STDLIB_H)
81 check_include_files(pthread.h HAVE_PTHREAD_H)
82 check_include_files(inttypes.h HAVE_INTTYPES_H)
83 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
84 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
85 check_include_files(rpc/rpc.h HAVE_RPC_RPC_H)
86 check_include_files("rpc/rpc.h;rpc/xdr.h" HAVE_RPC_XDR_H)
88 check_include_files(xmmintrin.h HAVE_XMMINTRIN_H)
89 check_include_files(emmintrin.h HAVE_EMMINTRIN_H)
90 check_include_files(pmmintrin.h HAVE_PMMINTRIN_H)
91 check_include_files(smmintrin.h HAVE_SMMINTRIN_H)
93 include(CheckFunctionExists)
94 check_function_exists(strcasecmp HAVE_STRCASECMP)
95 check_function_exists(strdup HAVE_STRDUP)
96 check_function_exists(vprintf HAVE_VPRINTF)
97 check_function_exists(memcmp HAVE_MEMCMP)
98 # After large files? check_function_exists(fseeko HAVE_FSEEKO)
100 include(CheckLibraryExists)
101 check_library_exists(m sqrt "" HAVE_LIBM)
103 include(CheckTypeSize)
104 check_type_size("bool" SIZEOF_BOOL) # will also set HAVE_BOOL
105 check_type_size("int" SIZEOF_INT)
106 check_type_size("long int" SIZEOF_LONG_INT)
107 check_type_size("long long int" SIZEOF_LONG_LONG_INT)
108 check_type_size("off_t" SIZEOF_OFF_T)
110 # Check for some basic types that we *need*, so set these to int if they are not present
111 check_type_size(uid_t uid_t)
118 check_type_size(gid_t gid_t)
125 check_type_size(size_t size_t)
132 check_type_size(off_t off_t)
139 include(TestBigEndian)
140 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
144 ########################################################################
145 # Find external packages #
146 ########################################################################
148 find_package(LibXml2)
150 include_directories(${LIBXML2_INCLUDE_DIR})
151 list(APPEND GMX_EXTRA_LIBRARIES ${LIBXML2_LIBRARIES})
156 # X11 includes/libraries are only set in the ngmx subdirectory!
162 find_package(Pthreads)
164 include_directories(${PTHREADS_INCLUDE_DIR})
165 list(APPEND GMX_EXTRA_LIBRARIES ${PTHREADS_LIBRARIES})
167 set(GMX_THREAD_PTHREADS 1)
169 set(GMX_THREAD_MPI 1)
174 message(FATAL_ERROR "Thread-based parallelization requested, but no threads library found.")
176 endif(PTHREADS_FOUND)
179 find_library(ACCELERATE_FRAMEWORK Accelerate)
180 list(APPEND GMX_EXTRA_LIBRARIES ${ACCELERATE_FRAMEWORK})
183 ########################################################################
184 # Our own GROMACS tests
185 ########################################################################
190 add_definitions( -DHAVE_CONFIG_H )
191 include_directories(${CMAKE_BINARY_DIR}/src)
192 include_directories(${CMAKE_SOURCE_DIR}/include)
194 include(gmxCheckBuildUserTime)
195 gmx_check_build_user_time(BUILD_TIME BUILD_USER BUILD_MACHINE)
197 include(gmxTestFloatFormat)
198 gmx_test_float_format(GMX_FLOAT_FORMAT_IEEE754
199 GMX_IEEE754_BIG_ENDIAN_BYTE_ORDER
200 GMX_IEEE754_BIG_ENDIAN_WORD_ORDER)
202 include(gmxTestLargeFiles)
203 gmx_test_large_files(GMX_LARGEFILES)
205 include(gmxTestSignal)
206 gmx_test_retsigtype(RETSIGTYPE)
207 gmx_test_sigusr1(HAVE_SIGUSR1)
209 include(gmxTestInline)
210 gmx_test_inline(INLINE_KEYWORD)
212 include(gmxTestPipes)
213 gmx_test_pipes(HAVE_PIPES)
215 include(gmxTestInlineASM)
216 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
217 gmx_test_inline_asm_msvc_x86(GMX_X86_MSVC_INLINE_ASM)
220 gmx_test_xdr(GMX_SYSTEM_XDR)
221 if(NOT GMX_SYSTEM_XDR)
222 set(GMX_INTERNAL_XDR 1)
223 endif(NOT GMX_SYSTEM_XDR)
225 if(GMX_FORTRAN OR GMX_POWER6)
226 enable_language(Fortran)
227 include(FortranCInterface)
228 discover_fortran_mangling(prefix isupper suffix extra_under_score found)
229 if(extra_under_score)
231 endif(extra_under_score)
234 set(F77_FUNCDEF "${prefix} ## NAME ## ${suffix}")
235 set(F77_FUNCDEF_ "${prefix} ## NAME ## ${suffix}${extrasuffix}")
237 set(F77_FUNCDEF "${prefix} ## name ## ${suffix}")
238 set(F77_FUNCDEF_ "${prefix} ## name ## ${suffix}${extrasuffix}")
240 else(GMX_FORTRAN OR GMX_POWER6)
241 set(F77_FUNCDEF "name ## _")
242 set(F77_FUNCDEF_ "name ## _")
243 endif(GMX_FORTRAN OR GMX_POWER6)
246 # Process nonbonded accelerated kernels settings
247 string(TOUPPER ${GMX_ACCELERATION} ${GMX_ACCELERATION})
248 if(${GMX_ACCELERATION} STREQUAL "NONE")
250 elseif(${GMX_ACCELERATION} STREQUAL "SSE")
253 endif(HAVE_XMMINTRIN_H)
256 endif(HAVE_EMMINTRIN_H)
257 # if(HAVE_PMMINTRIN_H)
259 # endif(HAVE_PMMINTRIN_H)
260 # if(HAVE_SMMINTRIN_H)
262 # endif(HAVE_SMMINTRIN_H)
264 elseif(${GMX_ACCELERATION} STREQUAL "FORTRAN")
266 elseif(${GMX_ACCELERATION} STREQUAL "BLUEGENE")
268 elseif(${GMX_ACCELERATION} STREQUAL "POWER6")
270 elseif(${GMX_ACCELERATION} STREQUAL "IA64")
272 set(DISABLE_WATERWATER_NLIST 1)
273 set(DISABLE_WATER_NLIST 1)
274 elseif(${GMX_ACCELERATION} STREQUAL "ALTIVEC")
275 check_include_files(altivec.h HAVE_ALTIVEC_H)
277 set(GMX_PPC_ALTIVEC 1)
278 endif(HAVE_ALTIVEC_H)
279 else(${GMX_ACCELERATION} STREQUAL "NONE")
280 MESSAGE(FATAL_ERROR "Unrecognized option for accelerated kernels: ${GMX_ACCELERATION}. Pick one of none, SSE, Fortran, BlueGene, Power6, ia64, altivec")
281 endif(${GMX_ACCELERATION} STREQUAL "NONE")
289 # Process QM/MM Settings
290 string(TOUPPER ${GMX_QMMM_PROGRAM} ${GMX_QMMM_PROGRAM})
291 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
292 set(GMX_QMMM_GAUSSIAN 1)
293 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
294 set(GMX_QMMM_MOPAC 1)
295 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
296 set(GMX_QMMM_GAMESS 1)
297 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
299 else(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
300 MESSAGE(FATAL_ERROR "Invalid QM/MM program option: ${GMX_QMMM_PROGRAM}. Choose one of: Gaussian, Mopac, Gamess, None")
301 endif(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
303 # Process FFT library settings
304 string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
305 if(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
306 # MESSAGE(STATUS "Using external FFT library - fftw3")
308 find_package(FFTW3 REQUIRED)
310 find_package(FFTW3F REQUIRED)
314 MESSAGE(FATAL_ERROR "Cannot find fftw3 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
315 endif(NOT FFTW3_FOUND)
318 include_directories(${FFTW3_INCLUDE_DIR})
319 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW3_LIBRARIES})
321 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTW2")
322 # MESSAGE(STATUS "Using external FFT library - fftw2")
324 find_package(FFTW2 REQUIRED)
326 find_package(FFTW2F REQUIRED)
330 MESSAGE(FATAL_ERROR "Cannot find fftw2 (with correct precision). Fix it, choose another FFT library, or use the Gromacs built-in fftpack (slower)!")
331 endif(NOT FFTW2_FOUND)
332 include_directories(${FFTW2_INCLUDE_DIR})
333 list(APPEND GMX_EXTRA_LIBRARIES ${FFTW2_LIBRARIES})
335 if("${FFTW2_LIBRARIES}" MATCHES "dfftw")
336 set(FFTW2_NAME_DFFTW 1)
337 elseif("${FFTW2_LIBRARIES}" MATCHES "sfftw")
338 set(FFTW2_NAME_SFFTW 1)
339 else("${FFTW2_LIBRARIES}" MATCHES "dfftw")
340 set(FFTW2_NAME_FFTW 1)
341 endif("${FFTW2_LIBRARIES}" MATCHES "dfftw")
344 elseif(${GMX_FFT_LIBRARY} STREQUAL "MKL")
345 # MESSAGE(STATUS "Using external FFT library - Intel MKL")
346 find_package(MKL REQUIRED)
347 include_directories(${MKL_INCLUDE_DIR})
348 list(APPEND GMX_EXTRA_LIBRARIES ${MKL_LIBRARIES})
353 #elseif(${GMX_FFT_LIBRARY} STREQUAL "ACML")
354 # MESSAGE(STATUS "Using external FFT library - AMD core math library")
355 # set(GMX_FFT_ACML 1)
356 elseif(${GMX_FFT_LIBRARY} STREQUAL "FFTPACK")
357 MESSAGE(STATUS "Using internal FFT library - fftpack")
358 set(GMX_FFT_FFTPACK 1)
359 else(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
360 MESSAGE(FATAL_ERROR "Invalid FFT library setting: ${GMX_FFT_LIBRARY}. Choose one of: fftw3, fftw2, mkl, acml, fftpack")
361 endif(${GMX_FFT_LIBRARY} STREQUAL "FFTW3")
363 # MKL has BLAS/LAPACK routines
364 if(HAVE_MKL OR ACCELERATE_FRAMEWORK)
365 set(GMX_EXTERNAL_BLAS TRUE CACHE BOOL "Use external BLAS instead of built-in")
366 set(GMX_EXTERNAL_LAPACK TRUE CACHE BOOL "Use external LAPACK instead of built-in")
367 else(HAVE_MKL OR ACCELERATE_FRAMEWORK)
368 set(GMX_EXTERNAL_BLAS FALSE CACHE BOOL "Use external LAPACK instead of built-in")
369 set(GMX_EXTERNAL_LAPACK FALSE CACHE BOOL "Use external LAPACK instead of built-in")
370 endif(HAVE_MKL OR ACCELERATE_FRAMEWORK)
372 # Math and thread libraries must often come after all others when linking...
374 list(APPEND GMX_EXTRA_LIBRARIES m)
379 set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
380 "Path to swindirect.h")
381 include_directories(${COREWRAP_INCLUDE_DIR})
384 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
385 set(CMAKE_C_FLAGS ${GROMACS_C_FLAGS} CACHE STRING "Compiler flags")
386 set(CMAKE_EXE_LINKER_FLAGS ${GROMACS_LINKER_FLAGS} CACHE STRING "Linker flags")
388 ########################################################################
389 # Specify install locations and which subdirectories to process #
390 ########################################################################
391 set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
392 set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
393 set(DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/gromacs)
394 set(MAN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/share/man)
396 set(GMXLIBDIR ${DATA_INSTALL_DIR}/top)
399 add_subdirectory(share)
400 add_subdirectory(include)
401 add_subdirectory(man)
403 add_subdirectory(src)