Logo AND Algorithmique Numérique Distribuée

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