Merge release-5-0 into master
[alexxy/gromacs.git] / share / template / CMakeLists.txt.template
1 cmake_minimum_required(VERSION 2.8.8)
2
3 project(template CXX)
4
5 if (NOT CMAKE_BUILD_TYPE)
6     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
7 endif()
8
9 # CMake modules are in a subdirectory to keep this file cleaner
10 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
11
12 # In principle, this could be deduced from GROMACS_IS_DOUBLE returned by
13 # find_package(GROMACS) based on the suffix alone, but it is clearer that the
14 # user explicitly sets what they want to get, and then need to provide a suffix
15 # to match.
16 option(GMX_DOUBLE "Use double precision" OFF)
17 set(GMX_SUFFIX "" CACHE STRING "Suffix for the GROMACS installation to use (empty for default)")
18
19 # This does not allow for a non-suffixed double-precision libgromacs, but
20 # that should be rare enough for demonstration purposes.
21 if (GMX_DOUBLE AND NOT GMX_SUFFIX)
22     set(GROMACS_SUFFIX "_d")
23 else()
24     set(GROMACS_SUFFIX ${GMX_SUFFIX})
25 endif()
26
27 find_package(GROMACS 5.1 REQUIRED)
28 gromacs_check_double(GMX_DOUBLE)
29 gromacs_check_compiler(CXX)
30 include_directories(${GROMACS_INCLUDE_DIRS})
31 add_definitions(${GROMACS_DEFINITIONS})
32
33 # Use static linking on MSVC
34 if (CMAKE_GENERATOR MATCHES "Visual Studio")
35     string(REPLACE /MD /MT CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
36     set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE)
37     string(REPLACE /MD /MT CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
38     set(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "" FORCE)
39 endif()
40
41 add_executable(template template.cpp)
42 target_link_libraries(template ${GROMACS_LIBRARIES})