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