BISON_TARGET inconsistent calling with new CMP0088
I understand that the change with CMP0088
was to change the Working directory (where the generated bison file was to be created) for the BISON_TARGET
macro, but CMP0088
just changes where the "explicit" path is needed.
You either have:
cmake_policy(SET CMP0088 OLD)
BISON_TARGET(my_parser parser.yy ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
or
cmake_policy(SET CMP0088 NEW)
BISON_TARGET(my_parser ${CMAKE_CURRENT_SOURCE_DIR}/parser.yy parser.cpp
DEFINES_FILE parser.h)
It seems to that what one would really wish to do is:
BISON_TARGET(my_parser parser.yy parser.cpp DEFINES_FILE parser.h)
It seems that if the first argument (BisonInput
) to the BISON_TARGET
macro is not an absolute path ${CURRENT_SOURCE_DIR}
should be prepended. This would mean that the source file is located in ${CURRENT_SOURCE_DIR}/parser.yy
and the working directory would be ${CURRENT_BINARY_DIR}
where the generated parser.cpp
and parser.hpp
files would be created, along with the location.hh
, position.hh
, stack.hh
depending upon the version of bison and %defines
in the source file.
A possible patch is below:
diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake
index e75981ca..65377f5d 100644
--- a/Modules/FindBISON.cmake
+++ b/Modules/FindBISON.cmake
@@ -257,18 +257,23 @@ if(BISON_EXECUTABLE)
PARENT_SCOPE # undocumented, do not use outside of CMake
)
set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+ set(_BisonInput "${BisonInput}")
if("x${_BISON_CMP0088}x" STREQUAL "xNEWx")
set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ if(NOT IS_ABSOLUTE "${BisonInput}")
+ set(_BisonInput "${CMAKE_CURRENT_SOURCE_DIR}/${BisonInput}")
+ endif()
endif()
unset(_BISON_CMP0088)
add_custom_command(OUTPUT ${BISON_TARGET_outputs}
- COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${BisonOutput} ${BisonInput}
+ COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${BisonOutput} ${_BisonInput}
VERBATIM
DEPENDS ${BisonInput}
COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}"
WORKING_DIRECTORY ${_BISON_WORKING_DIRECTORY})
+ unset(_BisonInput)
unset(_BISON_WORKING_DIRECTORY)
# define target variables