Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease of use with CMake #203

Open
simmplecoder opened this issue Apr 2, 2024 · 4 comments
Open

Ease of use with CMake #203

simmplecoder opened this issue Apr 2, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@simmplecoder
Copy link

I am not sure if I overlooked it, but It would be great to have a cmake script that users could include and invoke functions to invoke reflex. I have something like this in mind:

include(ReflexSupport)

# The line below generates a target and a custom target which target will depend on
reflex_make_target(TARGET lexer [STATIC | SHARED | OBJECT]
    FILES myflex1.reflex myflex2.reflex
)

Then users could do stuff like

target_include_directories(lexer PUBLIC include/definitions)
target_link_libraries(myapp PRIVATE lexer)

I would be up to implement the above if desired.

@genivia-inc
Copy link
Member

Love to see this materialize.

I would be up to implement the above if desired.

Yes, please do.

@genivia-inc genivia-inc added the enhancement New feature or request label Apr 3, 2024
@simmplecoder
Copy link
Author

I will give it a go then, should have something to show next week or so.

@simmplecoder
Copy link
Author

simmplecoder commented Apr 7, 2024

I have a prototype that I have tested on a small toy project. At the moment, the function looks like this:

add_reflex_target(
    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 )>
)

Here is a usage example:

cmake_minimum_required(VERSION 3.20)
project(monkeylang)

set(CMAKE_CXX_STANDARD 20)

find_package(Reflex REQUIRED)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(ReflexCMakeSupport)

add_reflex_target(
    TARGET lexer
    LIBRARY_TYPE SHARED
    FILES "reflex_input/lex.reflex"
    INCLUDE_DIRECTORIES include # provides token headers which are shared with parser
)

add_executable(app main.cpp)
target_link_libraries(app PRIVATE lexer)

The headers for each .l file will be generated inside CMAKE_CURRENT_BINARY_DIR/${_TARGET}/include/${_TARGET}, so anybody who links to the created target could use it like this (assuming lex.l input and lexer as target name):

#include <lexer/lex.hpp>

To incorporate the work into a PR I thought about applying the cmake script inside example, but I am unsure what targets I could create there. Could you please advise on a set of targets I should create inside examples directory? This would also serve second purpose for testing the script as well.

@genivia-inc
Copy link
Member

Thank you for the update.

Target examples you could pick might be a mix of lexers and C++ applications

  • echo very simple/simplistic example to test if examples build OK and the reflex tool runs OK
  • ctokens or jtokens or ptokens tokenizer (for C/C++, Java, Python)
  • flexexample3 uses Bison
  • cards since it doesn't use/create a lexer or parser, i.e. regex matching
  • and/or create your own?

It's up to you. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants