Refactor for testing interactive selection input
[alexxy/gromacs.git] / CMakeLists.txt
index 92809a7be67bd354652ba3b9042774a1ed78d6bb..c6a2cf3e38e4f220264b5e5e7c7948122923b952 100644 (file)
@@ -57,11 +57,15 @@ include(gmxVersionInfo)
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
     set(CMAKE_INSTALL_PREFIX "/usr/local/gromacs" CACHE STRING "Installation prefix (installation will need write permissions here)" FORCE)
 endif()
+if("${CMAKE_INSTALL_PREFIX}" STREQUAL "${CMAKE_BINARY_DIR}")
+    message(FATAL_ERROR "GROMACS cannot be installed into the build tree, choose a different location for CMAKE_INSTALL_PREFIX")
+endif()
 
 include(gmxBuildTypeReference)
 include(gmxBuildTypeProfile)
 include(gmxBuildTypeTSAN)
 include(gmxBuildTypeASAN)
+include(gmxBuildTypeMSAN)
 include(gmxBuildTypeReleaseWithAssert)
 
 if(NOT CMAKE_BUILD_TYPE)
@@ -162,6 +166,8 @@ option(GMX_COOL_QUOTES "Enable GROMACS cool quotes" ON)
 mark_as_advanced(GMX_COOL_QUOTES)
 gmx_add_cache_dependency(GMX_COOL_QUOTES BOOL "NOT GMX_FAHCORE" OFF)
 
+option(GMX_USE_OPENCL "Enable OpenCL acceleration" OFF)
+
 # Decide on GPU settings based on user-settings and GPU/CUDA detection.
 # We support CUDA >=v4.0 on *nix, but <= v4.1 doesn't work with MSVC
 if(MSVC)
@@ -170,7 +176,21 @@ else()
     set(REQUIRED_CUDA_VERSION 4.0)
 endif()
 set(REQUIRED_CUDA_COMPUTE_CAPABILITY 2.0)
-include(gmxManageGPU)
+
+# OpenCL required version: 1.1 or newer
+set(REQUIRED_OPENCL_MIN_VERSION 1.1)
+
+if(NOT GMX_USE_OPENCL)
+    # CUDA detection is done only if GMX_USE_OPENCL is OFF
+    include(gmxManageGPU)
+else()
+    #Now the OpenCL path
+    if(GMX_GPU)
+        include(gmxManageOpenCL)
+    else(GMX_GPU)
+        message(FATAL_ERROR "OpenCL requested but GPU option is not enabled (try -DGMX_GPU=on) ")
+    endif(GMX_GPU)
+endif()
 
 include(gmxDetectSimd)
 gmx_detect_simd(GMX_SUGGESTED_SIMD)
@@ -336,24 +356,24 @@ 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(CheckFunctionExists)
-check_function_exists(posix_memalign    HAVE_POSIX_MEMALIGN)
-check_function_exists(memalign          HAVE_MEMALIGN)
-check_function_exists(_aligned_malloc   HAVE__ALIGNED_MALLOC)
-check_function_exists(gettimeofday      HAVE_GETTIMEOFDAY)
-check_function_exists(fsync             HAVE_FSYNC)
-check_function_exists(_fileno           HAVE__FILENO)
-check_function_exists(fileno            HAVE_FILENO)
-check_function_exists(_commit           HAVE__COMMIT)
-check_function_exists(sigaction         HAVE_SIGACTION)
-check_function_exists(sysconf           HAVE_SYSCONF)
-check_function_exists(rsqrt             HAVE_RSQRT)
-check_function_exists(rsqrtf            HAVE_RSQRTF)
-check_function_exists(sqrtf             HAVE_SQRTF)
-check_function_exists(nice              HAVE_NICE)
+include(CheckCXXSymbolExists)
+check_cxx_symbol_exists(posix_memalign    stdlib.h     HAVE_POSIX_MEMALIGN)
+check_cxx_symbol_exists(memalign          stdlib.h     HAVE_MEMALIGN)
+check_cxx_symbol_exists(_aligned_malloc   stdlib.h     HAVE__ALIGNED_MALLOC)
+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)
+check_cxx_symbol_exists(rsqrt             math.h       HAVE_RSQRT)
+check_cxx_symbol_exists(rsqrtf            math.h       HAVE_RSQRTF)
+check_cxx_symbol_exists(sqrtf             math.h       HAVE_SQRTF)
 
 include(CheckLibraryExists)
-check_library_exists(m sqrt "" HAVE_LIBM)
+find_library(HAVE_LIBM m)
 check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
 check_library_exists(m feenableexcept "" HAVE_FEENABLEEXCEPT)
 
@@ -484,6 +504,15 @@ if(WIN32)
     add_definitions(-DNOMINMAX)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") #Work-around for cmake bug #10837
+    if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Intel" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+        set(CMAKE_INCLUDE_SYSTEM_FLAG_C "-isystem ")
+    endif()
+    if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Intel" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+        set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
+    endif()
+endif()
+
 # Detect boost unless GMX_EXTERNAL_BOOST is explicitly OFF
 # Used for default if GMX_EXTERNAL_BOOST is not defined (first CMake pass)
 if(NOT DEFINED GMX_EXTERNAL_BOOST OR GMX_EXTERNAL_BOOST)
@@ -763,6 +792,7 @@ set(MAN_INSTALL_DIR       share/man)
 set(CMAKE_INSTALL_DIR     share/cmake)
 # TODO: Make GMXRC adapt if this is changed
 set(PKGCONFIG_INSTALL_DIR ${LIB_INSTALL_DIR}/pkgconfig)
+set(OCL_INSTALL_DIR       ${DATA_INSTALL_DIR}/opencl)
 set(INCL_INSTALL_DIR      include)
 
 list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${INCL_INSTALL_DIR})
@@ -817,10 +847,10 @@ endif()
 install(FILES COPYING DESTINATION ${DATA_INSTALL_DIR} COMPONENT data)
 
 if(GMX_EXTERNAL_BOOST)
-    include_directories(${Boost_INCLUDE_DIRS})
+    include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
     list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
 else()
-    include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/boost)
+    include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/src/external/boost)
     list(APPEND INSTALLED_HEADER_INCLUDE_DIRS ${INCL_INSTALL_DIR}/gromacs/external/boost)
     list(APPEND INSTALLED_HEADED_DEFINITIONS "-DBOOST_NO_TYPEID")
     # typeid not supported for minimal internal version