Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3edfb3614c1b861eda6d294899d9bb6773e319a4
[simgrid.git] / tools / cmake / Distrib.cmake
1 #########################################
2 ### Fill in the "make install" target ###
3 #########################################
4
5 # doc
6 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/doc/html/)
7 install(DIRECTORY "${CMAKE_BINARY_DIR}/doc/html/"
8   DESTINATION doc/simgrid/html/)
9
10 # binaries
11 if(enable_smpi)
12   install(PROGRAMS
13     ${CMAKE_BINARY_DIR}/bin/smpicc
14     ${CMAKE_BINARY_DIR}/bin/smpicxx
15     ${CMAKE_BINARY_DIR}/bin/smpirun
16     ${CMAKE_BINARY_DIR}/bin/smpimain
17     DESTINATION bin/)
18   if(SMPI_FORTRAN)
19     install(PROGRAMS
20       ${CMAKE_BINARY_DIR}/bin/smpif90
21       ${CMAKE_BINARY_DIR}/bin/smpiff
22       DESTINATION bin/)
23     install(PROGRAMS
24       ${CMAKE_BINARY_DIR}/include/smpi/mpi.mod
25       DESTINATION include/smpi/)
26   endif()
27 endif()
28
29 if(enable_model-checking)
30   install(
31     PROGRAMS ${CMAKE_BINARY_DIR}/bin/simgrid-mc
32     DESTINATION bin/)
33 endif()
34
35 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/tesh  DESTINATION bin/)
36
37 install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/graphicator  DESTINATION bin/)
38
39 install(PROGRAMS ${CMAKE_HOME_DIRECTORY}/tools/MSG_visualization/colorize.pl
40   DESTINATION bin/
41   RENAME simgrid-colorizer)
42
43 add_custom_target(simgrid-colorizer ALL
44   COMMENT "Install ${CMAKE_BINARY_DIR}/bin/colorize"
45   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/tools/MSG_visualization/colorize.pl ${CMAKE_BINARY_DIR}/bin/colorize)
46
47 install(PROGRAMS ${CMAKE_HOME_DIRECTORY}/tools/simgrid_update_xml.pl
48   DESTINATION bin/
49   RENAME simgrid_update_xml)
50
51 add_custom_target(simgrid_update_xml ALL
52   COMMENT "Install ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml"
53   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/tools/simgrid_update_xml.pl ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml)
54
55 # libraries
56 install(TARGETS simgrid DESTINATION lib/)
57
58 if(enable_java)
59   set(SIMGRID_JAR_TO_INSTALL "${SIMGRID_JAR}")
60   install(TARGETS simgrid-java   DESTINATION lib/)
61   install(FILES ${SIMGRID_JAR_TO_INSTALL}
62       DESTINATION java/
63       RENAME simgrid.jar)
64 endif()
65
66 # include files
67 foreach(file ${headers_to_install}  ${generated_headers_to_install})
68   get_filename_component(location ${file} PATH)
69   string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" location "${location}")
70   install(FILES ${file} DESTINATION ${location})
71 endforeach()
72
73 # example files
74 foreach(file ${examples_to_install})
75   string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/examples/" "" file ${file})
76   get_filename_component(location ${file} PATH)
77   install(FILES "examples/${file}"
78     DESTINATION doc/simgrid/examples/${location})
79 endforeach(file ${examples_to_install})
80
81 ###########################################
82 ### Fill in the "make uninstall" target ###
83 ###########################################
84
85 add_custom_target(uninstall
86   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/doc/simgrid
87   COMMAND ${CMAKE_COMMAND} -E   echo "uninstall doc ok"
88   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/lib/libsimgrid*
89   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/lib/lua/5.1/simgrid*
90   COMMAND ${CMAKE_COMMAND} -E   echo "uninstall lib ok"
91   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/smpicc
92   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/smpicxx
93   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/smpiff
94   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/smpif90
95   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/smpirun
96   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/tesh
97   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/simgrid-colorizer
98   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/simgrid_update_xml
99   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/bin/graphicator
100   COMMAND ${CMAKE_COMMAND} -E   echo "uninstall bin ok"
101   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/instr
102   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/msg
103   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/simdag
104   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/smpi
105   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/simix
106   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/surf
107   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/xbt
108   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/mc
109   COMMAND ${CMAKE_COMMAND} -E   remove_directory ${CMAKE_INSTALL_PREFIX}/include/simgrid
110   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/include/simgrid.h
111   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/include/simgrid_config.h
112   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/include/xbt.h
113   COMMAND ${CMAKE_COMMAND} -E   echo "uninstall include ok"
114   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/simgrid_update_xml.1
115   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/tesh.1
116   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/smpicc.1
117   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/smpicxx.1
118   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/smpirun.1
119   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/smpiff.1
120   COMMAND ${CMAKE_COMMAND} -E   remove -f ${CMAKE_INSTALL_PREFIX}/share/man/man1/smpif90.1
121
122
123   COMMAND ${CMAKE_COMMAND} -E   echo "uninstall man ok"
124   WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
125
126 if(SIMGRID_HAVE_LUA)
127   add_custom_command(TARGET uninstall
128     COMMAND ${CMAKE_COMMAND} -E echo "uninstall binding lua ok"
129     COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_INSTALL_PREFIX}/lib/lua/5.1/simgrid.${LIB_EXE}
130     WORKING_DIRECTORY "${CMAKE_HOME_DIRECTORY}/")
131 endif()
132
133 ################################################################
134 ## Build a sain "make dist" target to build a source package ###
135 ##   containing only the files that I explicitely state      ###
136 ##   (instead of any cruft laying on my disk as CPack does)  ###
137 ################################################################
138
139 # This is the complete list of what will be added to the source archive
140 set(source_to_pack
141   ${headers_to_install}
142   ${source_of_generated_headers}
143   ${BINDINGS_SRC}
144   ${JEDULE_SRC}
145   ${JMSG_C_SRC}
146   ${JMSG_JAVA_SRC}
147   ${LUA_SRC}
148   ${MC_SRC_BASE}
149   ${MC_SRC}
150   ${MC_SIMGRID_MC_SRC}
151   ${MSG_SRC}
152   ${S4U_SRC}
153   ${NS3_SRC}
154   ${PLUGINS_SRC}
155   ${RNGSTREAM_SRC}
156   ${SIMDAG_SRC}
157   ${SIMGRID_SRC}
158   ${SIMIX_SRC}
159   ${SMPI_SRC}
160   ${SURF_SRC}
161   ${TRACING_SRC}
162   ${XBT_RL_SRC}
163   ${XBT_SRC}
164   ${EXTRA_DIST}
165   ${CMAKE_SOURCE_FILES}
166   ${CMAKEFILES_TXT}
167   ${DOC_FIGS}
168   ${DOC_IMG}
169   ${DOC_SOURCES}
170   ${DOC_TOOLS}
171   ${PLATFORMS_EXAMPLES}
172   ${README_files}
173   ${bin_files}
174   ${examples_src}
175   ${tesh_files}
176   ${teshsuite_src}
177   ${testsuite_src}
178   ${tools_src}
179   ${txt_files}
180   ${xml_files}
181   )
182
183 ##########################################
184 ### Fill in the "make dist-dir" target ###
185 ##########################################
186
187 add_custom_target(dist-dir
188   COMMENT "Generating the distribution directory"
189   COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_NAME}-${release_version}/
190   COMMAND ${CMAKE_COMMAND} -E remove ${PROJECT_NAME}-${release_version}.tar.gz
191   COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_NAME}-${release_version}
192   COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_NAME}-${release_version}/doc/html/
193   COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/doc/html/ ${PROJECT_NAME}-${release_version}/doc/html/
194   COMMAND rm -f `grep -rl " Reference" ${PROJECT_NAME}-${release_version}/doc/html/` # Doxygen, go away
195   COMMAND rm -f `grep -rl "Member List" ${PROJECT_NAME}-${release_version}/doc/html/` # Doxygen, you're getting annoying
196   )
197 add_dependencies(dist-dir maintainer_files)
198
199 set(dirs_in_tarball "")
200 foreach(file ${source_to_pack})
201   #message(${file})
202   # This damn prefix is still set somewhere (seems to be in subdirs)
203   string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
204
205   # Create the directory on need
206   get_filename_component(file_location ${file} PATH)
207   string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_tarball}")
208   if(NOT OPERATION)
209     set(dirs_in_tarball "${dirs_in_tarball};${file_location};")
210     add_custom_command(
211       TARGET dist-dir
212       COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_NAME}-${release_version}/${file_location}/)
213   endif()
214
215   # Actually copy the file
216   add_custom_command(
217     TARGET dist-dir
218     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/${file} ${PROJECT_NAME}-${release_version}/${file_location})
219 endforeach(file ${source_to_pack})
220
221 add_custom_command(
222   TARGET dist-dir
223   COMMAND ${CMAKE_COMMAND} -E echo "${GIT_VERSION}" > ${PROJECT_NAME}-${release_version}/.gitversion)
224
225 ##########################################################
226 ### Link all sources to the bindir if srcdir != bindir ###
227 ##########################################################
228 add_custom_target(hardlinks
229    COMMENT "Making the source files available from the bindir"
230 )
231 if (NOT ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
232   foreach(file ${source_to_pack})
233     #message(${file})
234     # This damn prefix is still set somewhere (seems to be in subdirs)
235     string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
236
237     # Create the directory on need
238     get_filename_component(file_location ${file} PATH)
239     string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_bindir}")
240     if(NOT OPERATION)
241       set(dirs_in_tarball "${dirs_in_bindir};${file_location};")
242       add_custom_command(
243         TARGET hardlinks
244         COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${file_location}/)
245     endif()
246
247     # Actually copy the file
248     add_custom_command(
249       TARGET hardlinks
250       COMMAND if test -f ${CMAKE_HOME_DIRECTORY}/${file} \; then rm -f ${CMAKE_BINARY_DIR}/${file}\; ln ${CMAKE_HOME_DIRECTORY}/${file} ${CMAKE_BINARY_DIR}/${file_location}\; fi
251     )
252   endforeach(file ${source_to_pack})
253 endif()
254
255
256 ######################################
257 ### Fill in the "make dist" target ###
258 ######################################
259
260 add_custom_target(dist
261   COMMENT "Removing the distribution directory"
262   DEPENDS ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${release_version}.tar.gz
263   COMMAND ${CMAKE_COMMAND} -E echo ${PROJECT_NAME}-${release_version} > ${CMAKE_BINARY_DIR}/VERSION
264   COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_NAME}-${release_version}/)
265
266 add_custom_command(
267   OUTPUT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${release_version}.tar.gz
268   COMMENT "Compressing the archive from the distribution directory"
269   COMMAND ${CMAKE_COMMAND} -E tar cf ${PROJECT_NAME}-${release_version}.tar ${PROJECT_NAME}-${release_version}/
270   COMMAND gzip -9v ${PROJECT_NAME}-${release_version}.tar
271   COMMAND ${CMAKE_COMMAND} -E remove_directory ${PROJECT_NAME}-${release_version}/)
272 add_dependencies(dist dist-dir)
273
274 if(NOT enable_maintainer_mode)
275   add_custom_target(echo-dist
276     COMMAND ${CMAKE_COMMAND} -E echo "WARNING: ----------------------------------------------------"
277     COMMAND ${CMAKE_COMMAND} -E echo "WARNING: Distrib is generated without option maintainer mode "
278     COMMAND ${CMAKE_COMMAND} -E echo "WARNING: ----------------------------------------------------")
279   add_dependencies(dist echo-dist)
280 endif()
281
282 ###########################################
283 ### Fill in the "make distcheck" target ###
284 ###########################################
285
286 set(CMAKE_BINARY_TEST_DIR ${CMAKE_BINARY_DIR})
287
288 # Allow to test the "make dist"
289 add_custom_target(distcheck
290   COMMAND ${CMAKE_COMMAND} -E echo "XXX compare archive with git repository"
291   COMMAND ${CMAKE_HOME_DIRECTORY}/tools/internal/check_dist_archive -batch ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}.tar.gz
292
293   COMMAND ${CMAKE_COMMAND} -E echo "XXX remove old copy"
294   COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}
295
296   COMMAND ${CMAKE_COMMAND} -E echo "XXX Untar distrib"
297   COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}.tar.gz ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}
298
299   COMMAND ${CMAKE_COMMAND} -E echo "XXX create build and install subtrees"
300   COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build
301   COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_inst
302
303   COMMAND ${CMAKE_COMMAND} -E echo "XXX Configure"
304   COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build
305           ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_inst -Denable_lto=OFF ..
306         
307   COMMAND ${CMAKE_COMMAND} -E echo "XXX Build"
308   COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build ${CMAKE_MAKE_PROGRAM} -j 4
309
310   COMMAND ${CMAKE_COMMAND} -E echo "XXX Test"
311   COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build ctest --output-on-failure -j 4
312
313   COMMAND ${CMAKE_COMMAND} -E echo "XXX Install"
314   COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build ${CMAKE_MAKE_PROGRAM} install
315   COMMAND ${CMAKE_COMMAND} -E create_symlink
316   ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_inst/lib/libsimgrid.so
317   ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_inst/lib/libsimgridtest.so
318
319   COMMAND ${CMAKE_COMMAND} -E echo "XXX Install with documentation"
320   COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}/_build ${CMAKE_MAKE_PROGRAM} install
321
322   COMMAND ${CMAKE_COMMAND} -E echo "XXX Remove temp directories"
323   COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_BINARY_TEST_DIR}/${PROJECT_NAME}-${release_version}
324   )
325 add_dependencies(distcheck dist)
326
327 #######################################
328 ### Fill in the "make check" target ###
329 #######################################
330
331 if(enable_memcheck)
332   add_custom_target(check COMMAND ctest -D ExperimentalMemCheck)
333 else()
334   add_custom_target(check COMMAND make test)
335 endif()
336
337 #######################################
338 ### Fill in the "make xxx-clean" target ###
339 #######################################
340
341 add_custom_target(maintainer-clean
342   COMMAND ${CMAKE_COMMAND} -E remove -f src/config_unit.c
343   COMMAND ${CMAKE_COMMAND} -E remove -f src/cunit_unit.c
344   COMMAND ${CMAKE_COMMAND} -E remove -f src/dict_unit.c
345   COMMAND ${CMAKE_COMMAND} -E remove -f src/dynar_unit.c
346   COMMAND ${CMAKE_COMMAND} -E remove -f src/ex_unit.c
347   COMMAND ${CMAKE_COMMAND} -E remove -f src/set_unit.c
348   COMMAND ${CMAKE_COMMAND} -E remove -f src/simgrid_units_main.c
349   COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_str_unit.c
350   COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_synchro_unit.c
351   COMMAND ${CMAKE_COMMAND} -E remove -f src/mpif.f90
352   WORKING_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
353
354 include(CPack)