Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix source for generated files.
[simgrid.git] / buildtools / Cmake / MaintainerMode.cmake
1 if(enable_maintainer_mode AND NOT WIN32)
2 find_program(FLEX_EXE NAMES flex)
3 find_program(FLEXML_EXE NAMES flexml)
4 find_program(SED_EXE NAMES sed)
5
6 IF(FLEX_EXE)
7         set(HAVE_FLEX 1)
8         exec_program("${FLEX_EXE} --version" OUTPUT_VARIABLE FLEX_VERSION)
9         string(REGEX MATCH "[0-9]+[.]+[0-9]+[.]+[0-9]+" FLEX_VERSION "${FLEX_VERSION}")
10         string(REGEX MATCH "^[0-9]+" FLEX_MAJOR_VERSION "${FLEX_VERSION}")
11         string(REGEX MATCH "[0-9]+[.]+[0-9]+$" FLEX_VERSION "${FLEX_VERSION}")
12         string(REGEX MATCH "^[0-9]+" FLEX_MINOR_VERSION "${FLEX_VERSION}")
13         string(REGEX MATCH "[0-9]+$" FLEX_PATCH_VERSION "${FLEX_VERSION}")
14 ENDIF(FLEX_EXE)
15
16 IF(FLEXML_EXE)
17         set(HAVE_FLEXML 1)
18         exec_program("${FLEXML_EXE} --version" OUTPUT_VARIABLE FLEXML_VERSION)
19         string(REGEX MATCH "[0-9]+[.]+[0-9]+" FLEXML_VERSION "${FLEXML_VERSION}")
20         string(REGEX MATCH "^[0-9]*" FLEXML_MAJOR_VERSION "${FLEXML_VERSION}")
21         string(REGEX MATCH "[0-9]*$" FLEXML_MINOR_VERSION "${FLEXML_VERSION}")
22 ENDIF(FLEXML_EXE)
23
24 message(STATUS "Found flex: ${FLEX_EXE}")
25 message(STATUS "Found flexml: ${FLEXML_EXE}")
26 message(STATUS "Found sed: ${SED_EXE}")
27
28 if(HAVE_FLEXML AND HAVE_FLEX AND SED_EXE)
29
30 message(STATUS "Flex version: ${FLEX_MAJOR_VERSION}.${FLEX_MINOR_VERSION}.${FLEX_PATCH_VERSION}")
31 message(STATUS "Flexml version: ${FLEXML_MAJOR_VERSION}.${FLEXML_MINOR_VERSION}")
32
33 set(string1  "'s/extern  *\\([^ ]*[ \\*]*\\)/XBT_PUBLIC_DATA(\\1) /'")
34 set(string2  "'s/XBT_PUBLIC_DATA(\\([^)]*\\)) *\\([^(]*\\)(/XBT_PUBLIC(\\1) \\2(/'")
35 set(string3  "'s/extern  *\\([^ ]*[ \\*]*\\)/XBT_PUBLIC_DATA(\\1) /'")
36 set(string4  "'s/XBT_PUBLIC_DATA(\\([^)]*\\)) *\\([^(]*\\)(/XBT_PUBLIC(\\1) \\2(/'")
37 set(string5  "'s/SET(DOCTYPE)/SET(ROOT_dax__adag)/'")
38 set(string6  "'s/extern  *\\([^ ]*[ \\*]*\\)/XBT_PUBLIC_DATA(\\1) /'")
39 set(string7  "'s/XBT_PUBLIC_DATA(\\([^)]*\\)) *\\([^(]*\\)(/XBT_PUBLIC(\\1) \\2(/'")
40 set(string8  "'s/#if defined(_WIN32)/#if defined(_XBT_WIN32)/g'")
41 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'")
42 set(string10 "'s/#if defined(_WIN32)/#if defined(_XBT_WIN32)/g'")
43 set(string11 "'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'")
44 set(string12 "'s/#if defined(_WIN32)/#if defined(_XBT_WIN32)/g'")
45 set(string13 "'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'")
46 set(string14 "'\\!^ \\* Generated [0-9/]\\{10\\} [0-9:]\\{8\\}\\.$$!d'")
47 set(string15 "'s/FAIL(\"Premature EOF/if(!ETag_surfxml_include_state()) FAIL(\"Premature EOF/'")
48
49 ADD_CUSTOM_COMMAND(
50         OUTPUT  ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h
51                         ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
52                         ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
53                         ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
54                         ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
55                         ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
56                         
57         DEPENDS ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
58                         ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
59                         ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
60                                         
61         #${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
62         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
63         COMMAND ${SED_EXE} -i ${string14} src/surf/simgrid_dtd.l
64         COMMAND ${CMAKE_COMMAND} -E echo "src/surf/simgrid_dtd.l"
65         #${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.l: ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
66         COMMAND ${FLEXML_EXE} -b 1000000 -P graphxml --sysid=graphxml.dtd -S src/xbt/graphxml.l -L src/xbt/graphxml.dtd
67         COMMAND ${SED_EXE} -i ${string14} src/xbt/graphxml.l
68         COMMAND ${CMAKE_COMMAND} -E echo "src/xbt/graphxml.l"
69         #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.l: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
70         COMMAND ${FLEXML_EXE} -b 1000000 --root-tags adag -P dax_ --sysid=dax.dtd -S src/simdag/dax_dtd.l -L src/simdag/dax.dtd
71         COMMAND ${SED_EXE} -i ${string5} src/simdag/dax_dtd.l
72         COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.l
73         COMMAND ${CMAKE_COMMAND} -E echo "src/simdag/dax_dtd.l"
74         
75         #${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid.dtd
76         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid.h
77         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
78         COMMAND ${SED_EXE} -i ${string1} include/surf/simgrid_dtd.h
79         COMMAND ${SED_EXE} -i ${string2} include/surf/simgrid_dtd.h     
80         COMMAND ${SED_EXE} -i ${string14} include/surf/simgrid_dtd.h
81         COMMAND ${CMAKE_COMMAND} -E echo "include/surf/simgrid_dtd.h"
82         #${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h: ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.dtd
83         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
84         COMMAND ${FLEXML_EXE} -P graphxml --sysid=graphxml.dtd -H include/xbt/graphxml.h -L src/xbt/graphxml.dtd
85         COMMAND ${SED_EXE} -i ${string3} include/xbt/graphxml.h 
86         COMMAND ${SED_EXE} -i ${string4} include/xbt/graphxml.h
87         COMMAND ${SED_EXE} -i ${string14} include/xbt/graphxml.h
88         COMMAND ${CMAKE_COMMAND} -E echo "include/xbt/graphxml.h"
89         #${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h: ${CMAKE_HOME_DIRECTORY}/src/simdag/dax.dtd
90         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
91         COMMAND ${FLEXML_EXE} --root-tags adag -P dax_ --sysid=dax.dtd -H src/simdag/dax_dtd.h -L src/simdag/dax.dtd
92         COMMAND ${SED_EXE} -i ${string6} src/simdag/dax_dtd.h   
93         COMMAND ${SED_EXE} -i ${string7} src/simdag/dax_dtd.h
94         COMMAND ${SED_EXE} -i ${string14} src/simdag/dax_dtd.h
95         COMMAND ${FLEX_EXE} -o src/xbt/datadesc/ddt_parse.yy.c -Pxbt_ddt_parse_ --noline src/xbt/datadesc/ddt_parse.yy.l
96         COMMAND ${CMAKE_COMMAND} -E echo "src/simdag/dax_dtd.h"
97         
98         #surf/simgrid_dtd.c: surf/simgrid_dtd.l
99         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
100         COMMAND ${SED_EXE} -i ${string8} src/surf/simgrid_dtd.l
101         COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/surf
102         COMMAND ${FLEX_EXE} -o src/surf/simgrid_dtd.c -Psurf_parse_ --noline src/surf/simgrid_dtd.l
103         COMMAND ${SED_EXE} -i ${string9} src/surf/simgrid_dtd.c
104     COMMAND ${SED_EXE} -i ${string15} src/surf/simgrid_dtd.c
105         
106         COMMAND ${CMAKE_COMMAND} -E echo "surf/simgrid_dtd.c"
107         #xbt/graphxml.c: xbt/graphxml.l
108         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
109         COMMAND ${SED_EXE} -i ${string10} src/xbt/graphxml.l    
110         COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/xbt
111         COMMAND ${FLEX_EXE} -o src/xbt/graphxml.c -Pxbt_graph_parse_ --noline src/xbt/graphxml.l
112         COMMAND ${SED_EXE} -i ${string11} src/xbt/graphxml.c
113         COMMAND ${CMAKE_COMMAND} -E echo "xbt/graphxml.c"
114         #simdag/dax_dtd.c: simdag/dax_dtd.l
115         COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
116         COMMAND ${SED_EXE} -i ${string12} src/simdag/dax_dtd.l
117         COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/src/simdag
118         COMMAND ${FLEX_EXE} -o src/simdag/dax_dtd.c -Pdax_ --noline src/simdag/dax_dtd.l
119         COMMAND ${SED_EXE} -i ${string13} src/simdag/dax_dtd.c
120         COMMAND ${CMAKE_COMMAND} -E echo "simdag/dax_dtd.c"
121         
122         WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
123         COMMENT "Generating files in maintainer mode..."
124 )
125
126         add_custom_target(maintainer_files
127                                                 DEPENDS ${CMAKE_HOME_DIRECTORY}/include/surf/simgrid_dtd.h
128                                                                 ${CMAKE_HOME_DIRECTORY}/include/xbt/graphxml.h
129                                                                 ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.h
130                                                                 ${CMAKE_HOME_DIRECTORY}/src/surf/simgrid_dtd.c
131                                                                 ${CMAKE_HOME_DIRECTORY}/src/xbt/graphxml.c
132                                                                 ${CMAKE_HOME_DIRECTORY}/src/simdag/dax_dtd.c
133                                                 )
134
135 else(HAVE_FLEXML AND HAVE_FLEX  AND SED_EXE)
136         if(NOT HAVE_FLEXML)
137                 message(STATUS "Error : Install flexml before use maintainer mode.")
138         endif(NOT HAVE_FLEXML)
139         if(NOT HAVE_FLEX)
140                 message(STATUS "Error : Install flex before use maintainer mode.")
141         endif(NOT HAVE_FLEX)
142         if(NOT SED_EXE)
143                 message(STATUS "Error : Install sed before use maintainer mode.")
144         endif(NOT SED_EXE)
145         
146         message(FATAL_ERROR STATUS "Error : Need to install all tools for maintainer mode !!!")
147 endif(HAVE_FLEXML AND HAVE_FLEX  AND SED_EXE)
148
149 endif(enable_maintainer_mode AND NOT WIN32)
150