Genivia / RE-flex

A high-performance C++ regex library and lexical analyzer generator with Unicode support. Extends Flex++ with Unicode support, indent/dedent anchors, lazy quantifiers, functions for lex and syntax error reporting and more. Seamlessly integrates with Bison and other parsers.
https://www.genivia.com/doc/reflex/html
BSD 3-Clause "New" or "Revised" License
504 stars 85 forks source link

Add CMake support for generating Reflex targets #204

Closed simmplecoder closed 4 months ago

simmplecoder commented 4 months ago

This PR addresses #203, adds a cmake function to create Reflex targets from the specified sources. It aims to provide easy-to-use CMake interface for users wishing to use Reflex as lexer generator. The product of the function is self-sufficient target. In case of a library the users can freely target_link_libraries against it.

The signature of the function is straightforward:

add_reflex_target(
    TARGET_TYPE <EXECUTABLE|LIBRARY>
    TARGET <target_name>
    LIBRARY_TYPE <whataever add_library accepts as type>
    FILES <list of reflex source files>
    INCLUDE_DIRECTORIES <list of public include directories>
    DEPENDENCY_TARGETS <list of targets to put inside target_link_libraries(<target_name> PUBLIC )>
)
simmplecoder commented 4 months ago

I would like to add an example that creates a library and then the library is linked into final executable. CMake has a concept of libraries and executables, but with bison it seems the headers are inside executable target, while the lexer library would depend on that. It makes creating a target rather awkward, so I thought I could get your opinion on other bits first. I also looked at the github actions, but it seems like it does not use cmake at all.

genivia-inc commented 4 months ago

I would like to add an example that creates a library and then the library is linked into final executable. CMake has a concept of libraries and executables, but with bison it seems the headers are inside executable target, while the lexer library would depend on that. It makes creating a target rather awkward, so I thought I could get your opinion on other bits first. I also looked at the github actions, but it seems like it does not use cmake at all.

Sorry, my working knowledge of cmake is limited to help you out. Perhaps check SO, Quora etc for answers? A similar SO Q&A: https://stackoverflow.com/questions/19398113/cmake-and-flex-bison

Perhaps create a couple of example cmake files? E.g. one for just using the reflex library, one for just using a scanner and one for using a scanner and Bison parse?

simmplecoder commented 4 months ago

I have looked at the examples and assuming they are how people usually use it, my code unfortunately will not be helpful as the cmake I wrote would require some valid (not necessarily useful) headers to be generated from reflex. Also it requires a bit more rigid naming with headers, which most people might not find useful. It came against my own usage cases, which is why I will have to abandon this PR for now. Please feel free to incorporate/modify/remove my code as you see fit.

genivia-inc commented 4 months ago

OK. It is a always good sign of a grown-up attitude to give something up if it doesn't meet expectations in the end. Don't get me wrong, I appreciate your work on this. I will keep your suggestions in mind!