912789403df6eeb2ca7239c0d6484427d8e22b3d
[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, 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 function (gmx_install_headers DESTINATION)
38     if (NOT GMX_BUILD_MDRUN_ONLY)
39         if (DESTINATION)
40             set(DESTINATION ${INCL_INSTALL_DIR}/gromacs/${DESTINATION})
41         else()
42             set(DESTINATION ${INCL_INSTALL_DIR}/gromacs)
43         endif()
44         install(FILES ${ARGN} DESTINATION ${DESTINATION} COMPONENT development)
45     endif()
46 endfunction ()
47
48 if(GMX_USE_TNG)
49     option(GMX_EXTERNAL_TNG "Use external TNG instead of compiling the version shipped with GROMACS."
50            OFF)
51     # Detect TNG if GMX_EXTERNAL_TNG is explicitly ON
52     if(GMX_EXTERNAL_TNG)
53         find_package(TNG_IO 1.6.0)
54         if(NOT TNG_IO_FOUND)
55             message(FATAL_ERROR
56                 "TNG >= 1.6.0 not found. "
57                 "You can set GMX_EXTERNAL_TNG=OFF to compile TNG.")
58         endif()
59         include_directories(${TNG_IO_INCLUDE_DIRS})
60     endif()
61     if(NOT GMX_EXTERNAL_TNG)
62         include(${CMAKE_SOURCE_DIR}/src/external/tng_io/BuildTNG.cmake)
63         tng_get_source_list(TNG_SOURCES TNG_IO_DEFINITIONS)
64         list(APPEND LIBGROMACS_SOURCES ${TNG_SOURCES})
65         tng_set_source_properties(WITH_ZLIB ${HAVE_ZLIB})
66
67         if (HAVE_ZLIB)
68             list(APPEND GMX_EXTRA_LIBRARIES ${ZLIB_LIBRARIES})
69             include_directories(${ZLIB_INCLUDE_DIRS})
70         endif()
71     endif()
72 else()
73     # We still need to get tng/tng_io_fwd.h from somewhere!
74     include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/tng_io/include)
75 endif()
76
77 add_subdirectory(gmxlib)
78 add_subdirectory(mdlib)
79 add_subdirectory(gmxpreprocess)
80 add_subdirectory(bonded)
81 add_subdirectory(commandline)
82 add_subdirectory(fft)
83 add_subdirectory(linearalgebra)
84 add_subdirectory(math)
85 add_subdirectory(random)
86 add_subdirectory(onlinehelp)
87 add_subdirectory(options)
88 add_subdirectory(pbcutil)
89 add_subdirectory(timing)
90 add_subdirectory(topology)
91 add_subdirectory(utility)
92 add_subdirectory(fileio)
93 add_subdirectory(swap)
94 add_subdirectory(essentialdynamics)
95 add_subdirectory(pulling)
96 add_subdirectory(simd)
97 add_subdirectory(imd)
98 if (NOT GMX_BUILD_MDRUN_ONLY)
99     add_subdirectory(legacyheaders)
100     add_subdirectory(gmxana)
101     add_subdirectory(statistics)
102     add_subdirectory(analysisdata)
103     add_subdirectory(selection)
104     add_subdirectory(trajectoryanalysis)
105     add_subdirectory(tools)
106 endif()
107
108 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES})
109
110 # This would be the standard way to include thread_mpi, but
111 # we want libgromacs to link the functions directly
112 #if(GMX_THREAD_MPI)
113 #    add_subdirectory(thread_mpi)
114 #endif()
115 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
116
117 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
118 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
119
120 set(LIBGROMACS_HEADERS
121     analysisdata.h
122     commandline.h
123     options.h
124     selection.h
125     trajectoryanalysis.h
126     utility.h)
127 configure_file(version.h.cmakein version.h)
128 gmx_install_headers("" ${LIBGROMACS_HEADERS})
129 gmx_install_headers("" ${CMAKE_CURRENT_BINARY_DIR}/version.h)
130
131 # This code is here instead of utility/CMakeLists.txt, because CMake
132 # custom commands and source file properties can only be set in the directory
133 # that contains the target that uses them.
134 # TODO: Generate a header instead that can be included from baseversion.c.
135 # That probably simplifies things somewhat.
136 set(GENERATED_VERSION_FILE utility/baseversion-gen.c)
137 gmx_configure_version_file(
138     utility/baseversion-gen.c.cmakein ${GENERATED_VERSION_FILE}
139     REMOTE_HASH SOURCE_FILE)
140 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
141
142 # apply gcc 4.4.x bug workaround
143 if(GMX_USE_GCC44_BUG_WORKAROUND)
144    include(gmxGCC44O3BugWorkaround)
145    gmx_apply_gcc44_bug_workaround("bonded/bonded.cpp")
146    gmx_apply_gcc44_bug_workaround("mdlib/force.c")
147    gmx_apply_gcc44_bug_workaround("mdlib/constr.c")
148 endif()
149
150 if (GMX_GPU)
151     cuda_add_library(libgromacs ${LIBGROMACS_SOURCES}
152             OPTIONS
153             RELWITHDEBINFO -g
154             DEBUG -g -D_DEBUG_=1)
155 else()
156     add_library(libgromacs ${LIBGROMACS_SOURCES})
157 endif()
158
159 # Recent versions of gcc and clang give warnings on scanner.cpp, which
160 # is a generated source file. These are awkward to suppress inline, so
161 # we do it in the compilation command (after testing that the compiler
162 # supports the suppressions). Setting the properties only works after
163 # the related target has been created, e.g. after when the file is
164 # used with add_library().
165 include(CheckCXXCompilerFlag)
166 check_cxx_compiler_flag(-Wno-unused-parameter HAS_NO_UNUSED_PARAMETER)
167 if (HAS_NO_UNUSED_PARAMETER)
168     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter")
169 endif()
170 check_cxx_compiler_flag(-Wno-deprecated-register HAS_NO_DEPRECATED_REGISTER)
171 if (HAS_NO_DEPRECATED_REGISTER)
172     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated-register")
173 else()
174     check_cxx_compiler_flag(-Wno-deprecated HAS_NO_DEPRECATED)
175     if (HAS_NO_DEPRECATED)
176         set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated")
177     endif()
178 endif()
179 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
180
181 target_link_libraries(libgromacs
182                       ${EXTRAE_LIBRARIES}
183                       ${GMX_EXTRA_LIBRARIES}
184                       ${TNG_IO_LIBRARIES}
185                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
186                       ${XML_LIBRARIES}
187                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS})
188 set_target_properties(libgromacs PROPERTIES
189                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
190                       SOVERSION ${LIBRARY_SOVERSION}
191                       VERSION ${LIBRARY_VERSION}
192                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
193
194 # Only install the library in mdrun-only mode if it is actually necessary
195 # for the binary
196 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
197     install(TARGETS libgromacs
198             EXPORT libgromacs
199             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
200             RUNTIME DESTINATION ${BIN_INSTALL_DIR}
201             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
202             COMPONENT libraries)
203 endif()
204
205 if (NOT GMX_BUILD_MDRUN_ONLY)
206     include(InstallLibInfo.cmake)
207 endif()
208
209 if (INSTALL_CUDART_LIB) #can be set manual by user
210     if (GMX_GPU)
211         foreach(CUDA_LIB ${CUDA_LIBRARIES})
212             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
213             if(IS_CUDART) #libcuda should not be installed
214                 #install also name-links (linker uses those)
215                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
216                 install(FILES ${CUDA_LIBS} DESTINATION
217                     ${LIB_INSTALL_DIR} COMPONENT libraries)
218             endif()
219         endforeach()
220     else()
221         message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
222     endif()
223 endif()