Fixed CMake 2.8.12+ CUDA dylib bugs and warnings on OS X
[alexxy/gromacs.git] / src / kernel / CMakeLists.txt
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 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
36 set(GMXPREPROCESS_SOURCES 
37     add_par.c       
38     calc_verletbuf.c
39     compute_io.c    
40     convparm.c      
41     gen_ad.c        
42     gen_vsite.c     
43     genhydro.c   
44     gpp_atomtype.c  
45     gpp_bond_atomtype.c     
46     h_db.c          
47     hackblock.c             
48     hizzie.c        
49     nm2type.c
50     pdb2top.c       
51     pgutil.c        
52     readir.c        
53     readpull.c      
54     readadress.c      
55     readrot.c
56     resall.c        
57     sorting.c       
58     specbond.c      
59     ter_db.c        
60     tomorse.c       
61     topdirs.c       
62     topexcl.c       
63     topio.c         
64     toppush.c       
65     topshake.c      
66     toputil.c       
67     tpbcmp.c        
68     vsite_parm.c    
69     fflibutil.c
70     xlate.c)
71
72 set(MDRUN_SOURCES 
73     gctio.c    ionize.c runner.c
74     do_gct.c     repl_ex.c  xutils.c pme_loadbal.c
75     md.c         mdrun.c    genalg.c membed.c)
76
77 add_library(gmxpreprocess ${GMXPREPROCESS_SOURCES})
78 target_link_libraries(gmxpreprocess md)
79 set_target_properties(gmxpreprocess PROPERTIES OUTPUT_NAME "gmxpreprocess${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION}
80     COMPILE_FLAGS "${OpenMP_C_FLAGS}")
81
82
83 if(GMX_GPU)
84     include_directories(${CMAKE_SOURCE_DIR}/src/gmxlib/gpu_utils)
85 endif()
86
87 if(GMX_OPENMM)
88     # Even though the OpenMM build has "moved to contrib", many things
89     # have be be done from within the scope of the CMakeLists.txt that
90     # builds its mdrun, and that is here
91     list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/src/contrib)
92     find_package(OpenMM)
93     include_directories(${CMAKE_CURRENT_SOURCE_DIR})
94     include(${CMAKE_SOURCE_DIR}/src/contrib/BuildMdrunOpenMM.cmake)
95 endif(GMX_OPENMM)
96
97 if(GMX_GPU OR GMX_FORCE_CXX)
98     set_source_files_properties(main.c PROPERTIES LANGUAGE CXX)
99     if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
100         set_source_files_properties(main.c PROPERTIES COMPILE_FLAGS "-x c++")
101     endif()
102 endif()
103
104 if(GMX_FAHCORE)
105   add_library(fahcore ${MDRUN_SOURCES})
106 else(GMX_FAHCORE)
107
108 set(GMX_KERNEL_PROGRAMS
109     grompp tpbconv pdb2gmx g_protonate gmxdump g_x2top gmxcheck)
110 if (NOT GMX_NO_QUOTES)
111   set(GMX_KERNEL_PROGRAMS ${GMX_KERNEL_PROGRAMS} g_luck)
112 endif (NOT GMX_NO_QUOTES)
113
114
115 foreach(PROGRAM ${GMX_KERNEL_PROGRAMS})
116     add_executable(${PROGRAM} ${PROGRAM}.c main.c)
117     if (NOT ${PROGRAM} STREQUAL "g_luck")
118         gmx_add_man_page(${PROGRAM})
119     endif()
120     target_link_libraries(${PROGRAM} gmxpreprocess md gmx ${OpenMP_LINKER_FLAGS})
121     set_target_properties(${PROGRAM} PROPERTIES OUTPUT_NAME "${PROGRAM}${GMX_BINARY_SUFFIX}")
122 endforeach()
123
124 add_executable(mdrun ${MDRUN_SOURCES} main.c)
125 gmx_add_man_page(mdrun)
126 target_link_libraries(mdrun gmxpreprocess md gmx ${OpenMP_LINKER_FLAGS})
127 set_target_properties(mdrun PROPERTIES OUTPUT_NAME "mdrun${GMX_BINARY_SUFFIX}" COMPILE_FLAGS "${OpenMP_C_FLAGS}")
128
129 if(GMX_OPENMM)
130     target_link_libraries(mdrun openmm_api_wrapper)
131 endif()
132
133 # Construct component groups for installation; note that a component may
134 # belong to only one group
135 foreach(PROGRAM ${GMX_KERNEL_PROGRAMS})
136     set(CPACK_COMPONENT_${PROGRAM}_GROUP tools)
137 endforeach()
138 set(CPACK_COMPONENT_MDRUN_GROUP mdrun)
139
140 foreach(PROGRAM ${GMX_KERNEL_PROGRAMS} mdrun)
141     # Manage CPack component dependencies
142     set(CPACK_COMPONENT_${PROGRAM}_DEPENDS libraries libraries-gmxpreprocess)
143
144     # Create custom install-xxxx target
145     if (BUILD_SHARED_LIBS)
146     # If shared libraries are used, we need to install the libraries in
147     # addition to the mdrun binary.
148        add_custom_target(install-${PROGRAM}
149            COMMAND ${CMAKE_COMMAND} -DCOMPONENT=libraries
150                    -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
151            COMMAND ${CMAKE_COMMAND} -DCOMPONENT=libraries-gmxpreprocess
152                    -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
153            COMMAND ${CMAKE_COMMAND} -DCOMPONENT=${PROGRAM}
154                    -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
155            COMMENT "Installing ${PROGRAM}")
156     else()
157        add_custom_target(install-${PROGRAM}
158            COMMAND ${CMAKE_COMMAND} -DCOMPONENT=${PROGRAM}
159                    -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
160            COMMENT "Installing ${PROGRAM}")
161     endif()
162     add_dependencies(install-${PROGRAM} ${PROGRAM})
163
164     # Finally, trigger installation
165     install(
166       TARGETS ${PROGRAM}
167       COMPONENT ${PROGRAM}
168       DESTINATION ${BIN_INSTALL_DIR}
169       )
170 endforeach()
171
172 install(TARGETS gmxpreprocess DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries-gmxpreprocess)
173
174 if (INSTALL_CUDART_LIB) #can be set manual by user
175     if (GMX_GPU)
176         foreach(CUDA_LIB ${CUDA_LIBRARIES})
177             string(REGEX MATCH "cudart" IS_CUDART ${CUDA_LIB})
178             if(IS_CUDART) #libcuda should not be installed
179                 #install also name-links (linker uses those)
180                 file(GLOB CUDA_LIBS ${CUDA_LIB}*)
181                 install(FILES ${CUDA_LIBS} DESTINATION
182                     ${LIB_INSTALL_DIR} COMPONENT libraries)
183             endif()
184         endforeach()
185     else()
186         message(WARNING "INSTALL_CUDART_LIB only makes sense with GMX_GPU")
187     endif()
188 endif ()
189 endif(GMX_FAHCORE)
190
191 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgmxpreprocess.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libgmxpreprocess.pc @ONLY)
192 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgmxpreprocess.pc
193         DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
194         RENAME "libgmxpreprocess${GMX_LIBS_SUFFIX}.pc"
195         COMPONENT development)