CMake Error: include could not find load file: targets - cmake

I'm trying to run AmazonFreeRTOS on my ESP32 (at Windows). After creating build folder in my amazon-freertos main folder I've tried to build it from main folder with
cmake --build .\build
The Error I've got is
include could not find load file: targets
However, there is a idf_functions.cmake file that contains include(targets) command, and the targets.cmake file is in the same folder so I don't know why the error occured.

If you pay close attention to the error, you'd notice the full error says something like:
CMake Error at
your-amazon-freertos-directory/vendors/espressif/esp-idf/tools/cmake/idf_functions.cmake: 26 (include)
include could not find load file:
targets
This is because idf_functions.cmake sets the variable IDF_PATH to $ENV{IDF_PATH} which was configured in ~/.profile when the line export IDF_PATH=~/esp/esp-idf was added, as seen here.
If you navigate to ~/esp/esp-idf/tools/cmake/ you'd notice that files like target.cmake and ldgen.cmake, which are being included <your-amazon-freertos-directory>/vendors/espressif/esp-idf/tools/cmake/idf_functions.cmake, do not exist.
Solution 1 (somewhat hacky):
Copy the contents of <your-amazon-freertos-directory>/vendors/espressif/esp-idf/tools/cmake/ to ~/esp/esp-idf/tools/cmake/
Solution 2:
Modify the ~/.profile file to add the following lines instead of that suggested in the guide:
export IDF_PATH=~/<your-amazon-freertos-directory>/vendors/espressif/esp-idf/
export PATH="$PATH:$IDF_PATH/tools"
This should circumvent any CMake include errors during generation of build files and during build.

Since Amazon FreeRTOS supports many different platforms in addition to ESP32, you might need to supply additional commands to tell CMake that ESP32 is the target you want to build.
Try using
cmake -DVENDOR=espressif -DBOARD=esp32_wrover_kit -DCOMPILER=xtensa-esp32 -S . -B your-build-directory
from your top level folder to generate your makefiles into the build folder, and then switching to your build folder and calling
make all
(From the "Build, Flash, and Run the Amazon FreeRTOS Demo Project" section of
https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html)

Related

Qt example project fails to build (No CMake configuration found)

I am trying to simply open Qt6.4.1 sensors example project, but it says that no CMake configuration found. I already made some simple Qt6 applications for Windows, and i have entire Qt6.4.1 package installed, so cant blame on bad installation. There is an error on line find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Sensors Svg) in CMakeLists.txt. Full error message:
C:\Qt\Examples\Qt-6.4.1\sensors\sensorsshowcase\CMakeLists.txt:12: error: By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6", but CMake did not find one. Could not find a package configuration file provided by "Qt6" with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed.
Pass the path to the directory containing the Qt6 files via CMAKE_PREFIX_PATH cache variable during configuration.
Note: Make sure to specify the type of the variable as PATH or use forward slashes as path separator for this to work properly.
E.g. for me I'd need to pass
-D CMAKE_PREFIX_PATH=D:/Qt/6.4.1/msvc2019_64
to tell CMake to look into the directory containing the Qt6.4.1 files compiled with MSVC.
Make sure that the directory you pass contains the file lib/cmake/Qt6/Qt6Config.cmake; this is the file find_package(Qt6 REQUIRED COMPONENTS ...) is looking for.
You can also fix your project setup that previously failed by adding the cache variable.
cmake -D CMAKE_PREFIX_PATH=D:/Qt/6.4.1/msvc2019_64 path/to/build_dir
Note: Don't forget to add the -A ... option when configuring a VS project; CMake defaults to Win32 as architecture, at least on my system.
You could add this info to a CMAKE_PREFIX_PATH environment variable, if you don't want to specify the info cache variable for every single project using qt 6 that you want to set up on your machine.

How to perform the "make install" step after building aws-sdk-cpp using Qt Creator and CMake

I am trying to add aws-sdk-cpp as a submodule in my Qt application using Qt Creator and CMake. I want it to build for any platform without doing the building and installing on the command line as described here.
My project structure and CMakeLists.txt files looks like this:
I have successfully built the entire aws-sdk-cpp using MSVC2019 in debug mode using Qt Creator. My projects build folder is now 15 GB containing all the built libraries. The current issue I'm now facing is this error:
CMake Error at app/CMakeLists.txt:23 (find_package):
By not providing "FindAWSSDK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "AWSSDK", but
CMake did not find one.
Could not find a package configuration file provided by "AWSSDK" with any
of the following names:
AWSSDKConfig.cmake
awssdk-config.cmake
Add the installation prefix of "AWSSDK" to CMAKE_PREFIX_PATH or set
"AWSSDK_DIR" to a directory containing one of the above files. If "AWSSDK"
provides a separate development package or SDK, be sure it has been
installed.
I think what is missing is the make install step described here and to set the path to AWSSDK_DIR.
I'm very new to CMake and I have not found any way to perform the make install step in the CMakeLists.txt file and then be able to set the AWSSDK_DIR which points to the AWSSDKConfig.cmake or awssdk-config.cmake file missing.
I'm also not sure which CMakeLists.txt file this should be written or if there is an entire other way to do this? Currently I'm stuck getting nowhere..

CMake could not find the VTKConfig.cmake

I'm trying to compile a program in CMake but I'm getting this error.
By not providing "FindVTK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "VTK", but
CMake did not find one.
Could not find a package configuration file provided by "VTK" (requested
version 6.1) with any of the following names:
VTKConfig.cmake
vtk-config.cmake
I can't find the relevant files (VTKConfig.cmake or vtk-config.cmake) on the machine but do have VTKConfig.cmake.in (which also doesn't work).
Does anyone know where I can download the file from, or what I might be doing wrong.
It seems like you just have the VTK source code but haven't built it yet. VTKConfig.cmake.in is a template used by CMake to generate the VTKConfig.cmake file in the build and install directory. Look at http://www.vtk.org/Wiki/VTK/Building to see how to build VTK.
When you have successfully built VTK you can give CMake a hint where to look for VTK with the VTK_DIR-parameter:
cmake -DVTK_DIR=/path/to/vtk/build-directory /path/to/your/source-directory
If you have successfully built VTK, you would end up with a VTK-Release-build folder containing all the build files, one of which is VTKConfig.cmake. Your program is not able to find this file. You just need to set an environment variable named VTK_DIR before running your program. You can do so by running:
export VTK_DIR=/path/to/VTK-Release-build/
"FindVTK.cmake"the file of cmake is made in build directry.
please add this Path. export VTK_DIR=/path/VTK-Release-version/build

How to find the CMake command line I used for the build?

This is what typically happens. I get source code that has cmake build scripts. I create a build subdirectory, change to it, run cmake <options> ... Depending upon the project and its dependencies I have to repeat the last step until it finds all necessary dependencies and generates makefiles. I successfully build and use the project. Few days pass, I forget about this installation. Then one day I'm trying to setup the same project on another machine and now I can't recall what exact CMake command line I used in the past to get things working.
I still have the old build directory on the old machine. Can I find the cmake command line I used in the past, by looking into some of the autogenerated files in the build directory? I was expecting CMake would just put the exact command line I used in one of these files in commented form. But if it does so, I haven't found it yet.
How can I find the original CMake command line I used?
You can't.
Original CMake command can be guessed from analysis of CMakeCache.txt
As a workaround, you could always create a simple wrapper to store the original command line used. Something along these lines:
#!/bin/bash
echo "$#" > cmake_command.log
$#

linking 3rd party libraries

I have created a simple application that works ok. However, now I need to link with some libraries in the following directory.
/opt/norton/lib
In my make file I have the following with works, but I need to use cmake
LIBS_PATH = -L/opt/norton/lib
INC_PATH = -I/opt/norton/inc
LIBS = -lntctrl
In my CMakeList.txt I have this but doesn't work I keep gettng the following error:
undefined reference to `nt_init'
This is my CMakeList.txt
# Includes files
INCLUDE_DIRECTORIES(/opt/norton/inc)
# Link libraries
LINK_DIRECTORIES(/opt/norton/lib)
# Add the library that is used by nt_init
TARGET_LINK_LIBRARIES(-lntctrl)
ADD_LIBRARY(application initialize_nw)
Many thanks for any advice,
Try out TARGET_LINK_LIBRARIES(ntctrl), the -l flag should not be used there (guess from what I have in mind)
This is how I would write the cmake file:
include_directories(/opt/norton/inc)
link_directories(/opt/norton/lib)
add_executable(application initialize_nw)
target_link_libraries(application ntctrl)
To show what are the actual command lines run during a make, use:
make VERBOSE=1
Maybe this shows you the difference between what you ran manually and the cmake generated commands.