cmake: how to use custom executable path for bison

2019-06-08 14:59发布

问题:

I would like to point cmake to a specific location to find the Bison executable on a specific platform. Is there a way to do this?

if(PLATFORM STREQUAL "Darwin")
  find_package(
    BISON 3.0.0 REQUIRED
    # Would like to do something like:
    PATH "/usr/local/opt/bison/bin/bison"
    )
else()
  find_package(
    BISON 3.0.0 REQUIRED
    )
endif()
if(BISON_FOUND)
  BISON_TARGET(
    Parser
    ${CMAKE_CURRENT_LIST_DIR}/Parser.yy
    ${CMAKE_CURRENT_BINARY_DIR}/Parser.cpp
    )
  target_sources(
    MyLib PRIVATE
    ${BISON_Parser_OUTPUTS}
    )
endif()

回答1:

According to documentation for module FindBISON.cmake, this module sets variable BISON_EXECUTABLE pointed to the program's executable.

Actually, this is cached variable, which is set be the script with find_program call. So you may set this cached variable manually for fix executable:

if(PLATFORM STREQUAL "Darwin")
    set(BISON_EXECUTABLE "/usr/local/opt/bison/bin/bison" CACHE PATH "Bison executable")
endif()
...
find_package(BISON 3.0.0 REQUIRED)

Note, that variables listed in documentation for different scripts FindXXX.cmake under

module defines the following variables:

don't need to be cached, so setting them will affect on result. E.g., variable BISON_VERSION listed in the same documentation for FindBISON.cmake is not cached, so you may not redefine it for affect on the script.



标签: cmake