如何在CMake中跟踪丢失的变量值? [英] How to trace a lost variable value in CMake?

查看:68
本文介绍了如何在CMake中跟踪丢失的变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:已接受的答案尚不能解决我的问题,但可以回答我所提出的问题-如果您能为我解决以下所述的实际问题,您可能会回答

Edit: the accepted answer does not solve my problem yet but it answered the question I've asked - if you can help me with my actual problem described below you might answer this question.

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

I have a CMake-project which makes use of a framework which needs a variable to be set (namely https://github.com/queezythegreat/arduino-cmake, which needs ARDUINO_SDK_PATH)

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

Strangely after I set that variable on the command line it first has a value but it looks like it disappears after a while.

我在跑步

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

..并收到一条错误消息,告诉我未设置.在我的 CMakeLists.txt 顶部打印出该值,并在该框架内的要检查变量的内部深处打印出这样的内容:

.. and get an error message which tells me that it's not set. Printing out the value at the top of my CMakeLists.txt and deep inside this framework where the variable is being checked gives me something like this:

>>> 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 但我想知道是否存在一种内置的方式来跟踪变量值.

So it looks like ARDUINO_SDK_PATH looses it's value somehow. I didn't find an actual command where it get's assigned any value so I don't know how to proceed.. I can now of course add code to my CMake project everywhere to print out the value of ARDUINO_SDK_PATH but I wonder if there's a builtin way to trace variable values.

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

I tried cmake --trace .. and cmake --trace-expand .. but the output doesn't seem helpful..

系统:带有CMake 3.6.2的Fedora 25

System: Fedora 25 with CMake 3.6.2

更新

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

Thanks to Florian I've added variable_watch(ARDUINO_SDK_PATH) as my first line in CMakeLists.txt and now my variable trace lines (message()) look like this:

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条这样的消息,但有两条跟踪行没有的值和没有跟踪的消息.

I have about 30 messages like this but there follow a couple of trace lines without the value and without the trace message.

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

So it looks like the variable ARDUINO_SDK_PATH gets replaced by a new one which is empty and which is not traced any more..

复制

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

In order to make this behavior reproducible I've uploaded the code: https://github.com/frans-fuerst/trinket_led

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

Note: the provided CMakeLists.txt does not contain useful code yet - it just reproduces the error.

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

You need to download the Arduino-SDK, extract it and provide the path on the command line:

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 命令,看起来很可疑.但是您可以删除它,并得到相同的结果.

Note: there is a find_path command in ArduinoToolchain.cmake which looks suspicious. But you can remove it with the same result..

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).

Just put a variable_watch(ARDUINO_SDK_PATH) at the top of your CMakeLists.txt.

参考

这篇关于如何在CMake中跟踪丢失的变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆