Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add the Storage::read_async and Storage::write_async methods
[simgrid.git] / tools / cmake / MaintainerMode.cmake
1 # Change the following when we need a recent enough version of flexml to get the maintainer mode working
2 set(FLEXML_MIN_MAJOR 1)
3 set(FLEXML_MIN_MINOR 9)
4 set(FLEXML_MIN_PATCH 6)
5 # Change the following when we need a recent enough version of flex to get the maintainer mode working.
6 # Maintainer mode does NOT work with version 2.5.35!
7 set(FLEX_MIN_MAJOR 2)
8 set(FLEX_MIN_MINOR 5)
9 set(FLEX_MIN_PATCH 39)
10
11 # the rest should only be changed if you understand what you're doing
12 if(enable_maintainer_mode AND NOT WIN32)
13   if (PYTHON_EXECUTABLE)
14     add_custom_command(
15       OUTPUT
16       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.cpp
17       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.cpp
18       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h
19       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.hpp
20
21       DEPENDS
22       ${CMAKE_HOME_DIRECTORY}/src/simix/simcalls.py
23       ${CMAKE_HOME_DIRECTORY}/src/simix/simcalls.in
24
25       COMMENT "Generating simcalls source files"
26       COMMAND ${PYTHON_EXECUTABLE} simcalls.py
27       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/src/simix/
28       )
29
30     add_custom_target(simcalls_generated_src
31       DEPENDS
32       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.cpp
33       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.cpp
34       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h
35       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.hpp
36       )
37
38     SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
39       "${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h;${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.cpp;${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.cpp;${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.hpp"
40       )
41   endif()
42 endif()
43
44 # Let's generate header files required by SMPI when the call location tracing
45 # has been activated.
46 if(enable_maintainer_mode AND NOT WIN32)
47   add_custom_command(OUTPUT ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces.h
48                             ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces_fortran.h
49     DEPENDS
50     ${CMAKE_HOME_DIRECTORY}/tools/smpi/generate_smpi_defines.pl
51     ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi.h
52
53     COMMENT "Generating header files for call-location tracing with SMPI"
54     # Make sure there is no space after the redirection operator (>). I received
55     # error messages in that case on my Debian system.
56     COMMAND "${CMAKE_HOME_DIRECTORY}/tools/smpi/generate_smpi_defines.pl" "${CMAKE_HOME_DIRECTORY}/include/smpi/smpi.h >${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces.h"
57     COMMAND "${CMAKE_HOME_DIRECTORY}/tools/smpi/generate_smpi_defines.pl" "-f" "${CMAKE_HOME_DIRECTORY}/include/smpi/smpi.h >${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces_fortran.h"
58   )
59
60   add_custom_target(smpi_generated_headers_call_location_tracing
61     DEPENDS
62     ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces.h
63     ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces_fortran.h
64   )
65
66   SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
67     "${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces.h;${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_extended_traces_fortran.h"
68   )
69 endif()
70
71 if(enable_maintainer_mode AND NOT WIN32)
72   find_program(FLEX_EXE NAMES flex)
73   find_program(FLEXML_EXE NAMES flexml)
74   find_program(SED_EXE NAMES sed)
75   find_program(BISON_EXE NAMES bison)
76   find_program(LEX_EXE NAMES lex)
77
78   mark_as_advanced(BISON_EXE)
79   mark_as_advanced(LEX_EXE)
80
81   if(BISON_EXE AND LEX_EXE)
82     add_custom_command(
83       OUTPUT
84       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/automaton_lexer.yy.c
85       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.cacc
86       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.hacc
87
88       DEPENDS
89       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.lex
90       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.yacc
91
92       COMMENT "Generating automaton source files"
93       COMMAND ${BISON_EXE} --name-prefix=xbt_automaton_parser_ -d parserPromela.yacc
94       COMMAND ${LEX_EXE} --prefix=xbt_automaton_parser_ --outfile=automaton_lexer.yy.c parserPromela.lex
95       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/
96       )
97
98     add_custom_target(automaton_generated_src
99       DEPENDS
100       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/automaton_lexer.yy.c
101       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.cacc
102       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.hacc
103       )
104
105     SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
106       "${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.cacc;${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.hacc;${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/automaton_parse.yy.c"
107       )
108   endif()
109
110   message(STATUS "Found flex: ${FLEX_EXE}")
111   IF(FLEX_EXE)
112     set(HAVE_FLEX 1)
113     execute_process(COMMAND ${FLEX_EXE} --version OUTPUT_VARIABLE FLEX_VERSION)
114     string(REGEX MATCH "[0-9]+[.]+[0-9]+[.]+[0-9]+" FLEX_VERSION "${FLEX_VERSION}")
115     string(REGEX MATCH "^[0-9]+" FLEX_MAJOR_VERSION "${FLEX_VERSION}")
116     string(REGEX MATCH "[0-9]+[.]+[0-9]+$" FLEX_VERSION "${FLEX_VERSION}")
117     string(REGEX MATCH "^[0-9]+" FLEX_MINOR_VERSION "${FLEX_VERSION}")
118     string(REGEX MATCH "[0-9]+$" FLEX_PATCH_VERSION "${FLEX_VERSION}")
119   ENDIF()
120
121   message(STATUS "Found flexml: ${FLEXML_EXE}")
122   IF(FLEXML_EXE)
123     set(HAVE_FLEXML 1)
124     execute_process(COMMAND ${FLEXML_EXE} --version OUTPUT_VARIABLE FLEXML_VERSION)
125     if (FLEXML_VERSION MATCHES "version Id:")
126       message(FATAL_ERROR "You have an ancient flexml version (${FLEXML_VERSION}). You need at least v${FLEXML_MIN_MAJOR}.${FLEXML_MIN_MINOR}.${FLEXML_MIN_PATCH} to compile in maintainer mode. Upgrade your flexml, or disable the Maintainer mode option in cmake.")
127     endif()
128
129     string(REGEX MATCH "[0-9]+[.]+[0-9]+[.]+[0-9]+" FLEXML_VERSION "${FLEXML_VERSION}")
130     string(REGEX MATCH "^[0-9]*" FLEXML_MAJOR_VERSION "${FLEXML_VERSION}")
131     string(REGEX MATCH "[0-9]+[.]+[0-9]+$" FLEXML_VERSION "${FLEXML_VERSION}")
132     string(REGEX MATCH "^[0-9]+" FLEXML_MINOR_VERSION "${FLEXML_VERSION}")
133     string(REGEX MATCH "[0-9]+$" FLEXML_PATCH_VERSION "${FLEXML_VERSION}")
134   ENDIF()
135
136   message(STATUS "Found sed: ${SED_EXE}")
137
138   if(HAVE_FLEXML AND HAVE_FLEX AND SED_EXE)
139
140     message(STATUS "Flex version: ${FLEX_MAJOR_VERSION}.${FLEX_MINOR_VERSION}.${FLEX_PATCH_VERSION} (need at least version ${FLEX_MIN_MAJOR}.${FLEX_MIN_MINOR}.${FLEX_MIN_PATCH})")
141     message(STATUS "Flexml version: ${FLEXML_MAJOR_VERSION}.${FLEXML_MINOR_VERSION}.${FLEXML_PATCH_VERSION} (need at least version ${FLEXML_MIN_MAJOR}.${FLEXML_MIN_MINOR}.${FLEXML_MIN_PATCH})")
142
143     IF(     (${FLEXML_MAJOR_VERSION} LESS ${FLEXML_MIN_MAJOR})
144         OR ((${FLEXML_MAJOR_VERSION} EQUAL ${FLEXML_MIN_MAJOR}) AND (${FLEXML_MINOR_VERSION} LESS ${FLEXML_MIN_MINOR}) )
145         OR (    (${FLEXML_MAJOR_VERSION} EQUAL ${FLEXML_MIN_MAJOR})
146             AND (${FLEXML_MINOR_VERSION} EQUAL ${FLEXML_MIN_MINOR})
147             AND (${FLEXML_PATCH_VERSION} LESS ${FLEXML_MIN_PATCH}) ))
148
149       message(FATAL_ERROR "Your flexml version is too old to compile in maintainer mode (need at least v${FLEXML_MIN_MAJOR}.${FLEXML_MIN_MINOR}.${FLEXML_MIN_PATCH}). Upgrade your flexml, or disable the Maintainer mode option in cmake.")
150
151     ENDIF()
152
153     IF(     (${FLEX_MAJOR_VERSION} LESS ${FLEX_MIN_MAJOR})
154         OR ((${FLEX_MAJOR_VERSION} EQUAL ${FLEX_MIN_MAJOR}) AND (${FLEX_MINOR_VERSION} LESS ${FLEX_MIN_MINOR}) )
155         OR (    (${FLEX_MAJOR_VERSION} EQUAL ${FLEX_MIN_MAJOR})
156             AND (${FLEX_MINOR_VERSION} EQUAL ${FLEX_MIN_MINOR})
157             AND (${FLEX_PATCH_VERSION} LESS ${FLEX_MIN_PATCH}) ))
158
159         message(FATAL_ERROR "Your flex version is too old to compile in maintainer mode (need at least v${FLEX_MIN_MAJOR}.${FLEX_MIN_MINOR}.${FLEX_MIN_PATCH}). Upgrade your flex, or disable the Maintainer mode option in cmake (run 'ccmake').")
160
161     ENDIF()
162
163     set(string1  "'s/extern /XBT_PUBLIC_DATA /'")
164     set(string2  "'s/XBT_PUBLIC_DATA \\([^(]*\\)(/XBT_PUBLIC \\1(/'")
165     set(string5  "'s/SET(DOCTYPE)/SET(ROOT_dax__adag)/'")
166     set(string9  "'s/#include <unistd.h>/#if defined(_WIN32)\\n#  ifndef __STRICT_ANSI__\\n#    include <io.h>\\n#    include <process.h>\\n#  endif\\n#else\\n#  include <unistd.h>\\n#endif/g'")
167     set(string14 "'\\!^ \\* Generated [0-9/]\\{10\\} [0-9:]\\{8\\}\\.$$!d'")
168
169     ADD_CUSTOM_COMMAND(
170       OUTPUT    ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.h
171                 ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
172                 ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.c
173                 ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
174
175       DEPENDS   ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid.dtd
176                 ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
177
178       #${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid.dtd
179       COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/surf/xml
180       COMMAND ${FLEXML_EXE} --root-tags platform -b 1000000 -P surfxml --sysid=http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd -S src/surf/xml/simgrid_dtd.l -L src/surf/xml/simgrid.dtd
181       COMMAND ${SED_EXE} -i ${string14} src/surf/xml/simgrid_dtd.l
182       COMMAND ${SED_EXE} -i "'s/FAIL(\"Bad declaration %s.\",yytext)/FAIL(\"Bad declaration %s.\\\\nIf your are using a XML v3 file (check the version attribute in <platform>), please update it with tools\\/simgrid_update_xml.pl\",yytext)/'" src/surf/xml/simgrid_dtd.l
183       COMMAND ${CMAKE_COMMAND} -E echo "       Generated src/surf/xml/simgrid_dtd.l"
184
185       #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
186       COMMAND ${FLEXML_EXE} -b 1000000 --root-tags adag -P dax_ --sysid=dax.dtd -S src/simdag/dax_dtd.l -L src/simdag/dax.dtd
187       COMMAND ${SED_EXE} -i ${string5} src/simdag/dax_dtd.l
188       COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.l
189       COMMAND ${CMAKE_COMMAND} -E echo "       Generated src/simdag/dax_dtd.l"
190
191       #${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid.dtd
192       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid.h
193       COMMAND ${FLEXML_EXE} --root-tags platform -P surfxml --sysid=http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd -H src/surf/xml/simgrid_dtd.h -L src/surf/xml/simgrid.dtd
194       COMMAND ${SED_EXE} -i ${string1} src/surf/xml/simgrid_dtd.h
195       COMMAND ${SED_EXE} -i ${string2} src/surf/xml/simgrid_dtd.h
196       COMMAND ${SED_EXE} -i ${string14} src/surf/xml/simgrid_dtd.h
197       COMMAND ${CMAKE_COMMAND} -E echo "       Generated src/surf/xml/simgrid_dtd.h"
198
199       #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
200       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
201       COMMAND ${FLEXML_EXE} --root-tags adag -P dax_ --sysid=dax.dtd -H src/simdag/dax_dtd.h -L src/simdag/dax.dtd
202       COMMAND ${SED_EXE} -i ${string1} src/simdag/dax_dtd.h
203       COMMAND ${SED_EXE} -i ${string2} src/simdag/dax_dtd.h
204       COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.h
205       COMMAND ${CMAKE_COMMAND} -E echo "       Generated src/simdag/dax_dtd.h"
206
207       #surf/xml/simgrid_dtd.c: surf/xml/simgrid_dtd.l
208       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.c
209       COMMAND ${FLEX_EXE} -o src/surf/xml/simgrid_dtd.c -Psurf_parse_ --noline src/surf/xml/simgrid_dtd.l
210       COMMAND ${SED_EXE} -i ${string9} src/surf/xml/simgrid_dtd.c
211       COMMAND ${SED_EXE} -i 's/int yyl\;/unsigned int yyl\;/' src/surf/xml/simgrid_dtd.c
212       COMMAND ${SED_EXE} -i 's/int surf_parse_leng\;/unsigned int surf_parse_leng\;/' src/surf/xml/simgrid_dtd.c
213       COMMAND ${SED_EXE} -i 's/n = 0\; n < max_size/n = 0\; n < (size_t) max_size/' src/surf/xml/simgrid_dtd.c
214       COMMAND ${SED_EXE} -i "s/register //" src/surf/xml/simgrid_dtd.c
215       COMMAND ${CMAKE_COMMAND} -E echo "       Generated surf/xml/simgrid_dtd.c"
216
217       #simdag/dax_dtd.c: simdag/dax_dtd.l
218       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
219       COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/simdag
220       COMMAND ${FLEX_EXE} -o src/simdag/dax_dtd.c -Pdax_ --noline src/simdag/dax_dtd.l
221       COMMAND ${SED_EXE} -i ${string9}                        src/simdag/dax_dtd.c
222       COMMAND ${SED_EXE} -i 's/int yyl\;/unsigned int yyl\;/' src/simdag/dax_dtd.c
223       COMMAND ${SED_EXE} -i 's/int dax_leng\;/unsigned int dax_leng\;/' src/simdag/dax_dtd.c
224       COMMAND ${CMAKE_COMMAND} -E echo "       Generated src/simdag/dax_dtd.c"
225
226       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
227       COMMENT "Generating files in maintainer mode..."
228       )
229
230   else()
231     if(NOT HAVE_FLEXML)
232       message(STATUS "Error : Install flexml to use the maintainer mode.")
233     endif()
234     if(NOT HAVE_FLEX)
235       message(STATUS "Error : Install flex to use the maintainer mode.")
236     endif()
237     if(NOT SED_EXE)
238       message(STATUS "Error : Install sed before use maintainer mode.")
239     endif()
240
241     message(FATAL_ERROR STATUS "Error : Need to install all tools for maintainer mode !!!")
242   endif()
243
244 endif()
245
246     add_custom_target(maintainer_files
247       DEPENDS ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.h
248               ${CMAKE_HOME_DIRECTORY}/src/surf/xml/simgrid_dtd.c
249               ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
250               ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
251       )