Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added dependency on FLEX 2.5.39 to MaintainerMode
[simgrid.git] / buildtools / 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   find_program(PYTHON_EXE NAMES python)
14   mark_as_advanced(PYTHON_EXE)
15   if (PYTHON_EXE)
16     add_custom_command(
17       OUTPUT
18       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.c
19       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.c
20       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h
21       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.h
22
23       DEPENDS
24       ${CMAKE_HOME_DIRECTORY}/src/simix/simcalls.py
25       ${CMAKE_HOME_DIRECTORY}/src/simix/simcalls.in
26
27       COMMENT "Generating simcalls source files"
28       COMMAND ${PYTHON_EXE} simcalls.py
29       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/src/simix/
30       )
31
32     add_custom_target(simcalls_generated_src
33       DEPENDS
34       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.c
35       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.c
36       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h
37       ${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.h
38       )
39
40     SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
41       "${CMAKE_HOME_DIRECTORY}/src/simix/popping_enum.h;${CMAKE_HOME_DIRECTORY}/src/simix/popping_generated.c;${CMAKE_HOME_DIRECTORY}/src/simix/popping_bodies.c;${CMAKE_HOME_DIRECTORY}/src/simix/popping_accessors.h"
42       )
43   endif()
44 endif()
45
46 if(enable_maintainer_mode AND NOT WIN32)
47   find_program(FLEX_EXE NAMES flex)
48   find_program(FLEXML_EXE NAMES flexml)
49   find_program(SED_EXE NAMES sed)
50   find_program(BISON_EXE NAMES bison)
51   find_program(LEX_EXE NAMES lex)
52
53   mark_as_advanced(BISON_EXE)
54   mark_as_advanced(LEX_EXE)
55
56   if(BISON_EXE AND LEX_EXE)
57     add_custom_command(
58       OUTPUT
59       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/automaton_lexer.yy.c
60       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.cacc
61       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.hacc
62
63       DEPENDS
64       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.lex
65       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.yacc
66
67       COMMENT "Generating automaton source files"
68       COMMAND ${BISON_EXE} --name-prefix=xbt_automaton_parser_ -d parserPromela.yacc
69       COMMAND ${LEX_EXE} --prefix=xbt_automaton_parser_ --outfile=automaton_lexer.yy.c parserPromela.lex
70       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/
71       )
72
73     add_custom_target(automaton_generated_src
74       DEPENDS
75       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/automaton_lexer.yy.c
76       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.cacc
77       ${CMAKE_HOME_DIRECTORY}/src/xbt/automaton/parserPromela.tab.hacc
78       )
79
80     SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
81       "${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"
82       )
83   endif()
84
85   message(STATUS "Found flex: ${FLEX_EXE}")
86   IF(FLEX_EXE)
87     set(HAVE_FLEX 1)
88     exec_program("${FLEX_EXE} --version" OUTPUT_VARIABLE FLEX_VERSION)
89     string(REGEX MATCH "[0-9]+[.]+[0-9]+[.]+[0-9]+" FLEX_VERSION "${FLEX_VERSION}")
90     string(REGEX MATCH "^[0-9]+" FLEX_MAJOR_VERSION "${FLEX_VERSION}")
91     string(REGEX MATCH "[0-9]+[.]+[0-9]+$" FLEX_VERSION "${FLEX_VERSION}")
92     string(REGEX MATCH "^[0-9]+" FLEX_MINOR_VERSION "${FLEX_VERSION}")
93     string(REGEX MATCH "[0-9]+$" FLEX_PATCH_VERSION "${FLEX_VERSION}")
94   ENDIF()
95
96   message(STATUS "Found flexml: ${FLEXML_EXE}")
97   IF(FLEXML_EXE)
98     set(HAVE_FLEXML 1)
99     exec_program("${FLEXML_EXE} --version" OUTPUT_VARIABLE FLEXML_VERSION)
100     if (FLEXML_VERSION MATCHES "version Id:")
101       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.")
102     endif()
103
104     string(REGEX MATCH "[0-9]+[.]+[0-9]+[.]+[0-9]+" FLEXML_VERSION "${FLEXML_VERSION}")
105     string(REGEX MATCH "^[0-9]*" FLEXML_MAJOR_VERSION "${FLEXML_VERSION}")
106     string(REGEX MATCH "[0-9]+[.]+[0-9]+$" FLEXML_VERSION "${FLEXML_VERSION}")
107     string(REGEX MATCH "^[0-9]+" FLEXML_MINOR_VERSION "${FLEXML_VERSION}")
108     string(REGEX MATCH "[0-9]+$" FLEXML_PATCH_VERSION "${FLEXML_VERSION}")
109   ENDIF()
110
111   message(STATUS "Found sed: ${SED_EXE}")
112
113   if(HAVE_FLEXML AND HAVE_FLEX AND SED_EXE)
114
115     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})")
116     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})")
117
118     IF(     (${FLEXML_MAJOR_VERSION} LESS ${FLEXML_MIN_MAJOR})
119         OR ((${FLEXML_MAJOR_VERSION} EQUAL ${FLEXML_MIN_MAJOR}) AND (${FLEXML_MINOR_VERSION} LESS ${FLEXML_MIN_MINOR}) )
120         OR (    (${FLEXML_MAJOR_VERSION} EQUAL ${FLEXML_MIN_MAJOR})
121             AND (${FLEXML_MINOR_VERSION} EQUAL ${FLEXML_MIN_MINOR})
122             AND (${FLEXML_PATCH_VERSION} LESS ${FLEXML_MIN_PATCH}) ))
123
124       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.")
125
126     ENDIF()
127
128     IF(     (${FLEX_MAJOR_VERSION} LESS ${FLEX_MIN_MAJOR})
129         OR ((${FLEX_MAJOR_VERSION} EQUAL ${FLEX_MIN_MAJOR}) AND (${FLEX_MINOR_VERSION} LESS ${FLEX_MIN_MINOR}) )
130         OR (    (${FLEX_MAJOR_VERSION} EQUAL ${FLEX_MIN_MAJOR})
131             AND (${FLEX_MINOR_VERSION} EQUAL ${FLEX_MIN_MINOR})
132             AND (${FLEX_PATCH_VERSION} LESS ${FLEX_MIN_PATCH}) ))
133
134         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').")
135
136     ENDIF()
137
138     set(string1  "'s/extern *\\([^(]*\\)\\( \\|\\( \\*\\)\\)/XBT_PUBLIC_DATA(\\1\\3) /'")
139     set(string2  "'s/XBT_PUBLIC_DATA(\\([^)]*\\)) *\\([^(]*\\)(/XBT_PUBLIC(\\1) \\2(/'")
140     set(string5  "'s/SET(DOCTYPE)/SET(ROOT_dax__adag)/'")
141     set(string8  "'s/#if defined(_WIN32)/#if defined(_XBT_WIN32)/g'")
142     set(string9  "'s/#include <unistd.h>/#if defined(_XBT_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__TOS_WIN__)\\n#  ifndef __STRICT_ANSI__\\n#    include <io.h>\\n#    include <process.h>\\n#  endif\\n#else\\n#  include <unistd.h>\\n#endif/g'")
143     set(string14 "'\\!^ \\* Generated [0-9/]\\{10\\} [0-9:]\\{8\\}\\.$$!d'")
144     set(string15 "'s/FAIL(\"Premature EOF/if(!ETag_surfxml_include_state()) FAIL(\"Premature EOF/'")
145
146     ADD_CUSTOM_COMMAND(
147       OUTPUT    ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h
148       ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
149       ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
150       ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
151       ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
152       ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
153
154       DEPENDS   ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
155       ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
156       ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
157
158       #${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
159       COMMAND ${FLEXML_EXE} --root-tags platform -b 1000000 -P surfxml --sysid=http://simgrid.gforge.inria.fr/simgrid.dtd -S src/surf/simgrid_dtd.l -L src/surf/simgrid.dtd
160       COMMAND ${SED_EXE} -i ${string14} src/surf/simgrid_dtd.l
161       COMMAND ${CMAKE_COMMAND} -E echo "src/surf/simgrid_dtd.l"
162
163       #${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.l: ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
164       COMMAND ${FLEXML_EXE} -b 1000000 -P graphxml --sysid=graphxml.dtd -S src/xbt/graphxml.l -L src/xbt/graphxml.dtd
165       COMMAND ${SED_EXE} -i ${string14} src/xbt/graphxml.l
166       COMMAND ${CMAKE_COMMAND} -E echo "src/xbt/graphxml.l"
167
168       #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
169       COMMAND ${FLEXML_EXE} -b 1000000 --root-tags adag -P dax_ --sysid=dax.dtd -S src/simdag/dax_dtd.l -L src/simdag/dax.dtd
170       COMMAND ${SED_EXE} -i ${string5} src/simdag/dax_dtd.l
171       COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.l
172       COMMAND ${CMAKE_COMMAND} -E echo "src/simdag/dax_dtd.l"
173
174       #${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
175       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid.h
176       COMMAND ${FLEXML_EXE} --root-tags platform -P surfxml --sysid=http://simgrid.gforge.inria.fr/simgrid.dtd -H include/surf/simgrid_dtd.h -L src/surf/simgrid.dtd
177       COMMAND ${SED_EXE} -i ${string1} include/surf/simgrid_dtd.h
178       COMMAND ${SED_EXE} -i ${string2} include/surf/simgrid_dtd.h
179       COMMAND ${SED_EXE} -i ${string14} include/surf/simgrid_dtd.h
180       COMMAND ${CMAKE_COMMAND} -E echo "include/surf/simgrid_dtd.h"
181
182       #${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h: ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
183       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
184       COMMAND ${FLEXML_EXE} -P graphxml --sysid=graphxml.dtd -H include/xbt/graphxml.h -L src/xbt/graphxml.dtd
185       COMMAND ${SED_EXE} -i ${string1} include/xbt/graphxml.h
186       COMMAND ${SED_EXE} -i ${string2} include/xbt/graphxml.h
187       COMMAND ${SED_EXE} -i ${string14} include/xbt/graphxml.h
188       COMMAND ${CMAKE_COMMAND} -E echo "include/xbt/graphxml.h"
189
190       #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
191       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
192       COMMAND ${FLEXML_EXE} --root-tags adag -P dax_ --sysid=dax.dtd -H src/simdag/dax_dtd.h -L src/simdag/dax.dtd
193       COMMAND ${SED_EXE} -i ${string1} src/simdag/dax_dtd.h
194       COMMAND ${SED_EXE} -i ${string2} src/simdag/dax_dtd.h
195       COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.h
196       COMMAND ${CMAKE_COMMAND} -E echo "src/simdag/dax_dtd.h"
197
198       #surf/simgrid_dtd.c: surf/simgrid_dtd.l
199       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
200       COMMAND ${SED_EXE} -i ${string8} src/surf/simgrid_dtd.l
201       COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/surf
202       COMMAND ${FLEX_EXE} -o src/surf/simgrid_dtd.c -Psurf_parse_ --noline src/surf/simgrid_dtd.l
203       COMMAND ${SED_EXE} -i ${string9} src/surf/simgrid_dtd.c
204       COMMAND ${SED_EXE} -i ${string15} src/surf/simgrid_dtd.c
205       COMMAND ${CMAKE_COMMAND} -E echo "surf/simgrid_dtd.c"
206
207       #xbt/graphxml.c: xbt/graphxml.l
208       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
209       COMMAND ${SED_EXE} -i ${string8} src/xbt/graphxml.l
210       COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/xbt
211       COMMAND ${FLEX_EXE} -o src/xbt/graphxml.c -Pxbt_graph_parse_ --noline src/xbt/graphxml.l
212       COMMAND ${SED_EXE} -i ${string9} src/xbt/graphxml.c
213       COMMAND ${CMAKE_COMMAND} -E echo "xbt/graphxml.c"
214
215       #simdag/dax_dtd.c: simdag/dax_dtd.l
216       COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
217       COMMAND ${SED_EXE} -i ${string8} src/simdag/dax_dtd.l
218       COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/simdag
219       COMMAND ${FLEX_EXE} -o src/simdag/dax_dtd.c -Pdax_ --noline src/simdag/dax_dtd.l
220       COMMAND ${SED_EXE} -i ${string9} src/simdag/dax_dtd.c
221       COMMAND ${CMAKE_COMMAND} -E echo "simdag/dax_dtd.c"
222
223       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
224       COMMENT "Generating files in maintainer mode..."
225       )
226
227   else()
228     if(NOT HAVE_FLEXML)
229       message(STATUS "Error : Install flexml before use maintainer mode.")
230     endif()
231     if(NOT HAVE_FLEX)
232       message(STATUS "Error : Install flex before use maintainer mode.")
233     endif()
234     if(NOT SED_EXE)
235       message(STATUS "Error : Install sed before use maintainer mode.")
236     endif()
237
238     message(FATAL_ERROR STATUS "Error : Need to install all tools for maintainer mode !!!")
239   endif()
240
241 endif()
242
243     add_custom_target(maintainer_files
244       DEPENDS ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h
245       ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
246       ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
247       ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
248       ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
249       ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
250       )