Logo AND Algorithmique Numérique Distribuée

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