Logo AND Algorithmique Numérique Distribuée

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