Logo AND Algorithmique Numérique Distribuée

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