How I get bison/flex on Windows

Having code that depends on bison/flex has always been a bit of a PITA on Windows because you have to manually go get the dependency, install it somewhere and then make sure that all your builds have that location in your PATH in order for find_package(BISON) to work.

Recently, I came up with this recipe that made my life easier; maybe it will help you too.

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
    include(FetchContent)
    FetchContent_Declare(download_bison
        URL "https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip"
        URL_MD5 "720226b1befe7033fb3ecc98f5ffd425"
        DOWNLOAD_EXTRACT_TIMESTAMP FALSE)
    FetchContent_MakeAvailable(download_bison)
    set(BISON_ROOT "${download_bison_SOURCE_DIR}")
    message(STATUS "BISON_ROOT=${BISON_ROOT}")
endif()
find_package(BISON REQUIRED)

…now I don’t need any manual steps for the Windows build to work in CI or for new developers cloning my project.

1 Like