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"
Just put a variable_watch(ARDUINO_SDK_PATH) at the top of your CMakeLists.txt.
References
variable_watch()
What's the CMake syntax to set and use variables?
Related
I haven't been using Clion for some time and these days I tried to run an old project and it gave me this compile error (It used to work fine). Then I created a new project to test, the error still persists. I also tried to update my Clion. Here is the error message:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/ninja -DCMAKE_CXX_COMPILER=/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 -G Ninja /Users/yzr/Desktop/untitled
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9
-- Check for working CXX compiler: /usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 - broken
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/CMakeTestCXXCompiler.cmake:62 (message):
The C++ compiler
"/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command(s):/Applications/CLion.app/Contents/bin/ninja/mac/ninja cmTC_5a895 && [1/2] Building CXX object CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o
FAILED: CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o
/usr/local/Cellar/gcc/9.2.0_1/bin/g++-9 -o CMakeFiles/cmTC_5a895.dir/testCXXCompiler.cxx.o -c /Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
dyld: Library not loaded: /usr/local/opt/isl/lib/libisl.21.dylib
Referenced from: /usr/local/Cellar/gcc/9.2.0_1/libexec/gcc/x86_64-apple-darwin18/9.2.0/cc1plus
Reason: image not found
g++-9: internal compiler error: Abort trap: 6 signal terminated program cc1plus
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://github.com/Homebrew/homebrew-core/issues> for instructions.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/Users/yzr/Desktop/untitled/cmake-build-debug/CMakeFiles/CMakeError.log".
Here is how my CMakeList.txt looks like:
cmake_minimum_required(VERSION 3.21)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
add_executable(untitled main.cpp)
I read this post and added the environment variable but it doesn't seem to work. This is really weird, as it all worked fine. It's just I didn't touch it for some time and need to take a look now. Has anyone encountered this before? Thanks!
Maybe you can try to delete the previous generated cmake-build-debug directory. As the outside environment and version may be updated, some information generated in previous cmake-build-debug directory may no longer be useful. So delete it and Reload the make file to see whether the problem could be solved.
I'm trying to learn cmake and do some basic stuff. It's not going well.
This output seems completely bizarre and broken:
-- The C compiler identification is GNU 10.2.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
PLATFORM_DIR: /home/dtrombley/src/p0/platform/x86_64-pc-cygwin Building on x86_64-pc-cygwin
Including contrib-src/glad...
CMake Error at contrib-src/glad/CMakeLists.txt:19 (project): The CMAKE_C_COMPILER:
x86_64-w64-mingw32-gcc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred! See also "/home/dtrombley/src/p0/build/CMakeFiles/CMakeOutput.log". See also "/home/<user>/src/p0/build/CMakeFiles/CMakeError.log".
I have a CMakeLists.txt in the top directory of my project, that finds my compiler just fine - as you can see about. The compiler is on the system path:
$ which x86_64-w64-mingw32-gcc
/usr/bin/x86_64-w64-mingw32-gcc
Then I include a subdirectory with add_subdirectory(), and it complains that it can't find the C compiler. Which the parent project has found. Shouldn't CMAKE_C_COMPILER be set and inherited by the child directory?
Why would the parent directory be able to find it, but the child directory cannot?
Additionally, setting the CC environment variable as suggested has zero effect.
What is going on here? Setting CMAKE_C_COMPILER explicitly results in the same output.
I need the freshest CMake installed on my OpenSuse in order to use an app. I'm trying to download it from the official site and follow the instructions: https://cmake.org/install/
However, I get the following errors:
aleksandr#linux-b0ak:~/Downloads/cmake-3.17.0-rc1> cmake .
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):
No CMAKE_CXX_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "/home/aleksandr/Downloads/cmake-3.17.0-rc1/CMakeFiles/CMakeOutput.log".
See also "/home/aleksandr/Downloads/cmake-3.17.0-rc1/CMakeFiles/CMakeError.log".
aleksandr#linux-b0ak:~/Downloads/cmake-3.17.0-rc1> ./bootstrap
---------------------------------------------
CMake 3.17.0-rc1, Copyright 2000-2020 Kitware, Inc. and Contributors
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.
Please specify one using environment variable CXX.
The C++ flags are "".
They can be changed using the environment variable CXXFLAGS.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /home/aleksandr/Downloads/cmake-3.17.0-rc1/Bootstrap.cmk/cmake_bootstrap.log
I am getting errors when trying to build nanomsg project in Windows 7:
cmake ..
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_5d837\fast"
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/cmake-3.9.4-win64-x64/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe" is not
able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_5d837\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_5d837\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:29 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeError.log".
I use gcc compiler and make from Mingw toolchain and I can run succesfully gcc.exe and mingw32-make.exe on a simple example.
In the file CMakeCache.txt the cache variables are set as follows:
//C compiler
CMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
//Program used to build from makefiles.
CMAKE_MAKE_PROGRAM:STRING=nmake
I think that the problem comes from CMAKE_MAKE_PROGRAM variable it should take C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe, however i dont understand from where it gets the value nmake.
Even i replaced it manually I get the same problem.
My questions :
How CMake fills the Cache variables ?
Why CMAKE_MAKE_PROGRAM takes the value nmake ?
Why changing manually this variable didn t solve the problem ?
CMake fills the cache file with the values it detects based what is in CMakeLists.txt and whatever files it includes in combination with any -D paramters supplied to cmake.
On Windows CMake will default to Microsoft's nmake tool. The way to override this is by passing parameter -G"MinGW Makefiles" to cmake, or in case you use MSYS shell -G"MSYS Makefiles".
But there is a faster build tool than make called Ninja (get it from https://ninja-build.org/) which you can use by passing -GNinja to cmake.
Note: I see you're using the old MinGW that comes with Code::Blocks. There is a more up to date successor to MinGW called MinGW-w64, which supports both Windows 32-bit and 64-bit. A recent standalone build can be downloaded from https://winlibs.com/ and it also includes ninja.exe.
P.S.: If you run into more issues building the nanomsg sources after following these tips, consider passing -DNN_TESTS:BOOL=OFF to cmake
I would like to investigate why I have this error:
$ cmake ..
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc" is not
able to compile a simple test program.
Unfortunately after the error:
I have no idea of what CMake did. I don't have a verbose log of the command it executed.
The CMakeFiles/cmTC_e4aa4.dir was cleaned after the error, so I have no possibility to explore the issue myself.
How should I investigate such an error?
I tried to use the --debug-trycompile option. This time CMake creates a CMakeTmp folder which makes perfectly without errors. However, I still have this CMakeFiles/cmTC_e4aa4.dir that generates errors and even with the option CMake unlinks the folder.
Getting a Verbose Log
The try_compile() calls that CMake does in the beginning to test the compiler, gives a detailed error output on the console and writes it to
[your binary output directory]/CMakeFiles/CMakeError.log
I've checked the source code again and there is no CMake option that would give more a more detailed output for CMake's internal try_compile() calls.
You could just force the output to standard output by adding some variable_watch() calls to your main CMakeLists.txt before your project() call like:
variable_watch(__CMAKE_C_COMPILER_OUTPUT)
variable_watch(__CMAKE_CXX_COMPILER_OUTPUT)
Keeping the Temporary Files
To keep the temporary file of try_compile, add --debug-trycompile to the cmake command line.
But be aware that the multiple compiler tests at the beginning overwrite the artifacts of previous ones:
It may however change the results of the try-compiles as old junk from a previous try-compile may cause a different test to either pass or fail incorrectly. This option is best used for one try-compile at a time, and only when debugging.
References
How to keep generated temporary files?
CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
For me, none of the log files in my output directory contained useful information from try_compile(), even when using --debug-trycompile.
I ended up using the OUTPUT_VARIABLE option to capture and then print the output like this:
try_compile(<options> OUTPUT_VARIABLE TRY_COMPILE_OUTPUT)
message(WARNING ${TRY_COMPILE_OUTPUT})