[CMAKE] Introduce a way to use auto generation using bison and flex. Dedicated to...
authorAmine Khaldi <amine.khaldi@reactos.org>
Thu, 27 Aug 2015 23:00:49 +0000 (23:00 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Thu, 27 Aug 2015 23:00:49 +0000 (23:00 +0000)
svn path=/trunk/; revision=68840

reactos/CMakeLists.txt
reactos/cmake/bison-flex.cmake [new file with mode: 0644]

index 3894c68..654ba0c 100644 (file)
@@ -75,6 +75,9 @@ if(NOT MSVC_IDE)
     unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
 endif()
 
+# Bison and Flex support
+# include(cmake/bison-flex.cmake)
+
 if(NOT CMAKE_CROSSCOMPILING)
 
     add_definitions(-DTARGET_${ARCH})
diff --git a/reactos/cmake/bison-flex.cmake b/reactos/cmake/bison-flex.cmake
new file mode 100644 (file)
index 0000000..d03d4a8
--- /dev/null
@@ -0,0 +1,27 @@
+
+# Simply use :
+#  add_bison_files(foo.y)
+#  and
+#  add_flex_files(foo.l)
+#  then add ${CMAKE_CURRENT_BINARY_DIR}/foo.tab.c
+#  and ${CMAKE_CURRENT_BINARY_DIR}/foo.yy.c to the source list
+
+function(add_bison_files)
+    foreach(_file ${ARGN})
+        get_filename_component(_name ${_file} NAME_WE)
+        add_custom_command(
+            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.c ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.h
+            COMMAND bison -p ${_name}_ -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.c --defines=${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.h ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+    endforeach()
+endfunction()
+
+function(add_flex_files)
+    foreach(_file ${ARGN})
+        get_filename_component(_name ${_file} NAME_WE)
+        add_custom_command(
+            OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.c ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.h
+            COMMAND flex -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.c --header-file=${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.h ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
+            DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+    endforeach()
+endfunction()