3fc93c45fd3252efbaf3180fe8e6e7b2ddd05792
[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,2016,2017,2018, 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 if (GMX_CLANG_CUDA)
38     include(gmxClangCudaUtils)
39 endif()
40
41 set_property(GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
42 set_property(GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
43 set_property(GLOBAL PROPERTY GMX_AVX_512_SOURCE)
44
45 function (_gmx_add_files_to_property PROPERTY)
46     foreach (_file ${ARGN})
47         if (IS_ABSOLUTE "${_file}")
48             set_property(GLOBAL APPEND PROPERTY ${PROPERTY} ${_file})
49         else()
50             set_property(GLOBAL APPEND PROPERTY ${PROPERTY}
51                          ${CMAKE_CURRENT_LIST_DIR}/${_file})
52         endif()
53     endforeach()
54 endfunction ()
55
56 function (gmx_add_libgromacs_sources)
57     _gmx_add_files_to_property(GMX_LIBGROMACS_SOURCES ${ARGN})
58 endfunction ()
59
60 function (gmx_install_headers)
61     if (NOT GMX_BUILD_MDRUN_ONLY)
62         file(RELATIVE_PATH _dest ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR})
63         install(FILES       ${ARGN}
64                 DESTINATION "${INCL_INSTALL_DIR}/${_dest}"
65                 COMPONENT   development)
66     endif()
67     _gmx_add_files_to_property(GMX_INSTALLED_HEADERS ${ARGN})
68 endfunction ()
69
70 function (gmx_write_installed_header_list)
71     get_property(_list GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
72     string(REPLACE ";" "\n" _list "${_list}")
73     # TODO: Make this only update the file timestamp if the contents actually change.
74     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt "${_list}")
75 endfunction()
76
77 add_subdirectory(gmxlib)
78 add_subdirectory(mdlib)
79 add_subdirectory(applied-forces)
80 add_subdirectory(listed-forces)
81 add_subdirectory(commandline)
82 add_subdirectory(domdec)
83 add_subdirectory(ewald)
84 add_subdirectory(fft)
85 add_subdirectory(gpu_utils)
86 add_subdirectory(hardware)
87 add_subdirectory(linearalgebra)
88 add_subdirectory(math)
89 add_subdirectory(mdrunutility)
90 add_subdirectory(mdtypes)
91 add_subdirectory(onlinehelp)
92 add_subdirectory(options)
93 add_subdirectory(pbcutil)
94 add_subdirectory(random)
95 add_subdirectory(tables)
96 add_subdirectory(taskassignment)
97 add_subdirectory(timing)
98 add_subdirectory(topology)
99 add_subdirectory(trajectory)
100 add_subdirectory(utility)
101 add_subdirectory(fileio)
102 add_subdirectory(swap)
103 add_subdirectory(essentialdynamics)
104 add_subdirectory(pulling)
105 add_subdirectory(awh)
106 add_subdirectory(simd)
107 add_subdirectory(imd)
108 if (NOT GMX_BUILD_MDRUN_ONLY)
109     add_subdirectory(gmxana)
110     add_subdirectory(gmxpreprocess)
111     add_subdirectory(correlationfunctions)
112     add_subdirectory(statistics)
113     add_subdirectory(analysisdata)
114     add_subdirectory(selection)
115     add_subdirectory(trajectoryanalysis)
116     add_subdirectory(energyanalysis)
117     add_subdirectory(tools)
118 endif()
119
120 get_property(PROPERTY_SOURCES GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
121 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES} ${PROPERTY_SOURCES})
122
123 # This would be the standard way to include thread_mpi, but
124 # we want libgromacs to link the functions directly
125 #if(GMX_THREAD_MPI)
126 #    add_subdirectory(thread_mpi)
127 #endif()
128 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
129
130 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
131 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
132
133 get_lmfit_properties(LMFIT_SOURCES LMFIT_LIBRARIES_TO_LINK LMFIT_INCLUDE_DIRECTORY LMFIT_INCLUDE_DIR_ORDER)
134 include_directories(${LMFIT_INCLUDE_DIR_ORDER} SYSTEM "${LMFIT_INCLUDE_DIRECTORY}")
135 list(APPEND LIBGROMACS_SOURCES ${LMFIT_SOURCES})
136
137 configure_file(version.h.cmakein version.h)
138 gmx_install_headers(
139     analysisdata.h
140     commandline.h
141     options.h
142     random.h
143     selection.h
144     trajectoryanalysis.h
145     utility.h
146     ${CMAKE_CURRENT_BINARY_DIR}/version.h
147     )
148
149 # This code is here instead of utility/CMakeLists.txt, because CMake
150 # custom commands and source file properties can only be set in the directory
151 # that contains the target that uses them.
152 # TODO: Generate a header instead that can be included from baseversion.c.
153 # That probably simplifies things somewhat.
154 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
155 gmx_configure_version_file(
156     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
157     REMOTE_HASH)
158 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
159
160 # set up CUDA compilation with clang
161 if (GMX_CLANG_CUDA)
162     foreach (_file ${LIBGROMACS_SOURCES})
163         get_filename_component(_ext ${_file} EXT)
164         if (${_ext} STREQUAL ".cu")
165             gmx_compile_cuda_file_with_clang(${_file})
166         endif()
167     endforeach()
168 endif()
169
170 if (GMX_USE_CUDA)
171     # Work around FindCUDA that prevents using target_link_libraries()
172     # with keywords otherwise...
173     set(CUDA_LIBRARIES PRIVATE ${CUDA_LIBRARIES})
174     if (NOT GMX_CLANG_CUDA)
175         cuda_add_library(libgromacs ${LIBGROMACS_SOURCES})
176     else()
177         add_library(libgromacs ${LIBGROMACS_SOURCES})
178     endif()
179     target_link_libraries(libgromacs PRIVATE ${CUDA_CUFFT_LIBRARIES})
180 else()
181     add_library(libgromacs ${LIBGROMACS_SOURCES})
182 endif()
183
184 # Recent versions of gcc and clang give warnings on scanner.cpp, which
185 # is a generated source file. These are awkward to suppress inline, so
186 # we do it in the compilation command (after testing that the compiler
187 # supports the suppressions).
188 include(CheckCXXCompilerFlag)
189 check_cxx_compiler_flag(-Wno-unused HAS_NO_UNUSED)
190 if (HAS_NO_UNUSED)
191     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter -Wno-unused-function")
192 endif()
193 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
194
195 if(SIMD_AVX_512_CXX_SUPPORTED AND NOT ("${GMX_SIMD_ACTIVE}" STREQUAL "AVX_512_KNL"))
196     # Since we might be overriding -march=core-avx2, add a flag so we don't warn for this specific file.
197     # On KNL this can cause illegal instruction because the compiler might use non KNL AVX instructions
198     # with the SIMD_AVX_512_CXX_FLAGS flags.
199     set_source_files_properties(hardware/identifyavx512fmaunits.cpp PROPERTIES COMPILE_FLAGS "${SIMD_AVX_512_CXX_FLAGS} ${CXX_NO_UNUSED_OPTION_WARNING_FLAGS}")
200 endif()
201
202 gmx_setup_tng_for_libgromacs()
203
204 target_link_libraries(libgromacs
205                       PRIVATE
206                       ${EXTRAE_LIBRARIES}
207                       ${GMX_EXTRA_LIBRARIES}
208                       ${GMX_COMMON_LIBRARIES}
209                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
210                       ${LMFIT_LIBRARIES_TO_LINK}
211                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS} ${OPENCL_LIBRARIES}
212                       ${GMX_STDLIB_LIBRARIES}
213                       PUBLIC
214                       ${GMX_PUBLIC_LIBRARIES}
215                       )
216 set_target_properties(libgromacs PROPERTIES
217                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
218                       SOVERSION ${LIBRARY_SOVERSION_MAJOR}
219                       VERSION ${LIBRARY_VERSION}
220                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
221
222 gmx_write_installed_header_list()
223
224 # Only install the library in mdrun-only mode if it is actually necessary
225 # for the binary
226 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
227     install(TARGETS libgromacs
228             EXPORT libgromacs
229             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
230             RUNTIME DESTINATION ${BIN_INSTALL_DIR}
231             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
232             COMPONENT libraries)
233 endif()
234
235 if (NOT GMX_BUILD_MDRUN_ONLY)
236     include(InstallLibInfo.cmake)
237 endif()
238
239 # Technically, the user could want to do this for an OpenCL build
240 # using the CUDA runtime, but currently there's no reason to want to
241 # do that.
242 if (INSTALL_CUDART_LIB) #can be set manual by user
243     if (GMX_USE_CUDA)
244         foreach(CUDA_LIB ${CUDA_LIBRARIES})
245             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
246             if(IS_CUDART) #libcuda should not be installed
247                 #install also name-links (linker uses those)
248                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
249                 install(FILES ${CUDA_LIBS} DESTINATION
250                     ${LIB_INSTALL_DIR} COMPONENT libraries)
251             endif()
252         endforeach()
253     else()
254         message(WARNING "INSTALL_CUDART_LIB only makes sense when configuring for CUDA support")
255     endif()
256 endif()
257
258 if(GMX_USE_OPENCL)
259     set(OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS})
260
261     install(FILES ${OPENCL_KERNELS} DESTINATION
262         ${OCL_INSTALL_DIR} COMPONENT libraries)
263 endif()
264
265 if (BUILD_TESTING)
266     add_subdirectory(compat/tests)
267 endif()