From 23eb559294e24b5eed8f6c676ed66a2c96163ac4 Mon Sep 17 00:00:00 2001
From: Eon Jeong <eonikupy@gmail.com>
Date: Thu, 28 May 2015 10:41:37 +0900
Subject: [PATCH 1/2] Add DEFINES feature for FindBISON
To: cmake-developers@cmake.org

This changeset adds DEFINES parameter feature to FindBISON module,
which corresponds to bison command line option --defines=FILE.

While --defines option can be given via COMPILE_FLAGS,
doing it messes the whole build process;
the internal BISON_${Name}_OUTPUT_HEADER and following BISON_${Name}_OUTPUT
is determined by the default name (-d), not from the manually given name,
so the dependency checker runs the BISON_TARGET macro again and again.
---
 Modules/FindBISON.cmake | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)
 mode change 100644 => 100755 Modules/FindBISON.cmake

diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake
old mode 100644
new mode 100755
index ec3ee78..d1c8f67
--- a/Modules/FindBISON.cmake
+++ b/Modules/FindBISON.cmake
@@ -128,6 +128,12 @@ if(BISON_EXECUTABLE)
     list(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts})
   endmacro()
 
+  # internal macro
+  macro(BISON_TARGET_option_defines Header)
+    set(BISON_TARGET_output_header "${Header}")
+    list(APPEND BISON_TARGET_cmdopt --defines=${BISON_TARGET_output_header})
+  endmacro()
+
   #============================================================
   # BISON_TARGET (public macro)
   #============================================================
@@ -147,25 +153,44 @@ if(BISON_EXECUTABLE)
         if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
           BISON_TARGET_option_extraopts("${ARGV4}")
         endif()
+        if("${ARGV3}" STREQUAL "DEFINES")
+          BISON_TARGET_option_defines("${ARGV4}")
+        endif()
       endif()
 
-      if(${ARGC} EQUAL 7)
+      if(${ARGC} GREATER 7 OR ${ARGC} EQUAL 7)
         if("${ARGV5}" STREQUAL "VERBOSE")
           BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV6}")
         endif()
-
         if("${ARGV5}" STREQUAL "COMPILE_FLAGS")
           BISON_TARGET_option_extraopts("${ARGV6}")
         endif()
+        if("${ARGV5}" STREQUAL "DEFINES")
+          BISON_TARGET_option_defines("${ARGV6}")
+        endif()
       endif()
 
-      # Header's name generated by bison (see option -d)
-      list(APPEND BISON_TARGET_cmdopt "-d")
-      string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}")
-      string(REPLACE "c" "h" _fileext ${_fileext})
-      string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"
-          BISON_${Name}_OUTPUT_HEADER "${ARGV2}")
-      list(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}")
+      if(${ARGC} EQUAL 9)
+        if("${ARGV7}" STREQUAL "VERBOSE")
+          BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV8}")
+        endif()
+        if("${ARGV7}" STREQUAL "COMPILE_FLAGS")
+          BISON_TARGET_option_extraopts("${ARGV8}")
+        endif()
+        if("${ARGV7}" STREQUAL "DEFINES")
+          BISON_TARGET_option_defines("${ARGV8}")
+        endif()
+      endif()
+
+      if(${BISON_TARGET_output_header} STREQUAL "")
+        # Header's name generated by bison (see option -d)
+        list(APPEND BISON_TARGET_cmdopt "-d")
+        string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}")
+        string(REPLACE "c" "h" _fileext ${_fileext})
+        string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"
+            BISON_TARGET_output_header "${ARGV2}")
+      endif()
+      list(APPEND BISON_TARGET_outputs "${BISON_TARGET_output_header}")
 
       add_custom_command(OUTPUT ${BISON_TARGET_outputs}
         ${BISON_TARGET_extraoutputs}
@@ -181,6 +206,7 @@ if(BISON_EXECUTABLE)
       set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs})
       set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
       set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
+      set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")
 
     endif()
   endmacro()
-- 
2.4.1

