Add bool useDomainDecomposition in mdrunner
[gromacs.git] / CMakeLists.txt
blob9ea85fe4b9b96ceb6444567b13b2bb98bebf26db
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 cmake_minimum_required(VERSION 3.9.6)
36 if(POLICY CMP0074) #3.12
37     cmake_policy(SET CMP0074 NEW)
38 endif()
39 cmake_policy(SET CMP0068 NEW) # From CMake-3.9
41 # CMake modules/macros are in a subdirectory to keep this file cleaner
42 # This needs to be set before project() in order to pick up toolchain files
43 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Platform)
45 project(Gromacs)
47 set(CMAKE_CXX_STANDARD 14)
48 set(CMAKE_CXX_STANDARD_REQUIRED ON)
49 set(CMAKE_CXX_EXTENSIONS OFF)
51 include(gmxManageCcache)
53 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
54 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
55 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
57 find_package(LibStdCpp)
59 # Set up common version variables, as well as general information about
60 # the build tree (whether the build is from a source package or from a git
61 # repository).  Also declares a few functions that will be used for generating
62 # version info files later.
63 include(gmxBuildTreeInfo)
64 include(gmxVersionInfo)
66 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
67     set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
68 endif()
69 if("${CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_BINARY_DIR}")
70     message(FATAL_ERROR "GROMACS cannot be installed into the build tree, choose a different location for CMAKE_INSTALL_PREFIX")
71 endif()
73 include(gmxBuildTypeReference)
74 include(gmxBuildTypeProfile)
75 include(gmxBuildTypeTSAN)
76 include(gmxBuildTypeASAN)
77 include(gmxBuildTypeMSAN)
78 include(gmxBuildTypeReleaseWithAssert)
80 if(NOT CMAKE_BUILD_TYPE)
81     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Reference RelWithAssert Profile TSAN ASAN MSAN." FORCE)
82     # Set the possible values of build type for cmake-gui
83     set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
84         "MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert" "Profile" "TSAN" "ASAN" "MSAN")
85 endif()
86 if(CMAKE_CONFIGURATION_TYPES)
87     # Add appropriate GROMACS-specific build types for the Visual
88     # Studio generator (Debug, Release, MinSizeRel and RelWithDebInfo
89     # are already present by default).
90     list(APPEND CMAKE_CONFIGURATION_TYPES "RelWithAssert" "Reference")
91     list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
92     set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
93         "List of configuration types"
94         FORCE)
95 endif()
96 set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBINFO RELWITHASSERT MINSIZEREL PROFILE)
98 set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
100 include(gmxCTestUtilities)
101 gmx_ctest_init()
103 include(gmxCPackUtilities)
104 gmx_cpack_init()
106 # Variables that accumulate stuff influencing the installed headers
107 set(INSTALLED_HEADER_INCLUDE_DIRS "")
108 set(INSTALLED_HEADER_DEFINITIONS "")
110 ########################################################################
111 # Global non-cache variables for implementing the build system
112 ########################################################################
114 # These variables collect libraries that GROMACS requires for
115 # linking. They should be appended to with list(APPEND ${name}
116 # new-library) calls. They are:
117 #  - Libraries that are required for libgromacs (only)
118 set(GMX_EXTRA_LIBRARIES "")
119 #  - Libraries that are required for all code in the repository
120 set(GMX_COMMON_LIBRARIES "")
121 #  - Libraries that all code linked against libgromacs needs
122 #    (i.e., something that is exposed in installed headers).
123 set(GMX_PUBLIC_LIBRARIES "")
125 ########################################################################
126 # Check and warn if cache generated on a different host is being reused
127 ########################################################################
128 if(CMAKE_HOST_UNIX)
129     execute_process(COMMAND hostname
130                     OUTPUT_VARIABLE TMP_HOSTNAME
131                     OUTPUT_STRIP_TRAILING_WHITESPACE)
132     if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "${TMP_HOSTNAME}")
133         message(WARNING "
134             The CMake cache, probably generated on a different host (${GMX_BUILD_HOSTNAME}),
135             is being reused! This could lead to inconsistencies; therefore, it is
136             recommended to regenerate the cache!")
137     endif()
138     set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
139             "Hostname of the machine where the cache was generated.")
140 endif()
142 ########################################################################
143 # Detect architecture before setting options so we can alter defaults
144 ########################################################################
145 # Detect the architecture the compiler is targetting, detect
146 # SIMD instructions possibilities on that hardware, suggest SIMD instruction set
147 # to use if none is specified, and populate the cache option for CPU
148 # SIMD.
149 include(gmxDetectTargetArchitecture)
150 gmx_detect_target_architecture()
152 ########################################################################
153 # User input options                                                   #
154 ########################################################################
155 include(gmxOptionUtilities)
157 set(CMAKE_PREFIX_PATH "" CACHE STRING "Extra locations to search for external libraries and tools (give directory without lib, bin, or include)")
159 # Fujitsu only has SIMD in double precision, so this will be faster
160 gmx_set_boolean(GMX_DOUBLE_DEFAULT GMX_TARGET_FUJITSU_SPARC64)
161 option(GMX_DOUBLE "Use double precision (much slower, use only if you really need it)" ${GMX_DOUBLE_DEFAULT})
162 option(GMX_RELAXED_DOUBLE_PRECISION "Accept single precision 1/sqrt(x) when using Fujitsu HPC-ACE SIMD" OFF)
163 mark_as_advanced(GMX_RELAXED_DOUBLE_PRECISION)
165 option(GMX_MPI    "Build a parallel (message-passing) version of GROMACS" OFF)
166 option(GMX_THREAD_MPI  "Build a thread-MPI-based multithreaded version of GROMACS (not compatible with MPI)" ON)
167 gmx_dependent_option(
168     GMX_MPI_IN_PLACE
169     "Enable MPI_IN_PLACE for MPIs that have it defined"
170     ON
171     GMX_MPI)
172 mark_as_advanced(GMX_MPI_IN_PLACE)
174 option(GMX_MIMIC "Enable MiMiC QM/MM interface (CPMD is required)" OFF)
176 option(GMX_FAHCORE "Build a library with mdrun functionality" OFF)
177 mark_as_advanced(GMX_FAHCORE)
179 option(GMX_COOL_QUOTES "Enable GROMACS cool quotes" ON)
180 mark_as_advanced(GMX_COOL_QUOTES)
181 gmx_add_cache_dependency(GMX_COOL_QUOTES BOOL "NOT GMX_FAHCORE" OFF)
183 option(GMX_USE_OPENCL "Enable OpenCL acceleration" OFF)
185 option(GMX_INSTALL_LEGACY_API "Install legacy headers" OFF)
187 # The earliest version of the CUDA toolkit that supports c++14 is 9.0
188 set(REQUIRED_CUDA_VERSION 9.0)
189 set(REQUIRED_CUDA_COMPUTE_CAPABILITY 3.0)
191 # OpenCL required version: 1.2 or newer
192 set(REQUIRED_OPENCL_MIN_VERSION_MAJOR 1)
193 set(REQUIRED_OPENCL_MIN_VERSION_MINOR 2)
194 set(REQUIRED_OPENCL_MIN_VERSION ${REQUIRED_OPENCL_MIN_VERSION_MAJOR}.${REQUIRED_OPENCL_MIN_VERSION_MINOR})
196 if(NOT GMX_USE_OPENCL)
197     # CUDA detection is done only if GMX_USE_OPENCL is OFF.
198     include(gmxManageGPU)
199     set(GMX_USE_CUDA ${GMX_GPU})
200     if(GMX_GPU)
201         set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_CUDA")
202     else()
203         set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_NONE")
204     endif()
205 else()
206     #Now the OpenCL path (for both AMD and NVIDIA)
207     if(GMX_GPU)
208         include(gmxManageOpenCL)
209         set(GMX_GPU_ACCELERATION_FRAMEWORK "GMX_GPU_OPENCL")
210     else()
211         message(FATAL_ERROR "OpenCL requested but GPU option is not enabled (try -DGMX_GPU=on) ")
212     endif()
213 endif()
215 gmx_option_multichoice(
216     GMX_SIMD
217     "SIMD instruction set for CPU kernels and compiler optimization"
218     "AUTO"
219     AUTO None SSE2 SSE4.1 AVX_128_FMA AVX_256 AVX2_256 AVX2_128 AVX_512 AVX_512_KNL MIC ARM_NEON ARM_NEON_ASIMD IBM_VMX IBM_VSX Sparc64_HPC_ACE Reference)
221 if(GMX_TARGET_MIC)
222     set(GMX_FFT_LIBRARY_DEFAULT "mkl")
223 else()
224     set(GMX_FFT_LIBRARY_DEFAULT "fftw3")
225 endif()
227 gmx_option_multichoice(
228     GMX_FFT_LIBRARY
229     "FFT library"
230     "${GMX_FFT_LIBRARY_DEFAULT}"
231     fftw3 mkl "fftpack[built-in]")
232 gmx_dependent_option(
233     GMX_BUILD_OWN_FFTW
234     "Download and build FFTW 3 during the GROMACS build process, rather than fall back on the really slow fftpack."
235     OFF
236     "GMX_FFT_LIBRARY STREQUAL FFTW3")
237 gmx_dependent_option(
238     GMX_DISABLE_FFTW_MEASURE
239     "Do not optimize FFTW setups (not needed with SSE)"
240     OFF
241     "GMX_FFT_LIBRARY STREQUAL FFTW3")
242 mark_as_advanced(GMX_BUILD_OWN_FFTW)
243 mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
245 gmx_option_multichoice(
246     GMX_QMMM_PROGRAM
247     "QM package for QM/MM"
248     None
249     none gaussian mopac gamess orca)
251 gmx_dependent_cache_variable(GMX_SIMD_REF_FLOAT_WIDTH  "Reference SIMD single precision width" STRING "4" "GMX_SIMD STREQUAL REFERENCE")
252 gmx_dependent_cache_variable(GMX_SIMD_REF_DOUBLE_WIDTH "Reference SIMD double precision width" STRING "2" "GMX_SIMD STREQUAL REFERENCE")
254 # This should be moved to a separate NBNXN cmake module when that code is cleaned up and modularized
256 option(GMX_BROKEN_CALLOC "Work around broken calloc()" OFF)
257 mark_as_advanced(GMX_BROKEN_CALLOC)
259 option(GMX_OPENMP "Enable OpenMP-based multithreading" ON)
261 option(GMX_USE_TNG "Use the TNG library for trajectory I/O" ON)
263 option(GMX_BUILD_MDRUN_ONLY "Build and install only the mdrun binary" OFF)
265 option(GMX_CYCLE_SUBCOUNTERS "Enable cycle subcounters to get a more detailed cycle timings" OFF)
266 mark_as_advanced(GMX_CYCLE_SUBCOUNTERS)
268 option(GMX_SKIP_DEFAULT_CFLAGS "Don't automatically add suggested/required Compiler flags." OFF)
269 mark_as_advanced(GMX_SKIP_DEFAULT_CFLAGS)
271 option(GMX_BUILD_FOR_COVERAGE
272        "Tune build for better code coverage metrics (e.g., disable asserts)"
273        OFF)
274 mark_as_advanced(GMX_BUILD_FOR_COVERAGE)
276 option(GMX_DEVELOPER_BUILD
277     "Enable Developer convenience features: always build unit-tests"
278     OFF)
279 mark_as_advanced(GMX_DEVELOPER_BUILD)
281 gmx_set_boolean(GMX_COMPILER_WARNINGS_DEFAULT "NOT SOURCE_IS_SOURCE_DISTRIBUTION")
282 option(GMX_COMPILER_WARNINGS
283     "Enable a default set of compiler warnings"
284     ${GMX_COMPILER_WARNINGS_DEFAULT})
285 mark_as_advanced(GMX_COMPILER_WARNINGS)
286 # Always turn on compiler warnings with a developer build.
287 gmx_add_cache_dependency(GMX_COMPILER_WARNINGS BOOL "NOT GMX_DEVELOPER_BUILD" ON)
289 option(GMX_BUILD_SHARED_EXE
290     "Build exectuables as shared binaries. If not set, this disables rpath and dynamic linker flags in an attempt to build a static binary, but this may require setting up the toolchain properly and making appropriate libraries available."
291     ON)
292 mark_as_advanced(GMX_BUILD_SHARED_EXE)
294 option(GMX_PHYSICAL_VALIDATION
295        "Include physical validation tests in ctest environment. These can then be called using 'make check-phys' or
296        'make check-all'. Warning: Running the physical validation tests takes significantly more time than other tests!"
297        OFF)
298 mark_as_advanced(GMX_PHYSICAL_VALIDATION)
300 ######################################################################
301 # Detect OpenMP support
302 ######################################################################
303 # The OpenMP detection _must_ come before tests for other CFLAGS.
304 include(gmxManageOpenMP)
308 ######################################################################
309 # Compiler tests
310 # These need to be done early (before further tests).
311 #####################################################################
313 include(gmxCFlags)
314 gmx_c_flags()
316 # These variables should be used for CMake-style lists (ie. separated
317 # by semicolons) of additional compiler flags which are not generated
318 # in gmxCFlags nor are SIMD or MPI related.
320 # TODO These variables should be consolidated into
321 # EXTRA_COMPILER_FLAGS so that we we don't perpetrate bugs where
322 # things that work in C compilation (e.g. merging from old branches)
323 # might not also work for C++ compilation.
324 set(EXTRA_C_FLAGS "")
325 set(EXTRA_CXX_FLAGS "")
327 # Run through a number of tests for buggy compilers and other issues
328 include(gmxTestCompilerProblems)
329 gmx_test_compiler_problems()
331 # Implement double-precision option. This is complicated because we
332 # need installed headers to use the precision mode of the build that
333 # produced the library, but cannot use config.h in that case. We also
334 # want such variables to always have a definition, because #if is more
335 # robust than #ifdef. So, we put this value on the compiler command
336 # line in all cases.
338 # GMX_RELAXED_DOUBLE_PRECISION does not need to be handled here,
339 # because no installed header needs it
340 if(GMX_DOUBLE)
341     set(GMX_DOUBLE_VALUE 1)
342 else()
343     set(GMX_DOUBLE_VALUE 0)
344 endif()
345 add_definitions(-DGMX_DOUBLE=${GMX_DOUBLE_VALUE})
346 list(APPEND INSTALLED_HEADER_DEFINITIONS "-DGMX_DOUBLE=${GMX_DOUBLE_VALUE}")
348 option(GMX_IMD "Enable Interactive Molecular Dynamics (IMD) sessions, e.g. with VMD" ON)
349 if(GMX_IMD AND WIN32)
350     list(APPEND GMX_EXTRA_LIBRARIES "wsock32")
351 endif()
355 ########################################################################
356 # Basic system tests (standard libraries, headers, functions, types)   #
357 ########################################################################
358 include(CheckIncludeFiles)
359 include(CheckIncludeFileCXX)
360 check_include_files(unistd.h     HAVE_UNISTD_H)
361 check_include_files(pwd.h        HAVE_PWD_H)
362 check_include_files(dirent.h     HAVE_DIRENT_H)
363 check_include_files(time.h       HAVE_TIME_H)
364 check_include_files(sys/time.h   HAVE_SYS_TIME_H)
365 check_include_files(io.h         HAVE_IO_H)
366 check_include_files(sched.h      HAVE_SCHED_H)
367 check_include_files(xmmintrin.h  HAVE_XMMINTRIN_H)
369 include(CheckCXXSymbolExists)
370 check_cxx_symbol_exists(gettimeofday      sys/time.h   HAVE_GETTIMEOFDAY)
371 check_cxx_symbol_exists(sysconf           unistd.h     HAVE_SYSCONF)
372 check_cxx_symbol_exists(nice              unistd.h     HAVE_NICE)
373 check_cxx_symbol_exists(fsync             unistd.h     HAVE_FSYNC)
374 check_cxx_symbol_exists(_fileno           stdio.h      HAVE__FILENO)
375 check_cxx_symbol_exists(fileno            stdio.h      HAVE_FILENO)
376 check_cxx_symbol_exists(_commit           io.h         HAVE__COMMIT)
377 check_cxx_symbol_exists(sigaction         signal.h     HAVE_SIGACTION)
379 # We cannot check for the __builtins as symbols, but check if code compiles
380 check_cxx_source_compiles("int main(){ return __builtin_clz(1);}"   HAVE_BUILTIN_CLZ)
381 check_cxx_source_compiles("int main(){ return __builtin_clzll(1);}" HAVE_BUILTIN_CLZLL)
382 if(MSVC)
383     check_cxx_source_compiles("#include <intrin.h>\n int main(){unsigned long r;unsigned long i=1;_BitScanReverse(&r,i);return r;}" HAVE_BITSCANREVERSE)
384     check_cxx_source_compiles("#include <intrin.h>\n int main(){unsigned long r;unsigned __int64 i=1;_BitScanReverse(&r,i);return r;}" HAVE_BITSCANREVERSE64)
385 elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
386     check_cxx_source_compiles("int main(){ return __cntlz4(1);}" HAVE_CNTLZ4)
387     check_cxx_source_compiles("int main(){ return __cntlz8(1);}" HAVE_CNTLZ8)
388 endif()
390 include(CheckLibraryExists)
391 find_library(HAVE_LIBM m)
392 mark_as_advanced(HAVE_LIBM)
393 check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
394 check_library_exists(m feenableexcept "" HAVE_FEENABLEEXCEPT)
395 check_library_exists(m fedisableexcept "" HAVE_FEDISABLEEXCEPT)
397 include(TestSchedAffinity)
398 test_sched_affinity(HAVE_SCHED_AFFINITY)
400 # Aligned memory allocation. We need to check for both mm_malloc(),
401 # posix_memalign(), memalign(), and on windows also _aligned_malloc()
402 include(gmxTestMMMalloc)
403 gmx_test_mm_malloc(HAVE__MM_MALLOC)
404 check_cxx_symbol_exists(posix_memalign    stdlib.h     HAVE_POSIX_MEMALIGN)
405 check_cxx_symbol_exists(memalign          stdlib.h     HAVE_MEMALIGN)
406 if(MSVC)
407     # No need to waste time on this test on platforms where it will never be true
408     check_cxx_symbol_exists(_aligned_malloc   stdlib.h     HAVE__ALIGNED_MALLOC)
409 endif()
411 include(TestBigEndian)
412 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
414 gmx_set_boolean(GMX_USE_NICE "HAVE_UNISTD_H AND HAVE_NICE")
416 # Management of GROMACS options for specific toolchains should go
417 # here. Because the initial settings for some of the main options have
418 # already happened, but things like library detection and MPI compiler
419 # feature detection have not, the docstrings for any over-rides of
420 # GROMACS defaults or user settings will make sense. Also, any
421 # toolchain-related reasons for choosing whether to detect various
422 # things can be sorted out now, before the detection takes place.
423 if(GMX_TARGET_FUJITSU_SPARC64)
424     include(gmxManageFujitsuSparc64)
425 endif()
427 ########################################################################
428 #Process MPI settings
429 ########################################################################
430 include(gmxManageMPI)
432 ########################################################################
433 #Process MiMiC settings
434 ########################################################################
435 include(gmxManageMimic)
437 ########################################################################
438 #Process shared/static library settings
439 ########################################################################
440 include(gmxManageSharedLibraries)
443 ########################################################################
444 # Find external packages                                               #
445 ########################################################################
447 # Unconditionally find the package, as it is also required for unit
448 # tests. This exports LIBXML2_FOUND, which we should not use because
449 # it does not tell us that linking will succeed. Instead, we test that
450 # next.
451 #if(DEFINED LIBXML2_LIBRARIES)
452 #  set(LibXml2_FIND_QUIETLY TRUE)
453 #endif()
454 #find_package(LibXml2)
455 #include(gmxTestLibXml2)
456 #gmx_test_libxml2(HAVE_LIBXML2)
457 #option(GMX_XML "Use libxml2 to parse xml files (currently has no effect)" ${HAVE_LIBXML2})
458 #set(PKG_XML "")
459 #mark_as_advanced(GMX_XML)
460 # Don't actually do anything, since libxml2 is currently not used by libgromacs
461 #if(GMX_XML AND NOT HAVE_LIBXML2)
462 #    message(FATAL_ERROR "libxml2 not found. Set GMX_XML=OFF to compile without XML support")
463 #endif()
464 #if(GMX_XML)
465 #    include_directories(${LIBXML2_INCLUDE_DIR})
466 #    set(PKG_XML libxml-2.0)
467 #    set(XML_LIBRARIES ${LIBXML2_LIBRARIES})
468 #endif()
470 gmx_option_trivalue(
471     GMX_HWLOC
472     "Use hwloc portable hardware locality library"
473     "AUTO")
475 if (GMX_HWLOC)
476     # Find quietly the second time.
477     if (HWLOC_FIND_QUIETLY_AFTER_FIRST_RUN)
478         set(HWLOC_FIND_QUIETLY TRUE)
479     endif()
480     find_package(HWLOC 1.5) 
482     if (HWLOC_FOUND)
483         if (HWLOC_LIBRARIES MATCHES ".a$")
484             set(_STATIC_HWLOC TRUE)
485         endif()
487         gmx_check_if_changed(HWLOC_FOUND_CHANGED HWLOC_FOUND)
488         if (_STATIC_HWLOC AND HWLOC_FOUND_CHANGED AND NOT GMX_HWLOC_FORCE)
489             message(STATUS "Static hwloc library found, will not attempt using it as it could lead to link-time errors. To use the detected library, manually set GMX_HWLOC=ON and you will likely have to pass appropriate linker flags too to satisfy the link-time dependencies of your hwloc library. Try \"pkg-config --libs --static hwloc\" for suggestions on what you will need.")
490             set(GMX_USE_HWLOC OFF)
491         else()
492             set(GMX_USE_HWLOC ON)
493         endif()
495         if (GMX_USE_HWLOC)
496             include_directories(SYSTEM ${HWLOC_INCLUDE_DIRS})
497             list(APPEND GMX_EXTRA_LIBRARIES ${HWLOC_LIBRARIES})
498         endif()
499     elseif(GMX_HWLOC_FORCE)
500         message(FATAL_ERROR "HWLOC package support required, but not found.")
501     endif()
503     set(HWLOC_FIND_QUIETLY_AFTER_FIRST_RUN TRUE CACHE INTERNAL "Be quiet during future attempts to find HWLOC")
504 endif()
506 option(GMX_EXTERNAL_TINYXML2 "Use external TinyXML-2 instead of compiling the version bundled with GROMACS." OFF)
507 mark_as_advanced(GMX_EXTERNAL_TINYXML2)
508 if(GMX_EXTERNAL_TINYXML2)
509     # Find an external TinyXML-2 library.
510     find_package(TinyXML-2 3.0.0)
511     set(HAVE_TINYXML2 ${TinyXML2_FOUND})
512     if(NOT HAVE_TINYXML2)
513         message(FATAL_ERROR "External TinyXML-2 could not be found, please adjust your search paths")
514     endif()
515 endif()
517 option(GMX_EXTRAE "Add support for tracing using EXTRAE" OFF)
518 mark_as_advanced(GMX_EXTRAE)
520 if (GMX_EXTRAE)
521   find_package(EXTRAE)
522   if(EXTRAE_FOUND)
523     include_directories(SYSTEM ${EXTRAE_INCLUDE_DIR})
524     set(HAVE_EXTRAE 1)
525   else()
526     message(FATAL_ERROR "EXTRAE library was not found. Please add the correct path to CMAKE_PREFIX_PATH")
527   endif()
528 endif()
530 option(GMX_X11 "Use X window system" OFF)
531 if (GMX_X11)
532     find_package(X11)
533     # X11 includes/libraries are only set in the ngmx subdirectory!
534     if(NOT X11_FOUND)
535         message(FATAL_ERROR
536                 "X11 include files and/or libraries were not found. "
537                 "Set GMX_X11=OFF to compile without X11 support. "
538                 "gmx view will not be available.")
539     endif()
540     include_directories(SYSTEM ${X11_INCLUDE_DIR})
541 endif()
543 include(ThreadMPI)
544 # Enable core threading facilities
545 tmpi_enable_core("${CMAKE_SOURCE_DIR}/src/external/thread_mpi/include")
546 if(GMX_THREAD_MPI)
547     # enable MPI functions
548     tmpi_enable()
549     set(MPI_IN_PLACE_EXISTS 1)
550 endif()
551 # If atomics are manually disabled a define is needed because atomics.h doesn't depend on config.h
552 if (TMPI_ATOMICS_DISABLED)
553    add_definitions(-DTMPI_ATOMICS_DISABLED)
554 endif()
556 include(gmxManageTNG)
558 include(gmxManageLmfit)
560 if(GMX_GPU)
561     # now that we have detected the dependencies, do the second configure pass
562     gmx_gpu_setup()
563     if (GMX_CLANG_CUDA)
564         list(APPEND GMX_EXTRA_LIBRARIES ${GMX_CUDA_CLANG_LINK_LIBS})
565         link_directories("${GMX_CUDA_CLANG_LINK_DIRS}")
566     endif()
567 endif()
569 if(CYGWIN)
570     set(GMX_CYGWIN 1)
571 endif()
573 if(WIN32)
574     set(GMX_NATIVE_WINDOWS 1)
575     # This makes windows.h not declare min/max as macros that would break
576     # C++ code using std::min/std::max.
577     add_definitions(-DNOMINMAX)
578 endif()
580 option(GMX_BUILD_UNITTESTS "Build unit tests with BUILD_TESTING" ON)
581 mark_as_advanced(GMX_BUILD_UNITTESTS)
582 gmx_add_cache_dependency(GMX_BUILD_UNITTESTS BOOL BUILD_TESTING OFF)
584 ########################################################################
585 # Our own GROMACS tests
586 ########################################################################
588 include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src)
589 # Required for config.h, maybe should only be set in src/CMakeLists.txt
590 include_directories(BEFORE ${CMAKE_BINARY_DIR}/src)
592 include(gmxTestInlineASM)
593 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
595 include(gmxSetBuildInformation)
596 gmx_set_build_information()
598 gmx_option_multichoice(
599     GMX_USE_RDTSCP
600     "Use low-latency RDTSCP instruction for CPU-based timers for mdrun execution; might need to be off when compiling for heterogeneous environments)"
601     "AUTO"
602     OFF ON AUTO DETECT)
603 mark_as_advanced(GMX_USE_RDTSCP)
605 macro(gmx_check_rdtscp)
606     if (CPU_DETECTION_FEATURES MATCHES "rdtscp")
607         set(HAVE_RDTSCP 1)
608         set(RDTSCP_DETECTION_MESSAGE " - detected on the build host")
609     else()
610         set(RDTSCP_DETECTION_MESSAGE " - not detected on the build host")
611     endif()
612 endmacro()
614 set(HAVE_RDTSCP 0)
615 if (GMX_USE_RDTSCP STREQUAL "ON")
616     set(HAVE_RDTSCP 1)
617 elseif(GMX_USE_RDTSCP STREQUAL "DETECT")
618     gmx_check_rdtscp()
619 elseif(GMX_USE_RDTSCP STREQUAL "AUTO")
620     # If the user specified automated SIMD selection, that the choice
621     # is made based on detection on the build host. If so, then RDTSCP
622     # should be chosen the same way.
623     #
624     # If the user specified an AVX SIMD level (e.g. when
625     # cross-compiling GROMACS) then they will get our best guess, ie
626     # that in practice AVX mostly correlates with rdtscp (and anyway
627     # is only relevant in rather old x86 hardware).
628     if (GMX_SIMD STREQUAL "AUTO")
629         gmx_check_rdtscp()
630     elseif (GMX_SIMD MATCHES "AVX")
631         set(HAVE_RDTSCP 1)
632     endif()
633 endif()
634 gmx_check_if_changed(HAVE_RDTSCP_CHANGED HAVE_RDTSCP)
635 if (HAVE_RDTSCP_CHANGED)
636     if (HAVE_RDTSCP)
637         message(STATUS "Enabling RDTSCP support${RDTSCP_DETECTION_MESSAGE}")
638     else()
639         message(STATUS "Disabling RDTSCP support${RDTSCP_DETECTION_MESSAGE}")
640     endif()
641 endif()
643 include(gmxTestLargeFiles)
644 gmx_test_large_files(GMX_LARGEFILES)
646 include(gmxTestSignal)
647 gmx_test_sigusr1(HAVE_SIGUSR1)
649 include(gmxTestPipes)
650 gmx_test_pipes(HAVE_PIPES)
652 include(gmxTestXDR)
653 gmx_test_xdr(GMX_SYSTEM_XDR)
654 # Darwin has system XDR, but it uses a three-argument flavour of
655 # xdrproc_t that it guarantees will still work if you pass the normal
656 # two-argument xdr filters, but gcc 8 warns about the cast necessary
657 # to do that, so it's simpler to just use our own XDR library.
659 # TODO It would be better to craft a cmake test which fails if such
660 # XDR operations cause warnings, and succeeds otherwise, because it is
661 # generally preferable to use system libraries where possible.
662 if(NOT GMX_SYSTEM_XDR OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
663     set(GMX_INTERNAL_XDR 1)
664 endif()
667 ##################################################
668 # Process SIMD instruction settings
669 ##################################################
670 # This checks what flags to add in order to
671 # support the SIMD instructions we need, it sets
672 # correct defines for the SIMD instructions supported,
673 # and adds advanced options to control accuracy
674 # for SIMD math operations.
675 include(gmxManageSimd)
676 gmx_manage_simd()
678 include(gmxManageCycleCounters)
679 gmx_manage_cycle_counters()
681 # Process QM/MM Settings
682 if(${GMX_QMMM_PROGRAM} STREQUAL "GAUSSIAN")
683     set(GMX_QMMM_GAUSSIAN 1)
684 elseif(${GMX_QMMM_PROGRAM} STREQUAL "MOPAC")
685     set(GMX_QMMM_MOPAC 1)
686 elseif(${GMX_QMMM_PROGRAM} STREQUAL "GAMESS")
687     set(GMX_QMMM_GAMESS 1)
688 elseif(${GMX_QMMM_PROGRAM} STREQUAL "ORCA")
689     set(GMX_QMMM_ORCA 1)
690 elseif(${GMX_QMMM_PROGRAM} STREQUAL "NONE")
691     # nothing to do
692 else()
693     gmx_invalid_option_value(GMX_QMMM_PROGRAM)
694 endif()
697 ##################################################
698 # Process FFT library settings
699 ##################################################
700 include(gmxManageFFTLibraries)
703 include(gmxManageLinearAlgebraLibraries)
705 include(gmxManagePluginSupport)
707 if (GMX_USE_PLUGINS)
708     if(NOT GMX_VMD_PLUGIN_PATH)
709         find_package(VMD)
710     endif()
711 endif()
713 # Link real-time library for POSIX timers. The check for clock_gettime
714 # confirms the linkability of rt.
715 if(HAVE_TIME_H AND HAVE_UNISTD_H AND HAVE_CLOCK_GETTIME)
716     list(APPEND GMX_EXTRA_LIBRARIES rt)
717 endif()
719 # Math and thread libraries must often come after all others when linking...
720 if (HAVE_LIBM)
721     list(APPEND GMX_PUBLIC_LIBRARIES m)
722 endif()
724 option(GMX_NACL "Configure for Native Client builds" OFF)
725 if (GMX_NACL)
726   list(APPEND GMX_EXTRA_LIBRARIES nosys)
727   set(GMX_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lnosys")
728   # TODO: Is this still necessary with the check for its presence?
729   set(GMX_USE_NICE 0)
730   set(GMX_NO_RENAME 1)
731 endif()
732 mark_as_advanced(GMX_NACL)
734 if(GMX_FAHCORE)
735   set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
736       "Path to swindirect.h")
737   include_directories(${COREWRAP_INCLUDE_DIR})
738 endif()
740 # Value of GMX_BUILD_HELP=AUTO tries to generate things, but will only
741 # produce warnings if that fails.
742 set(build_help_default AUTO)
743 if (SOURCE_IS_SOURCE_DISTRIBUTION OR CMAKE_CROSSCOMPILING)
744     set(build_help_default OFF)
745 endif()
746 gmx_option_trivalue(GMX_BUILD_HELP "Build completions automatically (requires that compiled binaries can be executed on the build host) and install man pages if built (requires building the 'man' target manually)" ${build_help_default})
747 mark_as_advanced(GMX_BUILD_HELP)
748 if (GMX_BUILD_HELP AND SOURCE_IS_SOURCE_DISTRIBUTION AND BUILD_IS_INSOURCE)
749     message(FATAL_ERROR
750         "Rebuilding shell completions or man pages is not supported for "
751         "in-source builds from a source distribution. "
752         "Set GMX_BUILD_HELP=OFF or do an out-of-source build to proceed.")
753 endif()
755 # # # # # # # # # # NO MORE TESTS AFTER THIS LINE! # # # # # # # # # # #
756 # these are set after everything else
757 if (NOT GMX_SKIP_DEFAULT_CFLAGS)
758     set(CMAKE_EXE_LINKER_FLAGS "${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
759     set(CMAKE_SHARED_LINKER_FLAGS "${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
760 else()
761     message("Recommended flags which are not added because GMX_SKIP_DEFAULT_CFLAGS=yes:")
762     message("CMAKE_C_FLAGS: ${SIMD_C_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_C_FLAGS};${GMXC_CFLAGS}")
763     foreach(build_type ${build_types_with_explicit_flags})
764         message("CMAKE_C_FLAGS_${build_type}: ${GMXC_CFLAGS_${build_type}}")
765     endforeach()
766     message("CMAKE_CXX_FLAGS: ${SIMD_CXX_FLAGS};${MPI_COMPILE_FLAGS};${EXTRA_CXX_FLAGS};${GMXC_CXXFLAGS}")
767     foreach(build_type ${build_types_with_explicit_flags})
768         message("CMAKE_CXX_FLAGS_${build_type}: ${GMXC_CXXFLAGS_${build_type}}")
769     endforeach()
770     message("CMAKE_EXE_LINKER_FLAGS: ${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS}")
771     message("CMAKE_SHARED_LINKER_FLAGS: ${FFT_LINKER_FLAGS} ${MPI_LINKER_FLAGS}")
772 endif()
774 ########################################################################
775 # Specify install locations
776 ########################################################################
777 # Use GNUInstallDirs to set paths on multiarch systems.
778 include(GNUInstallDirs)
780 set(GMX_INSTALL_DATASUBDIR "gromacs" CACHE STRING "Subdirectory for GROMACS data under CMAKE_INSTALL_DATADIR")
781 mark_as_advanced(GMX_INSTALL_DATASUBDIR)
783 # Internal convenience so we do not have to join two path segments in the code
784 set(GMX_INSTALL_GMXDATADIR ${CMAKE_INSTALL_DATADIR}/${GMX_INSTALL_DATASUBDIR})
786 # If the nesting level wrt. the installation root is changed,
787 # gromacs-config.cmake.cmakein needs to be adapted.
788 set(GMX_INSTALL_CMAKEDIR  ${CMAKE_INSTALL_DATAROOTDIR}/cmake)
790 # TODO: Make GMXRC adapt if this is changed
791 set(GMX_INSTALL_PKGCONFIGDIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
792 set(GMX_INSTALL_OCLDIR       ${GMX_INSTALL_GMXDATADIR}/opencl)
794 list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${CMAKE_INSTALL_INCLUDEDIR})
796 # Binary and library suffix options
797 include(gmxManageSuffixes)
799 ################################################################
800 # Shared library load path settings
801 ################################################################
802 if(NOT GMX_BUILD_SHARED_EXE)
803     # No rpath
804     set(CMAKE_SKIP_RPATH TRUE)
805     set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
806     set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
807 else()
808     # The build folder always has bin/ and lib/; if we are also going to
809     # install to lib/, then the installation RPATH works also in the build
810     # tree.  This makes installation slightly faster (no need to rewrite the
811     # RPATHs), and makes the binaries in the build tree relocatable.
812     if(CMAKE_INSTALL_LIBDIR STREQUAL "lib")
813         set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
814         set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
815     endif()
816     # Set the RPATH as relative to the executable location to make the
817     # binaries relocatable.
818     if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") #Assume OS X >=10.5
819         set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}")
820         set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_RPATH})
821     else()
822         set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
823     endif()
824     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
825     set(CMAKE_MACOSX_RPATH 1)
826 endif()
828 #COPYING file: Only necessary for binary distributions.
829 #Simpler to always install.
830 install(FILES COPYING DESTINATION ${GMX_INSTALL_GMXDATADIR} COMPONENT data)
832 if (GMX_BUILD_FOR_COVERAGE)
833     # Code heavy with asserts makes conditional coverage close to useless metric,
834     # as by design most of the false branches are impossible to trigger in
835     # correctly functioning code.  And the benefit of testing those that could
836     # be triggered by using an API against its specification isn't usually
837     # worth the effort.
838     add_definitions(-DNDEBUG -DGMX_DISABLE_ASSERTS)
839 endif()
841 if (BUILD_TESTING)
842     include(tests/CheckTarget.cmake)
843 endif()
845 # TODO: Determine control flow and defaults for package installation and testing use cases.
846 # Ref: http://redmine.gromacs.org/issues/2896
847 option(GMX_PYTHON_PACKAGE "Configure gmxapi Python package" OFF)
848 mark_as_advanced(GMX_PYTHON_PACKAGE)
850 if (NOT GMX_BUILD_MDRUN_ONLY)
851     # Note: Though only documented as an output variable, PYTHON_EXECUTABLE is
852     # also effective as a CMake input variable to effectively hint the location
853     # of the Python interpreter. This may be helpful in environments with both
854     # Python 2 and Python 3 on the default PATH.
855     # Ref: https://cmake.org/cmake/help/latest/module/FindPythonInterp.html
856     if(FIND_PACKAGE_MESSAGE_DETAILS_PythonInterp)
857         # Keep quiet on subsequent runs of cmake
858         set(PythonInterp_FIND_QUIETLY ON)
859     endif()
860     # Older CMake versions might not search for Python newer than 3.7.
861     set(Python_ADDITIONAL_VERSIONS 3.8)
862     if(GMX_PYTHON_PACKAGE)
863         find_package(PythonInterp 3.5 REQUIRED)
864         # Note: PythonLibs will be found later by pybind11.
865         # TODO: (issue #2998) When CMake >= 3.12 is required, update detection.
866         # I.e.  find_package(Python3 3.5 COMPONENTS Interpreter Development REQUIRED)
867     else()
868         find_package(PythonInterp 3.5)
869     endif()
870     find_package(ImageMagick QUIET COMPONENTS convert)
871     include(gmxTestImageMagick)
872     GMX_TEST_IMAGEMAGICK(IMAGE_CONVERT_POSSIBLE)
873     # TODO: Resolve circular dependency between docs, gromacs, and python_packaging
874     add_subdirectory(docs)
875     add_subdirectory(share)
876     add_subdirectory(scripts)
877 endif()
878 add_subdirectory(src)
880 if (BUILD_TESTING)
881     add_subdirectory(tests)
882 endif()
884 if(GMX_PYTHON_PACKAGE AND NOT GMX_BUILD_MDRUN_ONLY)
885     add_subdirectory(python_packaging)
886 endif()
888 gmx_cpack_write_config()
890 # Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
891 # Don't bother the user after the first configure pass.
892 if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT GMX_GPU_DETECTION_DONE)
893     message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
894 endif()
895 set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already been done")
897 #######################
898 ## uninstall target
899 #######################
900 CONFIGURE_FILE(   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
901                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
902                   IMMEDIATE @ONLY)
903 ###########################
904 ADD_CUSTOM_TARGET(uninstall
905                   "${CMAKE_COMMAND}" -P
906                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
907 ###########################
908 set_directory_properties(PROPERTIES
909             ADDITIONAL_MAKE_CLEAN_FILES "install_manifest.txt")