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