3

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.

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.

I'm running

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

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

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.

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

System: Fedora 25 with CMake 3.6.2

Update

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

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

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

Reproduce

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

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

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

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"
Community
  • 1
  • 1
frans
  • 8,868
  • 11
  • 58
  • 132

1 Answers1

9

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

References

Florian
  • 39,996
  • 9
  • 133
  • 149
  • This is at least very helpful - would give you +10 if that was possible. But now I'm observing a much stranger behavior: I get a message `Variable "ARDUINO_SDK_PATH" was accessed using READ_ACCESS with value ..` with the correct value about 30 times BUT SUDDENLY this message isn't printed any more and my trace messages show empty values. Looks like the variable itself (which is being traced) gets replaced (like in a `EXTERNAL_PROJECT`) – frans Apr 30 '17 at 18:41
  • @frans Strange. But you could try to add `set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)` (just because your error message implies that CMake is not be able to link an executable in `try_compile()`). – Florian Apr 30 '17 at 19:27
  • @frans Could you please take a look into `CMakeFiles/CMakeOutput.log` and `CMakeFiles/CMakeError.log`? I assume there will be more information in those files on what went wrong. – Florian Apr 30 '17 at 20:18
  • there is no `CMakeError.log` - I've added CMakeOutput.log to my post - I couldn't find anything helpful – frans Apr 30 '17 at 20:24
  • @frans Ok. The only thing that could "overwrite" your cached variable in the same project could be another non-cached that is hiding the cached one. Hadn't had the time to look into your code yet, but it could be related to [this](https://github.com/francoiscampbell/CLionArduinoPlugin/issues/11). – Florian May 01 '17 at 09:56
  • this is what it looks like to me, too - but how can a globally set CMake variable be overwritten? I've examined all occurrences of `ARDUINO_SDK_PATH` and they all just read the value (except `find_path` which I removed) – frans May 01 '17 at 10:21
  • I've added another question which more general: http://stackoverflow.com/questions/43718042/how-can-a-cmake-variable-be-hidden – frans May 01 '17 at 11:01