Merge remote-tracking branch 'gerrit/release-4-6'
[alexxy/gromacs.git] / CMakeLists.txt
index 16830abb7b19655bb5f76ae800fb3590c8737e0c..8cac7ae235d926b7e3f121e10e7b7312fdcd59f8 100644 (file)
@@ -11,6 +11,10 @@ project(Gromacs)
 include(Dart)
 mark_as_advanced(DART_ROOT)
 
+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)
+
 # PROJECT_VERSION should have the following structure: 
 # VERSION-dev[-SUFFIX] where the VERSION should have the for: vMajor.vMinor.vPatch
 #
@@ -19,7 +23,7 @@ mark_as_advanced(DART_ROOT)
 # machine with no git. 
 #
 # NOTE: when releasing the "-dev" suffix needs to be stripped off!
-set(PROJECT_VERSION "4.6-dev")
+set(PROJECT_VERSION "5.0-dev")
 set(CUSTOM_VERSION_STRING ""
     CACHE STRING "Custom version string (if empty, use hard-coded default)")
 mark_as_advanced(CUSTOM_VERSION_STRING)
@@ -28,8 +32,8 @@ if (CUSTOM_VERSION_STRING)
 endif (CUSTOM_VERSION_STRING)
 set(SOVERSION 6)
 # It is a bit irritating, but this has to be set separately for now!
-SET(CPACK_PACKAGE_VERSION_MAJOR "4")
-SET(CPACK_PACKAGE_VERSION_MINOR "6")
+SET(CPACK_PACKAGE_VERSION_MAJOR "5")
+SET(CPACK_PACKAGE_VERSION_MINOR "0")
 #SET(CPACK_PACKAGE_VERSION_PATCH "0")
 
 
@@ -45,6 +49,7 @@ if(NOT CMAKE_BUILD_TYPE)
 endif(NOT CMAKE_BUILD_TYPE)
 
 enable_language(C)
+enable_language(CXX)
 
 set(GMX_USE_RELATIVE_INSTALL_PATH OFF CACHE STRING "Use relative paths not absolute paths for cmake install. Has only an effect on cpack.")
 mark_as_advanced(GMX_USE_RELATIVE_INSTALL_PATH)
@@ -92,6 +97,9 @@ IF( WIN32 AND NOT CYGWIN)
   option(GMX_PREFER_STATIC_LIBS "When finding libraries prefer static system libraries (MT instead of MD)!" ON)
   mark_as_advanced(GMX_PREFER_STATIC_LIBS)
   SET(SHARED_LIBS_DEFAULT OFF)  #is currently not working on Windows
+  # This makes windows.h not declare min/max as macros that would break
+  # C++ code using std::min/std::max.
+  add_definitions(-DNOMINMAX)
 
   IF (GMX_PREFER_STATIC_LIBS)
     #Only setting Debug and Release flags. Others configurations current not used.
@@ -311,38 +319,22 @@ endif(GMX_OPENMM)
 # Basic system tests (standard libraries, headers, functions, types)   #
 ########################################################################
 include(CheckIncludeFiles)
-check_include_files(string.h     HAVE_STRING_H)
-check_include_files(math.h       HAVE_MATH_H)
-check_include_files(limits.h     HAVE_LIMITS_H)
-check_include_files(memory.h     HAVE_MEMORY_H)
 check_include_files(unistd.h    HAVE_UNISTD_H)
-check_include_files(direct.h    HAVE_DIRECT_H)
 check_include_files(pwd.h        HAVE_PWD_H)
-check_include_files(stdint.h    HAVE_STDINT_H)
-check_include_files(stdlib.h    HAVE_STDLIB_H)
 check_include_files(pthread.h    HAVE_PTHREAD_H)
 check_include_files(dirent.h     HAVE_DIRENT_H)
-check_include_files(inttypes.h   HAVE_INTTYPES_H)
 check_include_files(regex.h      HAVE_REGEX_H)
 check_include_files(sys/types.h  HAVE_SYS_TYPES_H)
-check_include_files(sys/stat.h   HAVE_SYS_STAT_H)
 check_include_files(sys/time.h   HAVE_SYS_TIME_H)
-check_include_files(rpc/rpc.h    HAVE_RPC_RPC_H)
-check_include_files("rpc/rpc.h;rpc/xdr.h"    HAVE_RPC_XDR_H)
 check_include_files(io.h                HAVE_IO_H)
 
 
 include(CheckFunctionExists)
-check_function_exists(strcasecmp        HAVE_STRCASECMP)
 check_function_exists(strdup            HAVE_STRDUP)
-check_function_exists(vprintf           HAVE_VPRINTF)
-check_function_exists(memcmp            HAVE_MEMCMP)
 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(isnan             HAVE_ISNAN)
-check_function_exists(_isnan            HAVE__ISNAN)
 check_function_exists(fsync             HAVE_FSYNC)
 check_function_exists(_fileno           HAVE__FILENO)
 check_function_exists(fileno            HAVE_FILENO)
@@ -357,7 +349,6 @@ check_library_exists(m cbrt "" HAVE_CBRT)
 
 include(CheckTypeSize)
 
-check_type_size("bool"          SIZEOF_BOOL) # will also set HAVE_BOOL
 check_type_size("int"           SIZEOF_INT) 
 check_type_size("long int"      SIZEOF_LONG_INT) 
 check_type_size("long long int" SIZEOF_LONG_LONG_INT) 
@@ -370,35 +361,6 @@ else (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
     set(GMX_64_BIT FALSE)
 endif (CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
 
-# Check for some basic types that we *need*, so set these to int if they are not present 
-check_type_size(uid_t uid_t)
-if(NOT uid_t)
-  set(uid_t int)
-else(NOT uid_t)
-  set(uid_t 0)
-endif(NOT uid_t)
-
-check_type_size(gid_t gid_t)
-if(NOT gid_t)
-  set(gid_t 1)
-else(NOT gid_t)
-  set(gid_t 0)
-endif(NOT gid_t)
-
-check_type_size(size_t size_t)
-if(NOT size_t)
-  set(size_t int)
-else(NOT size_t)
-  set(size_t 0)
-endif(NOT size_t)
-
-check_type_size(off_t off_t)
-if(NOT off_t)
-  set(off_t int)
-else(NOT off_t)
-  set(off_t 0)
-endif(NOT off_t)
-
 include(TestBigEndian)
 test_big_endian(GMX_INTEGER_BIG_ENDIAN)
 
@@ -431,7 +393,6 @@ if (GMX_XML)
     include_directories(${LIBXML2_INCLUDE_DIR})
     set(PKG_XML libxml-2.0)
     set(XML_LIBRARIES ${LIBXML2_LIBRARIES})
-    set(HAVE_LIBXML2 1)
   endif(LIBXML2_FOUND)
 endif(GMX_XML)
 
@@ -455,12 +416,14 @@ if (GMX_X11)
        endif(X11_FOUND)
 endif(GMX_X11)
 
+include(ThreadMPI)
+set(THREAD_MPI_LIB thread_mpi)
 if(GMX_THREAD_MPI)
+    tmpi_get_source_list(THREAD_MPI_SRC CXX)
     set(PKG_CFLAGS "${PKG_CFLAGS} -DGMX_THREAD_MPI")
-    include(ThreadMPI)
-    set(THREAD_MPI_LIB thread_mpi)
     set(GMX_MPI 1)
-    string(TOUPPER ${GMX_FFT_LIBRARY} ${GMX_FFT_LIBRARY})
+else(GMX_THREAD_MPI)
+    tmpi_get_source_list(THREAD_MPI_SRC CXX NOMPI)
 endif(GMX_THREAD_MPI)
 
 if(GMX_OPENMM)
@@ -513,6 +476,41 @@ else()
     set(USE_VERSION_H OFF)
 endif()
 
+option(GMX_INTERNAL_BOOST "Use minimal internal version of boost" OFF)
+if ( NOT GMX_INTERNAL_BOOST )
+  find_package( Boost 1.36.0 )
+else ( NOT GMX_INTERNAL_BOOST )
+  set (Boost_FOUND FALSE)
+endif( NOT GMX_INTERNAL_BOOST )
+
+if(Boost_FOUND AND NOT Boost_VERSION VERSION_LESS "103600" )
+  include_directories(${Boost_INCLUDE_DIRS})
+else()
+  if(NOT BOOST_QUIETLY)
+    message("Boost >= 1.36 not found. Using minimal internal version. Not recommended if GROMACS is used as library!")
+  endif()
+  include_directories(${CMAKE_SOURCE_DIR}/src/external/boost)
+  add_definitions( -DBOOST_NO_TYPEID )  #TYPEID not supported for minimal internal version (would add significant more code)
+  # TODO: Propagate the above settings to the installed CMakeFiles.txt template
+  # (from share/template/)
+  # TODO: Reorder stuff such that INCL_INSTALL_DIR could be used here
+  set(PKG_CFLAGS "${PKG_CFLAGS} -DBOOST_NO_TYPEID -I${CMAKE_INSTALL_PREFIX}/include/gromacs/external/boost")
+  install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/external/boost/boost
+          DESTINATION ${CMAKE_INSTALL_PREFIX}/include/gromacs/external/boost
+          COMPONENT development)
+endif()
+set(BOOST_QUIETLY TRUE CACHE INTERNAL "")
+
+if (LIBXML2_FOUND)
+    option(GMX_BUILD_UNITTESTS "Build unit tests with BUILD_TESTING (uses Google C++ Testing and Mocking Frameworks, requires libxml2)" ON)
+else (LIBXML2_FOUND)
+    set(GMX_BUILD_UNITTESTS OFF)
+endif (LIBXML2_FOUND)
+mark_as_advanced(GMX_BUILD_UNITTESTS)
+set(MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/cmake/legacy_and_external.supp)
+
+find_package(Doxygen)
+
 ########################################################################
 # Generate development version info for cache
 ########################################################################
@@ -524,9 +522,11 @@ endif()
 ########################################################################
 
 add_definitions( -DHAVE_CONFIG_H )
+include_directories(${CMAKE_SOURCE_DIR}/src)
+# Required for config.h, maybe should only be set in src/CMakeLists.txt
 include_directories(${CMAKE_BINARY_DIR}/src)
-include_directories(${CMAKE_BINARY_DIR}/include)
-include_directories(${CMAKE_SOURCE_DIR}/include)
+# Required for now to make old code compile
+include_directories(${CMAKE_SOURCE_DIR}/src/gromacs/legacyheaders)
 
 include(gmxTestInlineASM)
 gmx_test_inline_asm_gcc_x86(GMX_X86_GCC_INLINE_ASM)
@@ -553,9 +553,6 @@ gmx_test_sigusr1(HAVE_SIGUSR1)
 include(gmxTestInline)
 gmx_test_inline(INLINE_KEYWORD)
 
-include(gmxTestRestrict)
-gmx_test_inline(RESTRICT_KEYWORD)
-
 include(gmxTestPipes)
 gmx_test_pipes(HAVE_PIPES)
 
@@ -564,6 +561,10 @@ gmx_test_isfinite(HAVE_ISFINITE)
 gmx_test__isfinite(HAVE__ISFINITE)
 gmx_test__finite(HAVE__FINITE)
 
+include(gmxTestCXX11)
+gmx_test_cxx11(GMX_CXX11 CXX11_FLAG)
+set(GROMACS_CXX_FLAGS "${CXX11_FLAG} ${GROMACS_CXX_FLAGS}")
+
 include(gmxTestXDR)
 gmx_test_xdr(GMX_SYSTEM_XDR)
 if(NOT GMX_SYSTEM_XDR)
@@ -752,14 +753,15 @@ if(GMX_FORTRAN OR GMX_POWER6)
 
     if(isupper)
         set(F77_FUNCDEF   "${prefix} NAME ${suffix}")
-        set(F77_FUNCDEF_  "${prefix} NAME ${extrasuffix}")
+        # The underscored versions are not currently used.
+        #set(F77_FUNCDEF_  "${prefix} NAME ${extrasuffix}")
     else(isupper)
         set(F77_FUNCDEF   "${prefix} name ${suffix}")
-        set(F77_FUNCDEF_  "${prefix} name ${extrasuffix}")
+        #set(F77_FUNCDEF_  "${prefix} name ${extrasuffix}")
     endif(isupper)
 else(GMX_FORTRAN OR GMX_POWER6)
         set(F77_FUNCDEF   "name ## _")
-        set(F77_FUNCDEF_  "name ## _")
+        #set(F77_FUNCDEF_  "name ## _")
 endif(GMX_FORTRAN OR GMX_POWER6)
 
 # Process QM/MM Settings
@@ -1019,7 +1021,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
 endif()
 
 add_subdirectory(share)
-add_subdirectory(include)
 add_subdirectory(man)
 add_subdirectory(src)
 add_subdirectory(scripts)
@@ -1037,6 +1038,39 @@ ADD_CUSTOM_TARGET(uninstall
                   "${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake")
 ###########################
 
+########################################################################
+# Doxygen configuration
+########################################################################
+if (DOXYGEN_FOUND)
+    FILE(GLOB NB_KERNEL_DIRS src/gromacs/gmxlib/nonbonded/nb_kernel_*/)
+    LIST(REMOVE_ITEM NB_KERNEL_DIRS
+         ${CMAKE_SOURCE_DIR}/src/gromacs/gmxlib/nonbonded/nb_kernel_c)
+    FOREACH(NB_KERNEL_DIR ${NB_KERNEL_DIRS})
+        SET(NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN
+            "${NB_KERNEL_DIRS_TO_IGNORE_IN_DOXYGEN} \\\n                         ${NB_KERNEL_DIR}")
+    ENDFOREACH(NB_KERNEL_DIR)
+    CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Doxyfile-common.cmakein
+                   ${CMAKE_BINARY_DIR}/Doxyfile-common)
+    CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Doxyfile.cmakein
+                   ${CMAKE_BINARY_DIR}/Doxyfile)
+    CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Doxyfile-lib.cmakein
+                   ${CMAKE_BINARY_DIR}/Doxyfile-lib)
+    CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/Doxyfile-user.cmakein
+                   ${CMAKE_BINARY_DIR}/Doxyfile-user)
+    add_custom_target(doc
+      ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
+      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+      COMMENT "Generating full documentation with Doxygen" VERBATIM)
+    add_custom_target(doc-user
+      ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-user
+      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+      COMMENT "Generating user documentation with Doxygen" VERBATIM)
+    add_custom_target(doc-lib
+      ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile-lib
+      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+      COMMENT "Generating libary documentation with Doxygen" VERBATIM)
+endif (DOXYGEN_FOUND)
+
 
 ########################################################################
 # Tests                                                                #
@@ -1045,7 +1079,7 @@ ADD_CUSTOM_TARGET(uninstall
 include(CTest)
 mark_as_advanced(BUILD_TESTING)
 IF(BUILD_TESTING)
-       enable_testing()
-       add_subdirectory(tests)
+    enable_testing()
+    add_subdirectory(tests)
 ENDIF()