问题描述
我想将cmake指向特定位置,以在特定平台上找到Bison可执行文件。有没有办法做到这一点?
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()
推荐答案
根据对于模块 FindBISON.cmake
,此模块设置了变量 BISON_EXECUTABLE 指向程序的可执行文件。
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
不需要缓存,因此设置它们会影响结果。例如,在同一文档中为 FindBISON.cmake
列出的变量 BISON_VERSION 未缓存,因此您可能无法重新定义它影响脚本。
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:如何为野牛使用自定义可执行路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!