Serious-Engine/Sources/cmake/ParserAndScanner.cmake
James Le Cuirot c09d18623e
Allow ecc to be built independently using its own CMakeLists.txt file
This makes cross-compiling easier, and saves having to build once each
for TFE and TSE.

I considered using CMake's import/export feature, but there's little
point when you're only importing one binary target. Pointing the ECC
variable at the ecc binary itself is simpler.

I copied the minimum CMake version of 2.8.7 from the parent
project. To be confident this would actually work, I tested building
under CentOS 7 with CMake 2.8.12.
2021-11-16 23:06:41 +00:00

26 lines
962 B
CMake

macro(add_parser_and_scanner _PARSER _SCANNER)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.cpp"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.l"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND flex
ARGS -o${_SCANNER}.cpp ${_SCANNER}.l
)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.y"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND bison
ARGS -o${_PARSER}.cpp ${_PARSER}.y -d
)
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.h"
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${_PARSER}.hpp ${_PARSER}.h
)
endmacro()