Added the bundled clFFT into OpenCL builds
[gromacs.git] / src / gromacs / CMakeLists.txt
blob52bc8e1900bc91ab46de14509e3cc6f01ccbae39
2 # This file is part of the GROMACS molecular simulation package.
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.
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 if (GMX_CLANG_CUDA)
38     include(gmxClangCudaUtils)
39 endif()
41 set_property(GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
42 set_property(GLOBAL PROPERTY GMX_LIBGROMACS_GPU_IMPL_SOURCES)
43 set_property(GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
44 set_property(GLOBAL PROPERTY GMX_AVX_512_SOURCE)
46 function (_gmx_add_files_to_property PROPERTY)
47     foreach (_file ${ARGN})
48         if (IS_ABSOLUTE "${_file}")
49             set_property(GLOBAL APPEND PROPERTY ${PROPERTY} ${_file})
50         else()
51             set_property(GLOBAL APPEND PROPERTY ${PROPERTY}
52                          ${CMAKE_CURRENT_LIST_DIR}/${_file})
53         endif()
54     endforeach()
55 endfunction ()
57 function (gmx_add_libgromacs_sources)
58     _gmx_add_files_to_property(GMX_LIBGROMACS_SOURCES ${ARGN})
59 endfunction ()
61 # TODO Reconsider this, as the CUDA driver API is probably a simpler
62 # approach, at least for the build system. See Redmine #2530
63 function (gmx_compile_cpp_as_cuda)
64     _gmx_add_files_to_property(GMX_LIBGROMACS_GPU_IMPL_SOURCES ${ARGN})
65 endfunction ()
67 function (gmx_install_headers)
68     if (NOT GMX_BUILD_MDRUN_ONLY)
69         file(RELATIVE_PATH _dest ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_LIST_DIR})
70         install(FILES       ${ARGN}
71                 DESTINATION "${INCL_INSTALL_DIR}/${_dest}"
72                 COMPONENT   development)
73     endif()
74     _gmx_add_files_to_property(GMX_INSTALLED_HEADERS ${ARGN})
75 endfunction ()
77 function (gmx_write_installed_header_list)
78     get_property(_list GLOBAL PROPERTY GMX_INSTALLED_HEADERS)
79     string(REPLACE ";" "\n" _list "${_list}")
80     # TODO: Make this only update the file timestamp if the contents actually change.
81     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/installed-headers.txt "${_list}")
82 endfunction()
84 add_subdirectory(gmxlib)
85 add_subdirectory(mdlib)
86 add_subdirectory(applied-forces)
87 add_subdirectory(listed-forces)
88 add_subdirectory(commandline)
89 add_subdirectory(domdec)
90 add_subdirectory(ewald)
91 add_subdirectory(fft)
92 add_subdirectory(gpu_utils)
93 add_subdirectory(hardware)
94 add_subdirectory(linearalgebra)
95 add_subdirectory(math)
96 add_subdirectory(mdrun)
97 add_subdirectory(mdrunutility)
98 add_subdirectory(mdtypes)
99 add_subdirectory(onlinehelp)
100 add_subdirectory(options)
101 add_subdirectory(pbcutil)
102 add_subdirectory(random)
103 add_subdirectory(tables)
104 add_subdirectory(taskassignment)
105 add_subdirectory(timing)
106 add_subdirectory(topology)
107 add_subdirectory(trajectory)
108 add_subdirectory(utility)
109 add_subdirectory(fileio)
110 add_subdirectory(swap)
111 add_subdirectory(essentialdynamics)
112 add_subdirectory(pulling)
113 add_subdirectory(awh)
114 add_subdirectory(simd)
115 add_subdirectory(imd)
116 if (NOT GMX_BUILD_MDRUN_ONLY)
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(energyanalysis)
125     add_subdirectory(tools)
126 endif()
128 get_property(PROPERTY_SOURCES GLOBAL PROPERTY GMX_LIBGROMACS_SOURCES)
129 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES} ${PROPERTY_SOURCES})
131 # This would be the standard way to include thread_mpi, but
132 # we want libgromacs to link the functions directly
133 #if(GMX_THREAD_MPI)
134 #    add_subdirectory(thread_mpi)
135 #endif()
136 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
138 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
139 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
141 get_lmfit_properties(LMFIT_SOURCES LMFIT_LIBRARIES_TO_LINK LMFIT_INCLUDE_DIRECTORY LMFIT_INCLUDE_DIR_ORDER)
142 include_directories(${LMFIT_INCLUDE_DIR_ORDER} SYSTEM "${LMFIT_INCLUDE_DIRECTORY}")
143 list(APPEND LIBGROMACS_SOURCES ${LMFIT_SOURCES})
145 configure_file(version.h.cmakein version.h)
146 gmx_install_headers(
147     analysisdata.h
148     commandline.h
149     options.h
150     random.h
151     selection.h
152     trajectoryanalysis.h
153     utility.h
154     ${CMAKE_CURRENT_BINARY_DIR}/version.h
155     )
157 # This code is here instead of utility/CMakeLists.txt, because CMake
158 # custom commands and source file properties can only be set in the directory
159 # that contains the target that uses them.
160 # TODO: Generate a header instead that can be included from baseversion.c.
161 # That probably simplifies things somewhat.
162 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
163 gmx_configure_version_file(
164     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
165     REMOTE_HASH)
166 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
168 # Mark some shared GPU implementation files to compile with CUDA if needed
169 if (GMX_USE_CUDA)
170     get_property(LIBGROMACS_GPU_IMPL_SOURCES GLOBAL PROPERTY GMX_LIBGROMACS_GPU_IMPL_SOURCES)
171     set_source_files_properties(${LIBGROMACS_GPU_IMPL_SOURCES} PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ)
172 endif()
174 # set up CUDA compilation with clang
175 if (GMX_CLANG_CUDA)
176     foreach (_file ${LIBGROMACS_SOURCES})
177         get_filename_component(_ext ${_file} EXT)
178         get_source_file_property(_cuda_source_format ${_file} CUDA_SOURCE_PROPERTY_FORMAT)
179         if (${_ext} STREQUAL ".cu" OR _cuda_source_format)
180             gmx_compile_cuda_file_with_clang(${_file})
181         endif()
182     endforeach()
183 endif()
185 if (GMX_USE_CUDA)
186     # Work around FindCUDA that prevents using target_link_libraries()
187     # with keywords otherwise...
188     set(CUDA_LIBRARIES PRIVATE ${CUDA_LIBRARIES})
189     if (NOT GMX_CLANG_CUDA)
190         cuda_add_library(libgromacs ${LIBGROMACS_SOURCES})
191     else()
192         add_library(libgromacs ${LIBGROMACS_SOURCES})
193     endif()
194     target_link_libraries(libgromacs PRIVATE ${CUDA_CUFFT_LIBRARIES})
195 else()
196     add_library(libgromacs ${LIBGROMACS_SOURCES})
197 endif()
199 # TODO: installed clFFT should be preferred, if possible;
200 # src/external/src/clFFT/FindclFFT.cmake should help with that.
201 # Redmine issue #2500
202 if (GMX_USE_OPENCL)
203     set (_clFFT_dir ../external/clFFT/src)
204     add_subdirectory(${_clFFT_dir} clFFT-build)
205     target_sources(libgromacs PRIVATE
206         $<TARGET_OBJECTS:clFFT>
207         )
208     target_include_directories(libgromacs PRIVATE ${_clFFT_dir}/include)
209     # Use the magic variable for how to link any library needed for
210     # dlopen, etc.  which is -ldl where needed, and empty otherwise
211     # (e.g. Windows, BSD, Mac).
212     target_link_libraries(libgromacs PRIVATE "${CMAKE_DL_LIBS}")
213 endif()
215 # Recent versions of gcc and clang give warnings on scanner.cpp, which
216 # is a generated source file. These are awkward to suppress inline, so
217 # we do it in the compilation command (after testing that the compiler
218 # supports the suppressions).
219 include(CheckCXXCompilerFlag)
220 check_cxx_compiler_flag(-Wno-unused HAS_NO_UNUSED)
221 if (HAS_NO_UNUSED)
222     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter -Wno-unused-function")
223 endif()
224 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
226 if(SIMD_AVX_512_CXX_SUPPORTED)
227     # Since we might be overriding -march=core-avx2, add a flag so we don't warn for this specific file
228     set_source_files_properties(hardware/identifyavx512fmaunits.cpp PROPERTIES COMPILE_FLAGS "${SIMD_AVX_512_CXX_FLAGS} ${CXX_NO_UNUSED_OPTION_WARNING_FLAGS}")
229 endif()
231 gmx_setup_tng_for_libgromacs()
233 target_link_libraries(libgromacs
234                       PRIVATE
235                       ${EXTRAE_LIBRARIES}
236                       ${GMX_EXTRA_LIBRARIES}
237                       ${GMX_COMMON_LIBRARIES}
238                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
239                       ${LMFIT_LIBRARIES_TO_LINK}
240                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS}
241                       ${OpenCL_LIBRARIES}
242                       ${GMX_STDLIB_LIBRARIES}
243                       PUBLIC
244                       ${GMX_PUBLIC_LIBRARIES}
245                       )
246 set_target_properties(libgromacs PROPERTIES
247                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
248                       SOVERSION ${LIBRARY_SOVERSION_MAJOR}
249                       VERSION ${LIBRARY_VERSION}
250                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
252 gmx_write_installed_header_list()
254 # Only install the library in mdrun-only mode if it is actually necessary
255 # for the binary
256 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
257     install(TARGETS libgromacs
258             EXPORT libgromacs
259             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
260             RUNTIME DESTINATION ${BIN_INSTALL_DIR}
261             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
262             COMPONENT libraries)
263 endif()
265 if (NOT GMX_BUILD_MDRUN_ONLY)
266     include(InstallLibInfo.cmake)
267 endif()
269 # Technically, the user could want to do this for an OpenCL build
270 # using the CUDA runtime, but currently there's no reason to want to
271 # do that.
272 if (INSTALL_CUDART_LIB) #can be set manual by user
273     if (GMX_USE_CUDA)
274         foreach(CUDA_LIB ${CUDA_LIBRARIES})
275             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
276             if(IS_CUDART) #libcuda should not be installed
277                 #install also name-links (linker uses those)
278                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
279                 install(FILES ${CUDA_LIBS} DESTINATION
280                     ${LIB_INSTALL_DIR} COMPONENT libraries)
281             endif()
282         endforeach()
283     else()
284         message(WARNING "INSTALL_CUDART_LIB only makes sense when configuring for CUDA support")
285     endif()
286 endif()
288 if(GMX_USE_OPENCL)
289     set(OPENCL_KERNELS ${MDLIB_OPENCL_KERNELS})
291     install(FILES ${OPENCL_KERNELS} DESTINATION
292         ${OCL_INSTALL_DIR} COMPONENT libraries)
293 endif()
295 if (BUILD_TESTING)
296     add_subdirectory(compat/tests)
297 endif()