Merge branch release-4-6
[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, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # 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 add_subdirectory(gmxlib)
49 add_subdirectory(mdlib)
50 add_subdirectory(gmxpreprocess)
51 add_subdirectory(commandline)
52 add_subdirectory(fft)
53 add_subdirectory(linearalgebra)
54 add_subdirectory(onlinehelp)
55 add_subdirectory(options)
56 add_subdirectory(utility)
57 if (NOT GMX_BUILD_MDRUN_ONLY)
58     add_subdirectory(legacyheaders)
59     add_subdirectory(gmxana)
60     add_subdirectory(analysisdata)
61     add_subdirectory(selection)
62     add_subdirectory(trajectoryanalysis)
63 endif ()
64
65 list(APPEND LIBGROMACS_SOURCES ${GMXLIB_SOURCES} ${MDLIB_SOURCES})
66
67 file(GLOB LIBGROMACS_HEADERS *.h)
68 configure_file(version.h.cmakein version.h)
69 gmx_install_headers("" ${LIBGROMACS_HEADERS})
70 gmx_install_headers("" ${CMAKE_CURRENT_BINARY_DIR}/version.h)
71
72 # Add target that generates gitversion.c every time make is run
73 # if git version info is requested
74 # This code is here instead of utility/CMakeLists.txt because CMake
75 # ignores set_source_file_properties from subdirectories.
76 if (GMX_GIT_VERSION_INFO)
77     set(GENERATED_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/utility/gitversion.c)
78     add_custom_target(gmx_version ALL
79             COMMAND ${CMAKE_COMMAND}
80                 -D GIT_EXECUTABLE="${GIT_EXECUTABLE}"
81                 -D GIT_VERSION="${GIT_VERSION}"
82                 -D PROJECT_VERSION="${PROJECT_VERSION}"
83                 -D PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
84                 -D VERSION_C_CMAKEIN="${CMAKE_CURRENT_SOURCE_DIR}/utility/gitversion.c.cmakein"
85                 -D VERSION_C_OUT=${GENERATED_VERSION_FILE}
86                 -P ${CMAKE_SOURCE_DIR}/cmake/gmxGenerateVersionInfo.cmake
87             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
88             DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/utility/gitversion.c.cmakein
89             COMMENT "Generating git version information")
90     set_source_files_properties(${GENERATED_VERSION_FILE}
91                                 PROPERTIES GENERATED true)
92     list(APPEND LIBGROMACS_SOURCES ${GENERATED_VERSION_FILE})
93 endif()
94
95 # apply gcc 4.4.x bug workaround
96 if(GMX_USE_GCC44_BUG_WORKAROUND)
97    include(gmxGCC44O3BugWorkaround)
98    gmx_apply_gcc44_bug_workaround("gmxlib/bondfree.c")
99    gmx_apply_gcc44_bug_workaround("mdlib/force.c")
100    gmx_apply_gcc44_bug_workaround("mdlib/constr.c")
101 endif()
102
103 add_library(libgromacs ${LIBGROMACS_SOURCES})
104 if (GMX_GIT_VERSION_INFO)
105     add_dependencies(libgromacs gmx_version)
106 endif ()
107
108 if(GMX_BUILD_OWN_FFTW)
109     # This dependency has to be made here rather than the CMakeLists.txt that
110     # does the FFTW build, because of the order in which
111     # add_subdirectory() calls are made in the top-level CMakeLists.txt; the
112     # md library target does not necessarily exist yet. Also enabling and
113     # disabling GMX_BUILD_OWN_FFTW changes dependencies correctly.
114     add_dependencies(libgromacs gmxfftw)
115 endif()
116
117 target_link_libraries(libgromacs ${GMX_GPU_LIBRARIES}
118                       ${GMX_EXTRA_LIBRARIES}
119                       ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES}
120                       ${XML_LIBRARIES} ${GSL_LIBRARIES}
121                       ${THREAD_LIB} ${GMX_SHARED_LINKER_FLAGS})
122 set_target_properties(libgromacs PROPERTIES
123                       OUTPUT_NAME "gromacs${GMX_LIBS_SUFFIX}"
124                       SOVERSION ${SOVERSION}
125                       COMPILE_FLAGS "${OpenMP_C_FLAGS}")
126
127 # Only install the library in mdrun-only mode if it is actually necessary
128 # for the binary
129 if (NOT GMX_BUILD_MDRUN_ONLY OR BUILD_SHARED_LIBS)
130     install(TARGETS libgromacs DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
131 endif()
132
133 if (NOT GMX_BUILD_MDRUN_ONLY)
134     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgromacs.pc.cmakein
135                    ${CMAKE_CURRENT_BINARY_DIR}/libgromacs.pc @ONLY)
136     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgromacs.pc
137             DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
138             RENAME "libgromacs${GMX_LIBS_SUFFIX}.pc"
139             COMPONENT development)
140 endif()
141
142 if (INSTALL_CUDART_LIB) #can be set manual by user
143     if (GMX_GPU)
144         foreach(CUDA_LIB ${CUDA_LIBRARIES})
145             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
146             if(IS_CUDART) #libcuda should not be installed
147                 #install also name-links (linker uses those)
148                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
149                 install(FILES ${CUDA_LIBS} DESTINATION
150                     ${LIB_INSTALL_DIR} COMPONENT libraries)
151             endif()
152         endforeach()
153     else()
154         message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
155     endif()
156 endif ()