make install-mdrun now installes shared libs (fix for bugzilla 549) + mnir fixes
[gromacs/rigid-bodies.git] / src / kernel / CMakeLists.txt
blobf530b9987f1f3f5a57804e35ff7e6945cb142c58
2 set(GMXPREPROCESS_SOURCES 
3     add_par.c       
4     compute_io.c    
5     convparm.c      
6     gen_ad.c        
7     gen_vsite.c     
8     genhydro.c   
9     gpp_atomtype.c  
10     gpp_bond_atomtype.c     
11     h_db.c          
12     hackblock.c             
13     hizzie.c        
14     nm2type.c
15     pdb2top.c       
16     pgutil.c        
17     readir.c        
18     readpull.c      
19     resall.c        
20     sorting.c       
21     specbond.c      
22     ter_db.c        
23     tomorse.c       
24     topdirs.c       
25     topexcl.c       
26     topio.c         
27     toppush.c       
28     topshake.c      
29     toputil.c       
30     tpbcmp.c        
31     vsite_parm.c    
32     fflibutil.c
33     xlate.c)
35 set(MDRUN_SOURCES 
36     gctio.c    ionize.c runner.c
37     do_gct.c     repl_ex.c  xutils.c
38     md.c         mdrun.c    genalg.c md_openmm.c)
40 add_library(gmxpreprocess ${GMXPREPROCESS_SOURCES})
41 target_link_libraries(gmxpreprocess md)
42 set_target_properties(gmxpreprocess PROPERTIES OUTPUT_NAME "gmxpreprocess${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
43 set_target_properties(md PROPERTIES OUTPUT_NAME "md${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
46 if(GMX_OPENMM) 
47     add_subdirectory(gmx_gpu_utils)
48     include_directories(./gmx_gpu_utils ${OpenMM_INCLUDE_DIR})
49     link_directories(${OpenMM_LIBRARY_DIR}) 
50     # only define if this is a local build not a release 
51     # we assume that the auto-generated version is not used && 
52     # version string does not contain "-dev" => it's a release build
53     if(NOT USE_VERSION_H AND NOT PROJECT_VERSION MATCHES ".*-dev.*")  
54         add_definitions( -DOPENMM_PLUGIN_DIR="${OpenMM_PLUGIN_DIR}" ) 
55     else()
56         add_definitions( -DOPENMM_PLUGIN_DIR="" )
57     endif()
58     add_library(openmm_api_wrapper STATIC openmm_wrapper.cpp)
59     target_link_libraries(openmm_api_wrapper gmx_gpu_utils ${OpenMM_LIBRARIES})
60     set(GMX_OPENMM_LIBRARIES openmm_api_wrapper gmx_gpu_utils ${OpenMM_LIBRARIES})   
61 endif(GMX_OPENMM)
63 if(GMX_FAHCORE)
64   add_library(fahcore ${MDRUN_SOURCES})
65 else(GMX_FAHCORE)
67 list(APPEND GMX_EXTRA_LIBRARIES gmxpreprocess md)
69 add_executable(grompp grompp.c)
70 target_link_libraries(grompp ${GMX_EXTRA_LIBRARIES})
71 set_target_properties(grompp PROPERTIES OUTPUT_NAME "grompp${GMX_BINARY_SUFFIX}")
73 add_executable(tpbconv tpbconv.c)
74 target_link_libraries(tpbconv ${GMX_EXTRA_LIBRARIES})
75 set_target_properties(tpbconv PROPERTIES OUTPUT_NAME "tpbconv${GMX_BINARY_SUFFIX}")
77 add_executable(pdb2gmx pdb2gmx.c)
78 target_link_libraries(pdb2gmx ${GMX_EXTRA_LIBRARIES})
79 set_target_properties(pdb2gmx PROPERTIES OUTPUT_NAME "pdb2gmx${GMX_BINARY_SUFFIX}")
81 add_executable(g_protonate g_protonate.c)
82 target_link_libraries(g_protonate ${GMX_EXTRA_LIBRARIES})
83 set_target_properties(g_protonate PROPERTIES OUTPUT_NAME "g_protonate${GMX_BINARY_SUFFIX}")
85 add_executable(g_luck g_luck.c)
86 target_link_libraries(g_luck ${GMX_EXTRA_LIBRARIES})
87 set_target_properties(g_luck PROPERTIES OUTPUT_NAME "g_luck${GMX_BINARY_SUFFIX}")
89 add_executable(gmxdump gmxdump.c)
90 target_link_libraries(gmxdump ${GMX_EXTRA_LIBRARIES})
91 set_target_properties(gmxdump PROPERTIES OUTPUT_NAME "gmxdump${GMX_BINARY_SUFFIX}")
93 add_executable(g_x2top g_x2top.c)
94 target_link_libraries(g_x2top ${GMX_EXTRA_LIBRARIES})
95 set_target_properties(g_x2top PROPERTIES OUTPUT_NAME "g_x2top${GMX_BINARY_SUFFIX}")
97 add_executable(gmxcheck gmxcheck.c)
98 target_link_libraries(gmxcheck ${GMX_EXTRA_LIBRARIES})
99 set_target_properties(gmxcheck PROPERTIES OUTPUT_NAME "gmxcheck${GMX_BINARY_SUFFIX}")
101 add_executable(mdrun ${MDRUN_SOURCES})
102 target_link_libraries(mdrun ${GMX_EXTRA_LIBRARIES} ${GMX_OPENMM_LIBRARIES})
103 # set binary name to mdrun-gpu
104 if(GMX_OPENMM)
105     set(_mdrun_exec_name "mdrun-gpu")    
106 else()
107     set(_mdrun_exec_name "mdrun${GMX_BINARY_SUFFIX}")
108 endif()
109 set_target_properties(mdrun PROPERTIES OUTPUT_NAME "${_mdrun_exec_name}")
111 # this is to circumvent the following MSVC error: 
112 # warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs
113 # fatal error LNK1169: one or more multiply defined symbols found
114 if(GMX_OPENMM AND MSVC)
115     set_target_properties(mdrun PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT")
116 endif()
119 install(TARGETS 
120         grompp
121         tpbconv
122         pdb2gmx
123         g_protonate
124         g_luck
125         gmxdump
126         g_x2top
127         gmxcheck
128         mdrun
129         gmxpreprocess DESTINATION ${LIB_INSTALL_DIR}
130         RUNTIME DESTINATION ${BIN_INSTALL_DIR})
133 # if we build shared gromacs libs, when installing throught the install-mdrun target 
134 # these libs need to be installed as well
135 if(BUILD_SHARED_LIBS)
136     # in MDRUN_LIBS we store the libraries MDRUN links against (NOTE: hardcoded!!!)
137     set(MDRUN_LIBS gmxpreprocess md gmx)
138     
139     # generate install-libXXX custom target for each shared lib that mdrun links against
140     foreach(_lib ${MDRUN_LIBS})
141         # double-check that the type is SHARED
142         get_target_property(_type ${_lib} TYPE)
143         if(NOT ${_type} STREQUAL "SHARED_LIBRARY")
144             message(FATAL_ERROR " Internal error: library ${_lib} is not shared so it's not supposed to be processed for installing")
145         endif()
147         # figure out the path and filename under which the lib will be installed
148         # (libname with pre- and suffix)
149         get_target_property(_lib_path ${_lib} LOCATION)
150         string(REGEX REPLACE "/" ";" _lib_fname ${_lib_path})
151         list(REVERSE _lib_fname)
152         list(GET _lib_fname 0 _lib_fname)
154         # prepare path and filename for the pkgconfig stuff
155         string(REGEX REPLACE ".so$" ".pc" _lib_pc_path ${_lib_path})
156         string(REGEX REPLACE ".so$" ".pc" _lib_pc_fname ${_lib_fname})
157         # create custom target for copying each library to the install location 
158         # TODO: need to fix this to have the .so.6 form
159         add_custom_target(install-${_lib}
160             COMMAND ${CMAKE_COMMAND} -E copy 
161                 "${_lib_path}" "${LIB_INSTALL_DIR}/${_lib_fname}.${SOVERSION}"
162             COMMAND ${CMAKE_COMMAND} -E create_symlink 
163                 "${_lib_fname}.${SOVERSION}" "${LIB_INSTALL_DIR}/${_lib_fname}"
164             COMMAND ${CMAKE_COMMAND} -E copy
165                 "${_lib_pc_path}" "${LIB_INSTALL_DIR}/pkgconfig/${_lib_pc_fname}"
166             # DEPENDS ${_lib_pcpath}
167             COMMENT "Installing library ${_lib}")
168         add_dependencies(install-${_lib} ${_lib})
170         # gather the custom target names in a string
171         # set(_lib_install_targets "${_lib_install_targets} install-lib${_lib}")
172         list(APPEND _lib_install_targets "install-${_lib}")
173     endforeach(_lib)
174 endif(BUILD_SHARED_LIBS)
176 get_target_property(_mdrun_path mdrun LOCATION)
177 add_custom_target(install-mdrun
178     COMMAND ${CMAKE_COMMAND} -E copy "${_mdrun_path}" 
179         "${BIN_INSTALL_DIR}/${_mdrun_exec_name}"
180     COMMENT "Installing mdrun")
181 add_dependencies(install-mdrun mdrun ${_lib_install_targets})
183 endif(GMX_FAHCORE)
185 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgmxpreprocess.pc.cmakein ${CMAKE_CURRENT_BINARY_DIR}/libgmxpreprocess.pc @ONLY)
186 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgmxpreprocess.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig 
187   RENAME "libgmxpreprocess${GMX_LIBS_SUFFIX}.pc")