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