如何在 CMake 中追踪丢失的变量值?



编辑:接受的答案还没有解决我的问题,但它回答了我提出的问题 - 如果你能帮助我解决下面描述的实际问题,你可能会回答这个问题。

我有一个CMake项目,它使用了一个需要设置变量的框架(即 https://github.com/queezythegreat/arduino-cmake,需要ARDUINO_SDK_PATH

)奇怪的是,在我在命令行上设置该变量后,它首先有一个值,但看起来它会在一段时间后消失。

我在跑步

cmake -DARDUINO_SDK_PATH=/path/to/sdk ..

.. 并收到一条错误消息,告诉我它未设置。打印出我CMakeLists.txt顶部的值,并深入到正在检查变量的框架中,给了我这样的结果:

>>> ARDUINO_SDK_PATH (beginning): '/home/me/project/arduino-1.8.2'
>>> ARDUINO_SDK_PATH (before check): '/home/me/project/arduino-1.8.2'
-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
-- Check for working C compiler: /usr/bin/avr-gcc
>>> ARDUINO_SDK_PATH (before check): ''
CMake Error at /home/me/project/arduino-cmake/cmake/ArduinoToolchain.cmake:84 (message):
Could not find Arduino SDK (set ARDUINO_SDK_PATH)!
Call Stack (most recent call first):
/home/me/project/build/CMakeFiles/3.6.2/CMakeSystem.cmake:6 (include)
/home/me/project/build/CMakeFiles/CMakeTmp/CMakeLists.txt:3 (project)
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Configuring incomplete, errors occurred!
See also "/home/me/project/build/CMakeFiles/CMakeOutput.log".

所以看起来ARDUINO_SDK_PATH以某种方式失去了它的价值。我没有找到分配任何值的实际命令,所以我不知道如何继续。. 我现在当然可以在任何地方向我的 CMake 项目添加代码以打印出ARDUINO_SDK_PATH的值,但我想知道是否有一种内置方法来跟踪变量值。

我尝试了cmake --trace ..cmake --trace-expand ..,但输出似乎没有帮助。

系统:Fedora 25 与 CMake 3.6.2

更新

感谢 Florian,我添加了variable_watch(ARDUINO_SDK_PATH)作为CMakeLists.txt的第一行,现在我的变量跟踪线 (message()) 如下所示:

CMake Debug Log at arduino-cmake/cmake/ArduinoToolchain.cmake:41 (MESSAGE):
Variable "ARDUINO_SDK_PATH" was accessed using READ_ACCESS with value
"/home/me/project/arduino-1.8.2".
Call Stack (most recent call first):
/usr/share/cmake/Modules/CMakeDetermineSystem.cmake:98 (include)
CMakeLists.txt:10 (project)
>>> ARDUINO_SDK_PATH (before check): /home/me/project/arduino-1.8.2

我有大约 30 条这样的消息,但后面有几条没有值和跟踪消息的跟踪行。

因此,看起来变量ARDUINO_SDK_PATH被一个新的变量替换,该变量是空的并且不再被跟踪。

繁殖

为了使这种行为可重现,我上传了代码:https://github.com/frans-fuerst/trinket_led

注意:提供的CMakeLists.txt尚未包含有用的代码 - 它只是重现错误。

您需要下载Arduino-SDK,将其解压缩并在命令行上提供路径:

tar xvf ~/Downloads/arduino-1.8.2-linux64.tar.xz 
git clone https://github.com/frans-fuerst/trinket_led
cd trinket_led
git submodules update --init
mkdir build
cd build
cmake -DARDUINO_SDK_PATH=/path/to/arduino-1.8.2 ..

注意:ArduinoToolchain.cmake中有一个看起来可疑的find_path命令。但是您可以以相同的结果删除它..

CMakeFiles/CMakeOutput.log

The target system is: Arduino -  - 
The host system is: Linux - 4.10.12-200.fc25.x86_64+debug - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /usr/bin/avr-gcc 
Build flags: 
Id flags: 
The output was:
0

Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"
The C compiler identification is GNU, found in "/home/frans/_HOME/1704_trinket_led/build/CMakeFiles/3.6.2/CompilerIdC/a.out"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /usr/bin/avr-g++ 
Build flags: 
Id flags: 
The output was:
0

Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is GNU, found in "/home/frans/_HOME/1704_trinket_led/build/CMakeFiles/3.6.2/CompilerIdCXX/a.out"

只需在CMakeLists.txt的顶部放一个variable_watch(ARDUINO_SDK_PATH)即可。

引用

  • variable_watch()
  • 设置和使用变量的 CMake 语法是什么?

相关内容

  • 没有找到相关文章

最新更新