Comments (7)
as I know FlexLexer.h is a mandatory file when you generate C++ lexer. It should be in the same folder where win_flex.exe resides.
It seems Cmake know it somehow and tries to locate it.
from winflexbison.
Is this line necessary in the CMakeLists?
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
from winflexbison.
Adding the line I have mentioned above I always get this CMake error
CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: FL_LIBRARY (ADVANCED)
from winflexbison.
I'm not experienced in CMake and thus cannot help here.
from winflexbison.
@anphetamina I think this PR #79 and the mentioned example might help
from winflexbison.
@LonghronShen So we do have a new version with the PR included (available binaries found in the README as CI artifacts) now. Can you please elaborate where the issue with the initial approach is?
from winflexbison.
Thank you for the quick merge!
The CMake code snip from the OP:
find_package(BISON)
find_package(FLEX)
The FindFlex and FindBison module bundled with the CMake itself assumes that the Flex and Bison installation is on the default search path. This is not a problem for working on non-Windows platforms, or a custom CMake toolchain is provided. But for Windows users, this is not very easy for CMake to automatically find WinFlexBison without proper installation or settings.
If you don't want to install the WinFlexBison by tools like chocolatey, or write a custom CMake toolchain that defines the search path for flex and bison, with the PR #79 and the CMake modules provided in the example, you can now directly import and add WinFlexBison as a pure CMake dependency like this:
include(FetchContent)
if(WIN32)
# winflexbision
FetchContent_Declare(winflexbision
GIT_REPOSITORY https://github.com/lexxmark/winflexbison.git
GIT_TAG master)
FetchContent_GetProperties(winflexbision)
if(NOT winflexbision_POPULATED)
FetchContent_Populate(winflexbision)
add_subdirectory(${winflexbision_SOURCE_DIR} ${winflexbision_BINARY_DIR} EXCLUDE_FROM_ALL)
execute_process(COMMAND ${CMAKE_COMMAND}
-S ${winflexbision_SOURCE_DIR}
-B ${CMAKE_BINARY_DIR}/external/winflexbision
-G ${CMAKE_GENERATOR}
-D CMAKE_BUILD_TYPE=Debug
-D CMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
-D CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG=${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}
-D CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}
)
execute_process(COMMAND ${CMAKE_COMMAND}
--build ${CMAKE_BINARY_DIR}/external/winflexbision
)
execute_process(COMMAND ${CMAKE_COMMAND}
--install ${CMAKE_BINARY_DIR}/external/winflexbision --prefix ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
set(BISON_ROOT_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" CACHE STRING "BISON_ROOT_DIR" FORCE)
set(FLEX_ROOT_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" CACHE STRING "FLEX_ROOT_DIR" FORCE)
set(BISON_EXECUTABLE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/win_bison.exe" CACHE STRING "BISON_EXECUTABLE" FORCE)
set(BISON_version_result "0" CACHE STRING "BISON_version_result" FORCE)
set(BISON_version_output "bison++ Version 1,0,0" CACHE STRING "BISON_version_result" FORCE)
set(FLEX_EXECUTABLE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/win_flex.exe" CACHE STRING "FLEX_EXECUTABLE" FORCE)
set(FLEX_version_result "0" CACHE STRING "FLEX_version_result" FORCE)
set(FLEX_FIND_REQUIRED "0" CACHE STRING "FLEX_FIND_REQUIRED" FORCE)
include(UseBISON)
include(UseFLEX)
endif()
# unistd_h
FetchContent_Declare(unistd_h
GIT_REPOSITORY https://github.com/win32ports/unistd_h.git
GIT_TAG 0dfc48c1bc67fa27b02478eefe0443b8d2750cc2)
FetchContent_GetProperties(unistd_h)
if(NOT unistd_h_POPULATED)
FetchContent_Populate(unistd_h)
# add_subdirectory(${unistd_h_SOURCE_DIR} ${unistd_h_BINARY_DIR} EXCLUDE_FROM_ALL)
include_directories(${unistd_h_SOURCE_DIR})
endif()
else()
if(APPLE)
find_program(MAC_HBREW_BIN brew)
if(MAC_HBREW_BIN)
execute_process(COMMAND ${MAC_HBREW_BIN} "--prefix" OUTPUT_VARIABLE BREW_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
list(INSERT CMAKE_PREFIX_PATH 0 ${BREW_PREFIX})
endif()
execute_process(
COMMAND ${MAC_HBREW_BIN} --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
list(INSERT CMAKE_PREFIX_PATH 0 "${BREW_BISON_PREFIX}")
else()
message(FATAL_ERROR "Cannot find bison from homebrew.")
endif()
execute_process(
COMMAND ${MAC_HBREW_BIN} --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
list(INSERT CMAKE_PREFIX_PATH 0 "${BREW_FLEX_PREFIX}")
else()
message(FATAL_ERROR "Cannot find flex from homebrew.")
endif()
endif()
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
endif()
...
BISON_TARGET(xy_parser syntactic.y ${CMAKE_CURRENT_BINARY_DIR}/syntactic.cpp)
FLEX_TARGET(xy_scanner lexical.l ${CMAKE_CURRENT_BINARY_DIR}/lexical.cpp)
ADD_FLEX_BISON_DEPENDENCY(xy_scanner xy_parser)
add_library(xy-compiler-parser STATIC
${SRC}
${BISON_xy_parser_OUTPUTS}
${FLEX_xy_scanner_OUTPUTS})
target_link_libraries(xy-compiler-parser
PUBLIC ${llvm_libs}
PUBLIC ${FLEX_LIBRARIES})
target_include_directories(xy-compiler-parser
PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
PUBLIC ${CMAKE_CURRENT_LIST_DIR})
if(WIN32)
add_dependencies(xy-compiler-parser
win_bison
win_flex)
endif()
Note:
target_link_libraries
is important because this will automatically add the include directory of flex into the include directories list of this target so that FlexLexer.h can be found when compiling this target.- The trick is that an external CMake based project repo can be added as an dependency using the FetchContent module. So the whole WinFlexBison project is included, and the Unistd patch is also included. After the project is fetched, the build and installation command can be called so that the WinFlex and WinBison can be installed into the output directory of the current project. Then the bison and flex executable and header file paths can be inferred and directly injected to override the default actions in the FindFlex and FindBison module bundled with the CMake.
- The modification in the PR #79 contains the libfl and liby which are required by some projects, so that
${FLEX_LIBRARIES}
will work as expected. - By the way, the PR #79 only applies to the 3.x branch. For the 2.x branch, you can use the 2.x branch of my fork.
from winflexbison.
Related Issues (20)
- v2.5.23 not working on Windows XP HOT 25
- Can not fix file via --update HOT 16
- Crash on invalid input HOT 6
- Visual Studio - win_bison creates tab.h file exceeding compiler limits HOT 8
- Update to bison 3.7.4 HOT 10
- %option c++ is not compatible with %option noyywrap - linker error: multiple definition HOT 5
- Install guide lines? HOT 3
- Loss of data conversion in Flex scanner. HOT 5
- Update to Bison 3.8.1 HOT 11
- Missing LICENSE/COPYING file in repository toplevel HOT 6
- Cannot compile Bison input in C++ mode HOT 2
- Visual Studio dependencies and the provided CustomBuildRules HOT 3
- Could this project build with gcc HOT 2
- Runtime error when running multiple flex processes HOT 19
- D language support fixes reported upstream
- Using api.prefix{ ... } breaks yyerror()
- Chocolatey for 2.5.25 (Bison 3.8) HOT 1
- BSD license and GPL license missing from the binary package
- YYPTRDIFF_T not 64bit compatible?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winflexbison.