Fix zlib usage with TNG
[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         # TNG wants zlib if it is available
63         find_package(ZLIB QUIET)
64         include(gmxTestZLib)
65         gmx_test_zlib(HAVE_ZLIB)
66
67         include(${CMAKE_SOURCE_DIR}/src/external/tng_io/BuildTNG.cmake)
68         tng_get_source_list(TNG_SOURCES TNG_IO_DEFINITIONS)
69         list(APPEND LIBGROMACS_SOURCES ${TNG_SOURCES})
70         tng_set_source_properties(WITH_ZLIB ${HAVE_ZLIB})
71
72         if (HAVE_ZLIB)
73             list(APPEND GMX_EXTRA_LIBRARIES ${ZLIB_LIBRARIES})
74             include_directories(${ZLIB_INCLUDE_DIRS})
75         endif()
76     endif()
77 else()
78     # We still need to get tng/tng_io_fwd.h from somewhere!
79     include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src/external/tng_io/include)
80 endif()
81
82 add_subdirectory(gmxlib)
83 add_subdirectory(mdlib)
84 add_subdirectory(gmxpreprocess)
85 add_subdirectory(commandline)
86 add_subdirectory(fft)
87 add_subdirectory(linearalgebra)
88 add_subdirectory(math)
89 add_subdirectory(random)
90 add_subdirectory(onlinehelp)
91 add_subdirectory(options)
92 add_subdirectory(timing)
93 add_subdirectory(utility)
94 add_subdirectory(fileio)
95 add_subdirectory(swap)
96 add_subdirectory(essentialdynamics)
97 add_subdirectory(pulling)
98 add_subdirectory(simd)
99 add_subdirectory(imd)
100 if (NOT GMX_BUILD_MDRUN_ONLY)
101     add_subdirectory(legacyheaders)
102     add_subdirectory(gmxana)
103     add_subdirectory(statistics)
104     add_subdirectory(analysisdata)
105     add_subdirectory(selection)
106     add_subdirectory(trajectoryanalysis)
107     add_subdirectory(tools)
108 endif()
109
110 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES})
111
112 # This would be the standard way to include thread_mpi, but
113 # we want libgromacs to link the functions directly
114 #if(GMX_THREAD_MPI)
115 #    add_subdirectory(thread_mpi)
116 #endif()
117 #target_link_libraries(gmx ${GMX_EXTRA_LIBRARIES} ${THREAD_MPI_LIB})
118
119 tmpi_get_source_list(THREAD_MPI_SOURCES ${CMAKE_SOURCE_DIR}/src/external/thread_mpi/src)
120 list(APPEND LIBGROMACS_SOURCES ${THREAD_MPI_SOURCES})
121
122 file(GLOB LIBGROMACS_HEADERS *.h)
123 configure_file(version.h.cmakein version.h)
124 gmx_install_headers("" ${LIBGROMACS_HEADERS})
125 gmx_install_headers("" ${CMAKE_CURRENT_BINARY_DIR}/version.h)
126
127 # Add target that generates baseversion-gen.c every time make is run
128 # if git version info is requested, or create it statically.
129 # This code is here instead of utility/CMakeLists.txt because CMake
130 # ignores set_source_file_properties from subdirectories.
131 set(GENERATED_VERSION_FILE
132     ${CMAKE_CURRENT_BINARY_DIR}/utility/baseversion-gen.c)
133 set(GENERATED_VERSION_FILE_SOURCE
134     ${CMAKE_CURRENT_SOURCE_DIR}/utility/baseversion-gen.c.cmakein)
135 if (GMX_GIT_VERSION_INFO)
136     add_custom_target(gmx-version ALL
137             COMMAND ${CMAKE_COMMAND}
138                 -D GIT_EXECUTABLE="${GIT_EXECUTABLE}"
139                 -D PROJECT_VERSION="${PROJECT_VERSION}"
140                 -D PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
141                 -D VERSION_CMAKEIN=${GENERATED_VERSION_FILE_SOURCE}
142                 -D VERSION_OUT=${GENERATED_VERSION_FILE}
143                 -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
144             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
145             DEPENDS ${GENERATED_VERSION_FILE_SOURCE}
146             COMMENT "Generating git version information")
147     set_source_files_properties(${GENERATED_VERSION_FILE}
148                                 PROPERTIES GENERATED true)
149 else()
150     set(GMX_PROJECT_VERSION_STR ${PROJECT_VERSION})
151     configure_file(${GENERATED_VERSION_FILE_SOURCE} ${GENERATED_VERSION_FILE})
152 endif()
153 list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
154
155 # apply gcc 4.4.x bug workaround
156 if(GMX_USE_GCC44_BUG_WORKAROUND)
157    include(gmxGCC44O3BugWorkaround)
158    gmx_apply_gcc44_bug_workaround("gmxlib/bondfree.c")
159    gmx_apply_gcc44_bug_workaround("mdlib/force.c")
160    gmx_apply_gcc44_bug_workaround("mdlib/constr.c")
161 endif()
162
163 add_library(libgromacs ${LIBGROMACS_SOURCES})
164 if (GMX_GIT_VERSION_INFO)
165     add_dependencies(libgromacs gmx-version)
166 endif()
167
168 # Recent versions of gcc and clang give warnings on scanner.cpp, which
169 # is a generated source file. These are awkward to suppress inline, so
170 # we do it in the compilation command (after testing that the compiler
171 # supports the suppressions). Setting the properties only works after
172 # the related target has been created, e.g. after when the file is
173 # used with add_library().
174 include(CheckCXXCompilerFlag)
175 check_cxx_compiler_flag(-Wno-unused-parameter HAS_NO_UNUSED_PARAMETER)
176 if (HAS_NO_UNUSED_PARAMETER)
177     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-unused-parameter")
178 endif()
179 check_cxx_compiler_flag(-Wno-deprecated-register HAS_NO_DEPRECATED_REGISTER)
180 if (HAS_NO_DEPRECATED_REGISTER)
181     set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated-register")
182 else()
183     check_cxx_compiler_flag(-Wno-deprecated HAS_NO_DEPRECATED)
184     if (HAS_NO_DEPRECATED)
185         set(_scanner_cpp_compiler_flags "${_scanner_cpp_compiler_flags} -Wno-deprecated")
186     endif()
187 endif()
188 set_source_files_properties(selection/scanner.cpp PROPERTIES COMPILE_FLAGS "${_scanner_cpp_compiler_flags}")
189
190 target_link_libraries(libgromacs
191                       ${EXTRAE_LIBRARIES}
192                       ${GMX_GPU_LIBRARIES}
193                       ${GMX_EXTRA_LIBRARIES}
194                       ${TNG_IO_LIBRARIES}
195                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
196                       ${XML_LIBRARIES}
197                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS})
198 set_target_properties(libgromacs PROPERTIES
199                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
200                       SOVERSION ${LIBRARY_SOVERSION}
201                       VERSION ${LIBRARY_VERSION}
202                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
203
204 # Only install the library in mdrun-only mode if it is actually necessary
205 # for the binary
206 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
207     install(TARGETS libgromacs DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
208 endif()
209
210 if (NOT GMX_BUILD_MDRUN_ONLY)
211     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgromacs.pc.cmakein
212                    ${CMAKE_CURRENT_BINARY_DIR}/libgromacs.pc @ONLY)
213     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgromacs.pc
214             DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
215             RENAME "libgromacs${GMX_LIBS_SUFFIX}.pc"
216             COMPONENT development)
217 endif()
218
219 if (INSTALL_CUDART_LIB) #can be set manual by user
220     if (GMX_GPU)
221         foreach(CUDA_LIB ${CUDA_LIBRARIES})
222             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
223             if(IS_CUDART) #libcuda should not be installed
224                 #install also name-links (linker uses those)
225                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
226                 install(FILES ${CUDA_LIBS} DESTINATION
227                     ${LIB_INSTALL_DIR} COMPONENT libraries)
228             endif()
229         endforeach()
230     else()
231         message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
232     endif()
233 endif()