Merge branch release-5-1
[gromacs.git] / src / gromacs / CMakeLists.txt
bloba2f0382e0071c5ea5963cb0f480824813985737d
2 # This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
35 set(LIBGROMACS_SOURCES)
37 set_property(GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
38 set_property(GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
40 function (_gmx_add_files_to_property PROPERTY)
41     foreach (_file ${ARGN})
42         if (IS_ABSOLUTE "${_file}")
43             set_property(GLOBAL APPEND PROPERTY ${PROPERTY} ${_file})
44         else()
45             set_property(GLOBAL APPEND PROPERTY ${PROPERTY}
46                          ${CMAKE_CURRENT_LIST_DIR}/${_file})
47         endif()
48     endforeach()
49 endfunction ()
51 function (gmx_add_libgromacs_sources)
52     _gmx_add_files_to_property(GMX_LIBGROMACS_SOURCES ${ARGN})
53 endfunction ()
55 function (gmx_install_headers)
56     if (NOT GMX_BUILD_MDRUN_ONLY)
57         file(RELATIVE_PATH _dest ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR})
58         install(FILES       ${ARGN}
59                 DESTINATION "${INCL_INSTALL_DIR}/${_dest}"
60                 COMPONENT   development)
61     endif()
62     _gmx_add_files_to_property(GMX_INSTALLED_HEADERS ${ARGN})
63 endfunction ()
65 function (gmx_write_installed_header_list)
66     get_property(_list GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
67     string(REPLACE ";" "\n" _list "${_list}")
68     # TODO: Make this only update the file timestamp if the contents actually change.
69     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt "${_list}")
70 endfunction()
72 if(GMX_USE_TNG)
73     option(GMX_EXTERNAL_TNG "Use external TNG instead of compiling the version shipped with GROMACS."
74            OFF)
75     # Detect TNG if GMX_EXTERNAL_TNG is explicitly ON
76     if(GMX_EXTERNAL_TNG)
77         find_package(TNG_IO 1.6.0)
78         if(NOT TNG_IO_FOUND)
79             message(FATAL_ERROR
80                 "TNG >= 1.6.0 not found. "
81                 "You can set GMX_EXTERNAL_TNG=OFF to compile TNG.")
82         endif()
83         include_directories(SYSTEM ${TNG_IO_INCLUDE_DIRS})
84     endif()
85     if(NOT GMX_EXTERNAL_TNG)
86         include(${CMAKE_SOURCE_DIR}/src/external/tng_io/BuildTNG.cmake)
87         tng_get_source_list(TNG_SOURCES TNG_IO_DEFINITIONS)
88         list(APPEND LIBGROMACS_SOURCES ${TNG_SOURCES})
89         tng_set_source_properties(WITH_ZLIB ${HAVE_ZLIB})
91         if (HAVE_ZLIB)
92             list(APPEND GMX_EXTRA_LIBRARIES ${ZLIB_LIBRARIES})
93             include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
94         endif()
95     endif()
96 else()
97     # We still need to get tng/tng_io_fwd.h from somewhere!
98     include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/tng_io/include)
99 endif()
101 add_subdirectory(gmxlib)
102 add_subdirectory(mdlib)
103 add_subdirectory(listed-forces)
104 add_subdirectory(commandline)
105 add_subdirectory(domdec)
106 add_subdirectory(ewald)
107 add_subdirectory(fft)
108 add_subdirectory(gpu_utils)
109 add_subdirectory(hardware)
110 add_subdirectory(linearalgebra)
111 add_subdirectory(math)
112 add_subdirectory(mdrunutility)
113 add_subdirectory(mdtypes)
114 add_subdirectory(random)
115 add_subdirectory(onlinehelp)
116 add_subdirectory(options)
117 add_subdirectory(pbcutil)
118 add_subdirectory(tables)
119 add_subdirectory(timing)
120 add_subdirectory(topology)
121 add_subdirectory(trajectory)
122 add_subdirectory(utility)
123 add_subdirectory(fileio)
124 add_subdirectory(swap)
125 add_subdirectory(essentialdynamics)
126 add_subdirectory(pulling)
127 add_subdirectory(simd)
128 add_subdirectory(imd)
129 if (NOT GMX_BUILD_MDRUN_ONLY)
130     add_subdirectory(gmxana)
131     add_subdirectory(gmxpreprocess)
132     add_subdirectory(correlationfunctions)
133     add_subdirectory(statistics)
134     add_subdirectory(analysisdata)
135     add_subdirectory(selection)
136     add_subdirectory(trajectoryanalysis)
137     add_subdirectory(tools)
138 endif()
140 get_property(PROPERTY_SOURCES GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
141 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES} ${PROPERTY_SOURCES})
143 # This would be the standard way to include thread_mpi, but
144 # we want libgromacs to link the functions directly
145 #if(GMX_THREAD_MPI)
146 #    add_subdirectory(thread_mpi)
147 #endif()
148 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
150 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
151 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
153 configure_file(version.h.cmakein version.h)
154 gmx_install_headers(
155     analysisdata.h
156     commandline.h
157     options.h
158     selection.h
159     trajectoryanalysis.h
160     utility.h
161     ${CMAKE_CURRENT_BINARY_DIR}/version.h
162     )
164 # This code is here instead of utility/CMakeLists.txt, because CMake
165 # custom commands and source file properties can only be set in the directory
166 # that contains the target that uses them.
167 # TODO: Generate a header instead that can be included from baseversion.c.
168 # That probably simplifies things somewhat.
169 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
170 gmx_configure_version_file(
171     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
172     REMOTE_HASH SOURCE_FILE)
173 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
175 if (GMX_USE_CUDA)
176     cuda_add_library(libgromacs ${LIBGROMACS_SOURCES})
177 else()
178     add_library(libgromacs ${LIBGROMACS_SOURCES})
179 endif()
181 # Recent versions of gcc and clang give warnings on scanner.cpp, which
182 # is a generated source file. These are awkward to suppress inline, so
183 # we do it in the compilation command (after testing that the compiler
184 # supports the suppressions).
185 include(CheckCXXCompilerFlag)
186 check_cxx_compiler_flag(-Wno-unused-parameter HAS_NO_UNUSED_PARAMETER)
187 if (HAS_NO_UNUSED_PARAMETER)
188     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter")
189 endif()
190 check_cxx_compiler_flag(-Wno-deprecated-register HAS_NO_DEPRECATED_REGISTER)
191 if (HAS_NO_DEPRECATED_REGISTER)
192     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated-register")
193 else()
194     check_cxx_compiler_flag(-Wno-deprecated HAS_NO_DEPRECATED)
195     if (HAS_NO_DEPRECATED)
196         set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated")
197     endif()
198 endif()
199 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
201 target_link_libraries(libgromacs
202                       ${EXTRAE_LIBRARIES}
203                       ${GMX_EXTRA_LIBRARIES}
204                       ${TNG_IO_LIBRARIES}
205                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
206                       ${XML_LIBRARIES}
207                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES})
208 set_target_properties(libgromacs PROPERTIES
209                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
210                       SOVERSION ${LIBRARY_SOVERSION_MAJOR}
211                       VERSION ${LIBRARY_VERSION}
212                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
214 gmx_write_installed_header_list()
216 # Only install the library in mdrun-only mode if it is actually necessary
217 # for the binary
218 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
219     install(TARGETS libgromacs
220             EXPORT libgromacs
221             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
222             RUNTIME DESTINATION ${BIN_INSTALL_DIR}
223             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
224             COMPONENT libraries)
225 endif()
227 if (NOT GMX_BUILD_MDRUN_ONLY)
228     include(InstallLibInfo.cmake)
229 endif()
231 # Technically, the user could want to do this for an OpenCL build
232 # using the CUDA runtime, but currently there's no reason to want to
233 # do that.
234 if (INSTALL_CUDART_LIB) #can be set manual by user
235     if (GMX_USE_CUDA)
236         foreach(CUDA_LIB ${CUDA_LIBRARIES})
237             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
238             if(IS_CUDART) #libcuda should not be installed
239                 #install also name-links (linker uses those)
240                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
241                 install(FILES ${CUDA_LIBS} DESTINATION
242                     ${LIB_INSTALL_DIR} COMPONENT libraries)
243             endif()
244         endforeach()
245     else()
246         message(WARNING "INSTALL_CUDART_LIB only makes sense when configuring for CUDA support")
247     endif()
248 endif()
250 if(GMX_USE_OPENCL)
251     set(OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS})
253     install(FILES ${OPENCL_KERNELS} DESTINATION
254         ${OCL_INSTALL_DIR} COMPONENT libraries)
255 endif()