Add build of lib/expr using CMake
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sat, 21 Nov 2020 16:17:52 +0000 (17:17 +0100)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 16 Feb 2021 07:24:19 +0000 (08:24 +0100)
Towards https://gitlab.com/graphviz/graphviz/-/issues/1878.

lib/CMakeLists.txt
lib/expr/CMakeLists.txt [new file with mode: 0644]

index e36724a7cc5acb30926cfaba304935b610462851..34df31533fe640e3143cbaa7219e3a3a9043b6fb 100644 (file)
@@ -4,6 +4,7 @@ add_subdirectory(cdt)
 add_subdirectory(circogen)
 add_subdirectory(common)
 add_subdirectory(dotgen)
+add_subdirectory(expr)
 add_subdirectory(fdpgen)
 add_subdirectory(ingraphs)
 add_subdirectory(label)
diff --git a/lib/expr/CMakeLists.txt b/lib/expr/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7272716
--- /dev/null
@@ -0,0 +1,70 @@
+BISON_TARGET(
+  Exparse
+  exparse.y
+  ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c
+  COMPILE_FLAGS "--yacc -Wno-yacc --defines --debug --verbose"
+)
+
+add_custom_command(
+    OUTPUT exparse.c
+    MAIN_DEPENDENCY y.tab.c
+    COMMAND sed -e "s/fprintf/sfprintf/g" -e "s/FILE/Sfio_t/g" -e "s/stderr/sfstderr/g" ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c > exparse.c
+)
+
+if (WIN32)
+    add_custom_command(
+        OUTPUT exparse.h
+        MAIN_DEPENDENCY y.tab.h
+        COMMAND echo \#ifndef _EXPARSE_H > exparse.h
+        COMMAND echo \#define _EXPARSE_H >> exparse.h
+        COMMAND type y.tab.h >> exparse.h
+        COMMAND echo \#endif /* _EXPARSE_H */ >> exparse.h
+    )
+else()
+    add_custom_command(
+        OUTPUT exparse.h
+        MAIN_DEPENDENCY y.tab.h
+        COMMAND echo "\\#ifndef _EXPARSE_H" > exparse.h
+        COMMAND echo "\\#define _EXPARSE_H" >> exparse.h
+        COMMAND cat y.tab.h >> exparse.h
+        COMMAND echo "\\#endif /* _EXPARSE_H */" >> exparse.h
+    )
+endif()
+
+add_library(expr STATIC
+    # Header files
+    exgram.h
+    exlib.h
+    exop.h
+    expr.h
+
+    # Source files
+    excc.c
+    excontext.c
+    exdata.c
+    exerror.c
+    exeval.c
+    exexpr.c
+    exlexname.c
+    exopen.c
+    exrewind.c
+    extoken.c
+    extype.c
+    exzero.c
+    exnospace.c
+    exstash.c
+
+    # Generated files
+    ${CMAKE_CURRENT_BINARY_DIR}/exparse.h
+    ${CMAKE_CURRENT_BINARY_DIR}/exparse.c
+)
+
+target_include_directories(expr PRIVATE
+    ${GRAPHVIZ_LIB_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_BINARY_DIR}/.. # needed to find generated expr/exparse.h
+    ${GRAPHVIZ_LIB_DIR}/ast
+    ${GRAPHVIZ_LIB_DIR}/vmalloc
+    ${GRAPHVIZ_LIB_DIR}/sfio
+    ${GRAPHVIZ_LIB_DIR}/cdt
+)