1

我想建立一个项目@local 字典。

在“CMakeLists.txt”中,项目 A 想使用“FIND_PACKAGE”命令找到另一个库 B。

问题是库 B 可以在系统目录中找到,而我在本地目录中重建它,那么我如何在键入“cmake .”时通过输入附加参数来控制这种情况?

4

2 回答 2

1

您可以使用 CMake 的-D 命令行选项指定变量值。

请注意,有问题的变量必须存储在缓存中才能工作,因为命令行只是设置一个缓存条目,而局部变量隐藏了同名的缓存变量。

cmake -DMY_AWESOME_VARIABLE=Foo <path_to_source>

CMakeLists.txt

 [...]
# set a default value that will be used if no option is given on the command line
set(MY_AWESOME_VARIABLE "Default value" CACHE STRING "")
# this line will output the current value from cache; so either the default
# value or whatever was given last on the command line
message(${MY_AWESOME_VARIABLE})
# local variables hide cache entry, so the next message will always print "Local"
set(MY_AWESOME_VARIABLE "Local")
message(${MY_AWESOME_VARIABLE})
于 2013-10-11T11:07:06.433 回答
0

您可以暂时将 PATH 环境变量更改为仅本地 bin aud 或 usr... 通过运行 cmake :

PATH=~/bin:~/usr:~/usr/bin cmake

但是你必须将所有必需的可执行文件放在那个/那些文件夹中。

于 2013-10-11T04:43:58.973 回答