Move code for managing mdrun -cpi and -append
[alexxy/gromacs.git] / src / gromacs / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 set(LIBGROMACS_SOURCES)
36
37 set_property(GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
38
39 function (gmx_install_headers)
40     if (NOT GMX_BUILD_MDRUN_ONLY)
41         file(RELATIVE_PATH _dest ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR})
42         install(FILES       ${ARGN}
43                 DESTINATION "${INCL_INSTALL_DIR}/${_dest}"
44                 COMPONENT   development)
45     endif()
46     foreach (_file ${ARGN})
47         if (IS_ABSOLUTE "${_file}")
48             set_property(GLOBAL APPEND PROPERTY GMX_INSTALLED_HEADERS ${_file})
49         else()
50             set_property(GLOBAL APPEND PROPERTY GMX_INSTALLED_HEADERS
51                          ${CMAKE_CURRENT_LIST_DIR}/${_file})
52         endif()
53     endforeach()
54 endfunction ()
55
56 function (gmx_write_installed_header_list)
57     get_property(_list GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
58     string(REPLACE ";" "\n" _list "${_list}")
59     # TODO: Make this only update the file timestamp if the contents actually change.
60     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt "${_list}")
61 endfunction()
62
63 if(GMX_USE_TNG)
64     option(GMX_EXTERNAL_TNG "Use external TNG instead of compiling the version shipped with GROMACS."
65            OFF)
66     # Detect TNG if GMX_EXTERNAL_TNG is explicitly ON
67     if(GMX_EXTERNAL_TNG)
68         find_package(TNG_IO 1.6.0)
69         if(NOT TNG_IO_FOUND)
70             message(FATAL_ERROR
71                 "TNG >= 1.6.0 not found. "
72                 "You can set GMX_EXTERNAL_TNG=OFF to compile TNG.")
73         endif()
74         include_directories(${TNG_IO_INCLUDE_DIRS})
75     endif()
76     if(NOT GMX_EXTERNAL_TNG)
77         include(${CMAKE_SOURCE_DIR}/src/external/tng_io/BuildTNG.cmake)
78         tng_get_source_list(TNG_SOURCES TNG_IO_DEFINITIONS)
79         list(APPEND LIBGROMACS_SOURCES ${TNG_SOURCES})
80         tng_set_source_properties(WITH_ZLIB ${HAVE_ZLIB})
81
82         if (HAVE_ZLIB)
83             list(APPEND GMX_EXTRA_LIBRARIES ${ZLIB_LIBRARIES})
84             include_directories(${ZLIB_INCLUDE_DIRS})
85         endif()
86     endif()
87 else()
88     # We still need to get tng/tng_io_fwd.h from somewhere!
89     include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/tng_io/include)
90 endif()
91
92 add_subdirectory(gmxlib)
93 add_subdirectory(mdlib)
94 add_subdirectory(listed-forces)
95 add_subdirectory(commandline)
96 add_subdirectory(domdec)
97 add_subdirectory(ewald)
98 add_subdirectory(fft)
99 add_subdirectory(linearalgebra)
100 add_subdirectory(math)
101 add_subdirectory(mdrunutility)
102 add_subdirectory(random)
103 add_subdirectory(onlinehelp)
104 add_subdirectory(options)
105 add_subdirectory(pbcutil)
106 add_subdirectory(timing)
107 add_subdirectory(topology)
108 add_subdirectory(utility)
109 add_subdirectory(fileio)
110 add_subdirectory(swap)
111 add_subdirectory(essentialdynamics)
112 add_subdirectory(pulling)
113 add_subdirectory(simd)
114 add_subdirectory(imd)
115 if (NOT GMX_BUILD_MDRUN_ONLY)
116     add_subdirectory(legacyheaders)
117     add_subdirectory(gmxana)
118     add_subdirectory(gmxpreprocess)
119     add_subdirectory(correlationfunctions)
120     add_subdirectory(statistics)
121     add_subdirectory(analysisdata)
122     add_subdirectory(selection)
123     add_subdirectory(trajectoryanalysis)
124     add_subdirectory(tools)
125 endif()
126
127 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES})
128
129 # This would be the standard way to include thread_mpi, but
130 # we want libgromacs to link the functions directly
131 #if(GMX_THREAD_MPI)
132 #    add_subdirectory(thread_mpi)
133 #endif()
134 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
135
136 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
137 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
138
139 configure_file(version.h.cmakein version.h)
140 gmx_install_headers(
141     analysisdata.h
142     commandline.h
143     options.h
144     selection.h
145     trajectoryanalysis.h
146     utility.h
147     ${CMAKE_CURRENT_BINARY_DIR}/version.h
148     )
149
150 # This code is here instead of utility/CMakeLists.txt, because CMake
151 # custom commands and source file properties can only be set in the directory
152 # that contains the target that uses them.
153 # TODO: Generate a header instead that can be included from baseversion.c.
154 # That probably simplifies things somewhat.
155 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
156 gmx_configure_version_file(
157     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
158     REMOTE_HASH SOURCE_FILE)
159 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
160
161 # apply gcc 4.4.x bug workaround
162 if(GMX_USE_GCC44_BUG_WORKAROUND)
163    include(gmxGCC44O3BugWorkaround)
164    gmx_apply_gcc44_bug_workaround("listed-forces/bonded.cpp")
165    gmx_apply_gcc44_bug_workaround("mdlib/force.c")
166    gmx_apply_gcc44_bug_workaround("mdlib/constr.c")
167 endif()
168
169 if (GMX_GPU)
170     cuda_add_library(libgromacs ${LIBGROMACS_SOURCES}
171             OPTIONS
172             RELWITHDEBINFO -g
173             DEBUG -g -D_DEBUG_=1)
174 else()
175     add_library(libgromacs ${LIBGROMACS_SOURCES})
176 endif()
177
178 # Recent versions of gcc and clang give warnings on scanner.cpp, which
179 # is a generated source file. These are awkward to suppress inline, so
180 # we do it in the compilation command (after testing that the compiler
181 # supports the suppressions). Setting the properties only works after
182 # the related target has been created, e.g. after when the file is
183 # used with add_library().
184 include(CheckCXXCompilerFlag)
185 check_cxx_compiler_flag(-Wno-unused-parameter HAS_NO_UNUSED_PARAMETER)
186 if (HAS_NO_UNUSED_PARAMETER)
187     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter")
188 endif()
189 check_cxx_compiler_flag(-Wno-deprecated-register HAS_NO_DEPRECATED_REGISTER)
190 if (HAS_NO_DEPRECATED_REGISTER)
191     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated-register")
192 else()
193     check_cxx_compiler_flag(-Wno-deprecated HAS_NO_DEPRECATED)
194     if (HAS_NO_DEPRECATED)
195         set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated")
196     endif()
197 endif()
198 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
199
200 target_link_libraries(libgromacs
201                       ${EXTRAE_LIBRARIES}
202                       ${GMX_EXTRA_LIBRARIES}
203                       ${TNG_IO_LIBRARIES}
204                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
205                       ${XML_LIBRARIES}
206                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS})
207 set_target_properties(libgromacs PROPERTIES
208                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
209                       SOVERSION ${LIBRARY_SOVERSION_MAJOR}
210                       VERSION ${LIBRARY_VERSION}
211                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
212
213 gmx_write_installed_header_list()
214
215 # Only install the library in mdrun-only mode if it is actually necessary
216 # for the binary
217 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
218     install(TARGETS libgromacs
219             EXPORT libgromacs
220             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
221             RUNTIME DESTINATION ${BIN_INSTALL_DIR}
222             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
223             COMPONENT libraries)
224 endif()
225
226 if (NOT GMX_BUILD_MDRUN_ONLY)
227     include(InstallLibInfo.cmake)
228 endif()
229
230 if (INSTALL_CUDART_LIB) #can be set manual by user
231     if (GMX_GPU)
232         foreach(CUDA_LIB ${CUDA_LIBRARIES})
233             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
234             if(IS_CUDART) #libcuda should not be installed
235                 #install also name-links (linker uses those)
236                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
237                 install(FILES ${CUDA_LIBS} DESTINATION
238                     ${LIB_INSTALL_DIR} COMPONENT libraries)
239             endif()
240         endforeach()
241     else()
242         message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
243     endif()
244 endif()