From ce5d908bb1256ede680fbfd521f087060a567dca Mon Sep 17 00:00:00 2001
From: Martin Jansa <martin.jansa@gmail.com>
Date: Tue, 3 Sep 2024 14:17:51 +0200
Subject: [PATCH] CMakeLists.txt: allow to set BISON_FLAGS like -l

Signed-off-by: Martin Jansa <martin.jansa@gmail.com>

Upstream-Status: Pending
---
 CMakeLists.txt | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -108,16 +108,21 @@ include_directories(SYSTEM ${LIBCEREAL_I
 
 find_package(BISON REQUIRED)
 find_package(FLEX REQUIRED)
+
+# avoid buildpaths in generated #line statements and allow to pass --file-prefix-map=OLD=NEW
+set(BISON_FLAGS "${BISON_FLAGS} -l")
+set(FLEX_FLAGS "${FLEX_FLAGS} -L")
+
 # `parser_class_name` is deprecated and generates warnings in bison >= 3.3.
 # But `api.parser.class` is not supported in bison < 3.3. So we must inject
 # the %define based on the bison version here.
 if(${BISON_VERSION} VERSION_GREATER_EQUAL 3.3)
-  set(BISON_FLAGS "-Dapi.parser.class={Parser} -Wcounterexamples")
+  set(BISON_FLAGS "${BISON_FLAGS} -Dapi.parser.class={Parser} -Wcounterexamples")
 else()
-  set(BISON_FLAGS "-Dparser_class_name={Parser} -Wcounterexamples")
+  set(BISON_FLAGS "${BISON_FLAGS} -Dparser_class_name={Parser} -Wcounterexamples")
 endif()
 bison_target(bison_parser src/parser.yy ${CMAKE_BINARY_DIR}/parser.tab.cc COMPILE_FLAGS ${BISON_FLAGS} VERBOSE)
-flex_target(flex_lexer src/lexer.l ${CMAKE_BINARY_DIR}/lex.yy.cc)
+flex_target(flex_lexer src/lexer.l ${CMAKE_BINARY_DIR}/lex.yy.cc COMPILE_FLAGS ${FLEX_FLAGS})
 add_flex_bison_dependency(flex_lexer bison_parser)
 add_library(parser STATIC ${BISON_bison_parser_OUTPUTS} ${FLEX_flex_lexer_OUTPUTS})
 target_compile_options(parser PRIVATE "-w")
