Professional Documents
Culture Documents
cmake_minimum_required(VERSION 3.4.3)
project(Gromacs)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(gmxBuildTypeReference)
include(gmxBuildTypeProfile)
include(gmxBuildTypeTSAN)
include(gmxBuildTypeASAN)
include(gmxBuildTypeMSAN)
include(gmxBuildTypeReleaseWithAssert)
if(NOT CMAKE_BUILD_TYPE)
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)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo" "Reference" "RelWithAssert" "Profile" "TSAN"
"ASAN" "MSAN")
endif()
if(CMAKE_CONFIGURATION_TYPES)
# Add appropriate GROMACS-specific build types for the Visual
# Studio generator (Debug, Release, MinSizeRel and RelWithDebInfo
# are already present by default).
list(APPEND CMAKE_CONFIGURATION_TYPES "RelWithAssert" "Reference")
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
"List of configuration types"
FORCE)
endif()
set(build_types_with_explicit_flags RELEASE DEBUG RELWITHDEBINFO RELWITHASSERT
MINSIZEREL PROFILE)
include(gmxCTestUtilities)
gmx_ctest_init()
include(gmxCPackUtilities)
gmx_cpack_init()
########################################################################
# Global non-cache variables for implementing the build system
########################################################################
########################################################################
# Check and warn if cache generated on a different host is being reused
########################################################################
if(CMAKE_HOST_UNIX)
execute_process(COMMAND hostname
OUTPUT_VARIABLE TMP_HOSTNAME
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GMX_BUILD_HOSTNAME AND NOT "${GMX_BUILD_HOSTNAME}" STREQUAL "$
{TMP_HOSTNAME}")
message(WARNING "
The CMake cache, probably generated on a different host ($
{GMX_BUILD_HOSTNAME}),
is being reused! This could lead to inconsistencies; therefore, it is
recommended to regenerate the cache!")
endif()
set(GMX_BUILD_HOSTNAME "${TMP_HOSTNAME}" CACHE INTERNAL
"Hostname of the machine where the cache was generated.")
endif()
########################################################################
# Detect architecture before setting options so we can alter defaults
########################################################################
# Detect the architecture the compiler is targetting, detect
# SIMD instructions possibilities on that hardware, suggest SIMD instruction set
# to use if none is specified, and populate the cache option for CPU
# SIMD.
include(gmxDetectTargetArchitecture)
gmx_detect_target_architecture()
########################################################################
# Detect CXX11 support and flags
########################################################################
# The cmake/Check{C,CXX}CompilerFlag.cmake files in the GROMACS distribution
# are used with permission from CMake v3.0.0 so that GROMACS can detect
# invalid options with the Intel Compilers, and we have added a line
# to detect warnings with the Fujitsu compilers on K computer and ICC.
# CMake-3.0 also has a bug where the FAIL_REGEX pattern for AIX contains
# a semicolon. Since this is also used as a separator in lists inside CMake,
# that string ends up being split into two separate patterns, and the last
# part is just a single word that also matches other messages. We solved this
# by replacing the semicolon with a period that matches any character.
#
# These files should be removed from the source tree when a CMake version that
# includes the features in question becomes required for building GROMACS.
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
# This must come early, since some of our configuration flag tests
# depend on being able to compile C++11 source files.
include(gmxTestCXX11)
gmx_test_cxx11(GMX_CXX11_FLAGS GMX_STDLIB_CXX_FLAGS GMX_STDLIB_LIBRARIES)
# Make sure all C++ code will be compiled in C++11 mode, with the
# expected standard library.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GMX_CXX11_FLAGS} $
{GMX_STDLIB_CXX_FLAGS}")
########################################################################
# User input options #
########################################################################
include(gmxOptionUtilities)
gmx_option_multichoice(
GMX_SIMD
"SIMD instruction set for CPU kernels and compiler optimization"
"AUTO"
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_QPX IBM_VMX IBM_VSX Sparc64_HPC_ACE Reference)
if(GMX_TARGET_MIC)
set(GMX_FFT_LIBRARY_DEFAULT "mkl")
else()
set(GMX_FFT_LIBRARY_DEFAULT "fftw3")
endif()
gmx_option_multichoice(
GMX_FFT_LIBRARY
"FFT library"
"${GMX_FFT_LIBRARY_DEFAULT}"
fftw3 mkl "fftpack[built-in]")
gmx_dependent_option(
GMX_BUILD_OWN_FFTW
"Download and build FFTW 3 during the GROMACS build process, rather than fall
back on the really slow fftpack."
OFF
"GMX_FFT_LIBRARY STREQUAL FFTW3")
gmx_dependent_option(
GMX_DISABLE_FFTW_MEASURE
"Do not optimize FFTW setups (not needed with SSE)"
OFF
"GMX_FFT_LIBRARY STREQUAL FFTW3")
mark_as_advanced(GMX_BUILD_OWN_FFTW)
mark_as_advanced(GMX_DISABLE_FFTW_MEASURE)
gmx_option_multichoice(
GMX_QMMM_PROGRAM
"QM package for QM/MM"
None
none gaussian mopac gamess orca)
# This should be moved to a separate NBNXN cmake module when that code is cleaned
up and modularized
option(GMX_BUILD_FOR_COVERAGE
"Tune build for better code coverage metrics (e.g., disable asserts)"
OFF)
mark_as_advanced(GMX_BUILD_FOR_COVERAGE)
option(GMX_DEVELOPER_BUILD
"Enable Developer convenience features: always build unit-tests"
OFF)
mark_as_advanced(GMX_DEVELOPER_BUILD)
option(GMX_BUILD_SHARED_EXE
"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."
ON)
mark_as_advanced(GMX_BUILD_SHARED_EXE)
option(GMX_PHYSICAL_VALIDATION
"Include physical validation tests in ctest environment. These can then be
called using 'make check-phys' or
'make check-all'. Warning: Running the physical validation tests takes
significantly more time than other tests!"
OFF)
mark_as_advanced(GMX_PHYSICAL_VALIDATION)
######################################################################
# Detect OpenMP support
######################################################################
# The OpenMP detection _must_ come before tests for other CFLAGS.
include(gmxManageOpenMP)
######################################################################
# Compiler tests
# These need to be done early (before further tests).
#####################################################################
include(gmxCFlags)
gmx_c_flags()
# This variable should be used for additional compiler flags which are not
# generated in gmxCFlags nor are SIMD or MPI related.
#
# TODO These variables should be consolidated into
# EXTRA_COMPILER_FLAGS so that we we don't perpetrate bugs where
# things that work in C compilation (e.g. merging from old branches)
# also work for C++ compilation.
set(EXTRA_C_FLAGS "")
set(EXTRA_CXX_FLAGS "")
# Run through a number of tests for buggy compilers and other issues
include(gmxTestCompilerProblems)
gmx_test_compiler_problems()
if(WIN32)
list(APPEND GMX_EXTRA_LIBRARIES "wsock32")
add_definitions(-DGMX_HAVE_WINSOCK)
endif()
########################################################################
# Basic system tests (standard libraries, headers, functions, types) #
########################################################################
include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(pwd.h HAVE_PWD_H)
check_include_files(dirent.h HAVE_DIRENT_H)
check_include_files(time.h HAVE_TIME_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(io.h HAVE_IO_H)
check_include_files(sched.h HAVE_SCHED_H)
check_include_files(regex.h HAVE_POSIX_REGEX)
# TODO: It could be nice to inform the user if no regex support is found,
# as selections won't be fully functional.
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
check_cxx_symbol_exists(sysconf unistd.h HAVE_SYSCONF)
check_cxx_symbol_exists(nice unistd.h HAVE_NICE)
check_cxx_symbol_exists(fsync unistd.h HAVE_FSYNC)
check_cxx_symbol_exists(_fileno stdio.h HAVE__FILENO)
check_cxx_symbol_exists(fileno stdio.h HAVE_FILENO)
check_cxx_symbol_exists(_commit io.h HAVE__COMMIT)
check_cxx_symbol_exists(sigaction signal.h HAVE_SIGACTION)
# We cannot check for the __builtins as symbols, but check if code compiles
check_cxx_source_compiles("int main(){ return __builtin_clz(1);}"
HAVE_BUILTIN_CLZ)
check_cxx_source_compiles("int main(){ return __builtin_clzll(1);}"
HAVE_BUILTIN_CLZLL)
if(MSVC)
check_cxx_source_compiles("#include <intrin.h>\n int main(){unsigned long
r;unsigned long i=1;_BitScanReverse(&r,i);return r;}" HAVE_BITSCANREVERSE)
check_cxx_source_compiles("#include <intrin.h>\n int main(){unsigned long
r;unsigned __int64 i=1;_BitScanReverse(&r,i);return r;}" HAVE_BITSCANREVERSE64)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
check_cxx_source_compiles("int main(){ return __cntlz4(1);}" HAVE_CNTLZ4)
check_cxx_source_compiles("int main(){ return __cntlz8(1);}" HAVE_CNTLZ8)
endif()
include(CheckLibraryExists)
find_library(HAVE_LIBM m)
mark_as_advanced(HAVE_LIBM)
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
check_library_exists(m feenableexcept "" HAVE_FEENABLEEXCEPT)
include(TestSchedAffinity)
test_sched_affinity(HAVE_SCHED_AFFINITY)
include(TestBigEndian)
test_big_endian(GMX_INTEGER_BIG_ENDIAN)
if(GMX_TARGET_FUJITSU_SPARC64)
include(gmxManageFujitsuSparc64)
endif()
########################################################################
#Process MPI settings
########################################################################
include(gmxManageMPI)
########################################################################
#Process shared/static library settings
########################################################################
include(gmxManageSharedLibraries)
########################################################################
# Find external packages #
########################################################################
if(DEFINED HWLOC_LIBRARIES)
set(Hwloc_FIND_QUIETLY TRUE)
endif()
find_package(Hwloc 1.5)
if (HWLOC_FOUND)
if (HWLOC_LIBRARIES MATCHES ".a$")
set(_STATIC_HWLOC TRUE)
endif()
gmx_check_if_changed(HWLOC_FOUND_CHANGED HWLOC_FOUND)
if (_STATIC_HWLOC AND HWLOC_FOUND_CHANGED)
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.")
set(GMX_HWLOC_DEFAULT OFF)
else()
set(GMX_HWLOC_DEFAULT ON)
endif()
else()
set(GMX_HWLOC_DEFAULT OFF)
endif()
option(GMX_HWLOC "Add support for hwloc Portable Hardware locality library" $
{GMX_HWLOC_DEFAULT})
if(GMX_HWLOC)
if(HWLOC_FOUND)
include_directories(SYSTEM ${HWLOC_INCLUDE_DIRS})
list(APPEND GMX_EXTRA_LIBRARIES ${HWLOC_LIBRARIES})
else()
message(FATAL_ERROR "Hwloc package support requested, but not found.")
endif()
endif()
if (GMX_EXTRAE)
find_package(EXTRAE)
if(EXTRAE_FOUND)
include_directories(SYSTEM ${EXTRAE_INCLUDE_DIR})
set(HAVE_EXTRAE 1)
else()
message(FATAL_ERROR "EXTRAE library was not found. Please add the correct path
to CMAKE_PREFIX_PATH")
endif()
endif()
option(GMX_X11 "Use X window system" OFF)
if (GMX_X11)
find_package(X11)
# X11 includes/libraries are only set in the ngmx subdirectory!
if(NOT X11_FOUND)
message(FATAL_ERROR
"X11 include files and/or libraries were not found. "
"Set GMX_X11=OFF to compile without X11 support. "
"gmx view will not be available.")
endif()
include_directories(SYSTEM ${X11_INCLUDE_DIR})
endif()
include(ThreadMPI)
# Enable core threading facilities
tmpi_enable_core("${CMAKE_SOURCE_DIR}/src/external/thread_mpi/include")
# Enable tMPI C++ support
tmpi_enable_cxx()
if(GMX_THREAD_MPI)
# enable MPI functions
tmpi_enable()
set(MPI_IN_PLACE_EXISTS 1)
endif()
# If atomics are manually disabled a define is needed because atomics.h doesn't
depend on config.h
if (TMPI_ATOMICS_DISABLED)
add_definitions(-DTMPI_ATOMICS_DISABLED)
endif()
include(gmxManageTNG)
include(gmxManageLmfit)
if(GMX_GPU)
# now that we have detected the dependencies, do the second configure pass
gmx_gpu_setup()
if (GMX_CLANG_CUDA)
list(APPEND GMX_EXTRA_LIBRARIES ${GMX_CUDA_CLANG_LINK_LIBS})
link_directories("${GMX_CUDA_CLANG_LINK_DIRS}")
endif()
endif()
if(CYGWIN)
set(GMX_CYGWIN 1)
endif()
if(WIN32)
set(GMX_NATIVE_WINDOWS 1)
# This makes windows.h not declare min/max as macros that would break
# C++ code using std::min/std::max.
add_definitions(-DNOMINMAX)
endif()
########################################################################
# Our own GROMACS tests
########################################################################
add_definitions( -DHAVE_CONFIG_H )
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src)
# TODO required at high level because both libgromacs and progs/mdrun
# require it, both for thread-MPI and its atomics and mutexes.
include_directories(BEFORE SYSTEM $
{CMAKE_SOURCE_DIR}/src/external/thread_mpi/include)
# Required for config.h, maybe should only be set in src/CMakeLists.txt
include_directories(BEFORE ${CMAKE_BINARY_DIR}/src)
include(gmxTestInlineASM)
gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
include(gmxSetBuildInformation)
gmx_set_build_information()
gmx_option_multichoice(
GMX_USE_RDTSCP
"Use low-latency RDTSCP instruction for CPU-based timers for mdrun execution;
might need to be off when compiling for heterogeneous environments)"
"AUTO"
OFF ON AUTO DETECT)
mark_as_advanced(GMX_USE_RDTSCP)
macro(gmx_check_rdtscp)
if (CPU_DETECTION_FEATURES MATCHES "rdtscp")
set(HAVE_RDTSCP 1)
set(RDTSCP_DETECTION_MESSAGE " - detected on the build host")
else()
set(RDTSCP_DETECTION_MESSAGE " - not detected on the build host")
endif()
endmacro()
set(HAVE_RDTSCP 0)
if (GMX_USE_RDTSCP STREQUAL "ON")
set(HAVE_RDTSCP 1)
elseif(GMX_USE_RDTSCP STREQUAL "DETECT")
gmx_check_rdtscp()
elseif(GMX_USE_RDTSCP STREQUAL "AUTO")
# If the user specified automated SIMD selection, that the choice
# is made based on detection on the build host. If so, then RDTSCP
# should be chosen the same way.
#
# If the user specified an AVX SIMD level (e.g. when
# cross-compiling GROMACS) then they will get our best guess, ie
# that in practice AVX mostly correlates with rdtscp (and anyway
# is only relevant in rather old x86 hardware).
if (GMX_SIMD STREQUAL "AUTO")
gmx_check_rdtscp()
elseif (GMX_SIMD MATCHES "AVX")
set(HAVE_RDTSCP 1)
endif()
endif()
gmx_check_if_changed(HAVE_RDTSCP_CHANGED HAVE_RDTSCP)
if (HAVE_RDTSCP_CHANGED)
if (HAVE_RDTSCP)
message(STATUS "Enabling RDTSCP support${RDTSCP_DETECTION_MESSAGE}")
else()
message(STATUS "Disabling RDTSCP support${RDTSCP_DETECTION_MESSAGE}")
endif()
endif()
include(gmxTestLargeFiles)
gmx_test_large_files(GMX_LARGEFILES)
include(gmxTestSignal)
gmx_test_sigusr1(HAVE_SIGUSR1)
include(gmxTestPipes)
gmx_test_pipes(HAVE_PIPES)
check_include_file_cxx(regex HAVE_CXX11_REGEX)
include(gmxTestXDR)
gmx_test_xdr(GMX_SYSTEM_XDR)
if(NOT GMX_SYSTEM_XDR)
set(GMX_INTERNAL_XDR 1)
endif()
##################################################
# Process SIMD instruction settings
##################################################
# This checks what flags to add in order to
# support the SIMD instructions we need, it sets
# correct defines for the SIMD instructions supported,
# and adds advanced options to control accuracy
# for SIMD math operations.
include(gmxManageSimd)
gmx_manage_simd()
include(gmxManageCycleCounters)
gmx_manage_cycle_counters()
##################################################
# Process FFT library settings
##################################################
include(gmxManageFFTLibraries)
include(gmxManageLinearAlgebraLibraries)
include(gmxManagePluginSupport)
if (GMX_USE_PLUGINS)
if(NOT GMX_VMD_PLUGIN_PATH)
find_package(VMD)
endif()
endif()
# Link real-time library for POSIX timers. The check for clock_gettime
# confirms the linkability of rt.
if(HAVE_TIME_H AND HAVE_UNISTD_H AND HAVE_CLOCK_GETTIME)
list(APPEND GMX_EXTRA_LIBRARIES rt)
endif()
# Math and thread libraries must often come after all others when linking...
if (HAVE_LIBM)
list(APPEND GMX_PUBLIC_LIBRARIES m)
endif()
if(GMX_FAHCORE)
set(COREWRAP_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../corewrap" CACHE STRING
"Path to swindirect.h")
include_directories(${COREWRAP_INCLUDE_DIR})
endif()
if(NOT GMX_OPENMP)
#Unset all OpenMP flags in case OpenMP was disabled either by the user
#or because it was only partially detected (e.g. only for C but not C++
compiler)
unset(OpenMP_C_FLAGS CACHE)
unset(OpenMP_CXX_FLAGS CACHE)
else()
set(GMX_EXE_LINKER_FLAGS ${GMX_EXE_LINKER_FLAGS} ${OpenMP_LINKER_FLAGS})
set(GMX_SHARED_LINKER_FLAGS ${GMX_SHARED_LINKER_FLAGS} $
{OpenMP_SHARED_LINKER_FLAGS})
endif()
########################################################################
# Specify install locations
########################################################################
# Use GNUInstallDirs to set paths on multiarch systems.
include(GNUInstallDirs)
# Internal convenience so we do not have to join two path segments in the code
set(GMX_INSTALL_GMXDATADIR ${CMAKE_INSTALL_DATADIR}/${GMX_INSTALL_DATASUBDIR})
################################################################
# Shared library load path settings
################################################################
if(NOT GMX_BUILD_SHARED_EXE)
# No rpath
set(CMAKE_SKIP_RPATH TRUE)
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS) # remove -Wl,-Bdynamic
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
else()
# The build folder always has bin/ and lib/; if we are also going to
# install to lib/, then the installation RPATH works also in the build
# tree. This makes installation slightly faster (no need to rewrite the
# RPATHs), and makes the binaries in the build tree relocatable.
if(CMAKE_INSTALL_LIBDIR STREQUAL "lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW) # From CMake-3.9
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR TRUE)
endif()
endif()
# Set the RPATH as relative to the executable location to make the
# binaries relocatable.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") #Assume OS X >=10.5
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_RPATH})
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
endif()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_MACOSX_RPATH 1)
endif()
if (GMX_BUILD_FOR_COVERAGE)
# Code heavy with asserts makes conditional coverage close to useless metric,
# as by design most of the false branches are impossible to trigger in
# correctly functioning code. And the benefit of testing those that could
# be triggered by using an API against its specification isn't usually
# worth the effort.
add_definitions(-DNDEBUG -DGMX_DISABLE_ASSERTS)
endif()
if (BUILD_TESTING)
include(tests/CheckTarget.cmake)
endif()
if (NOT GMX_BUILD_MDRUN_ONLY)
add_subdirectory(docs)
add_subdirectory(share)
add_subdirectory(scripts)
endif()
add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(tests)
endif()
gmx_cpack_write_config()
# Issue a warning if NVIDIA GPUs were detected, but CUDA was not found.
# Don't bother the user after the first configure pass.
if ((CUDA_NOTFOUND_AUTO AND GMX_DETECT_GPU_AVAILABLE) AND NOT
GMX_GPU_DETECTION_DONE)
message(WARNING "${CUDA_NOTFOUND_MESSAGE}")
endif()
set(GMX_GPU_DETECTION_DONE TRUE CACHE INTERNAL "Whether GPU detection has already
been done")
#######################
## uninstall target
#######################
CONFIGURE_FILE( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
###########################
ADD_CUSTOM_TARGET(uninstall
"${CMAKE_COMMAND}" -P
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
###########################
set_directory_properties(PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "install_manifest.txt")