-
Notifications
You must be signed in to change notification settings - Fork 120
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
Trouble compiling a *.l file using CMake #69
Comments
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. |
Is this line necessary in the CMakeLists? |
Adding the line I have mentioned above I always get this CMake error
|
I'm not experienced in CMake and thus cannot help here. |
@anphetamina I think this PR #79 and the mentioned example might help |
@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? |
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:
|
I'm trying to compile the provided c++ example from the doc:
I've also put the path to the winflexbison folder in my PATH environment variable. Using this CMake file:
It will always say:
Inside the
lexer.cpp
file generated is not able to localizeFlexLexer.h
. Am I missing something?The text was updated successfully, but these errors were encountered: