OK. I'm able to Configure and Generate successfully from CMake GUI and it appears to generate a bunch of files in my build folder. But it's not creating the Make file. Any ideas?
Edit:
All I did was create a workspace in Eclipse with a main project and a Static Library project. It's a simple HelloWorld application where the main project produces the "Hello" part of the output and the Static Library produces the "World" part of the output.
Does the CMake output give any error message? No. The only output from the CMake GUI is: Configuring done and Generating Done.
Is the correct generator selected? What settings are you using? I'm new to CMake, so I'm not entirely sure what you are asking but I can give you a screen capture:
The screen capture above shows the Eclipse project structure in the background and the CMake GUI with configuration in the foreground. The screen capture below shows the files that do get generated.
----------------------------------------------------- More Info -----------------------------------------------
I deleted all of my build folders and ran cmake again. This time I received the following output with errors:
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
World_INCLUDE_DIRS
used as include directory in directory /Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/Hello/src
World_LIBRARIES
linked by target "hello" in directory /Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/Hello/src
-- Configuring incomplete, errors occurred!
Here is the contents of my FindWorld.cmake file:
find_path(World_INCLUDE_DIRS World.h /usr/include "$ENV{WORLD_ROOT}/src")
find_library(World_LIBRARIES libWorld.a /usr/lib "$ENV{WORLD_ROOT}/Debug")
set(World_FOUND TRUE)
if (NOT World_INCLUDE_DIRS)
set(World_FOUND FALSE)
endif (NOT World_INCLUDE_DIRS)
if (NOT World_LIBRARIES)
set(World_FOUND FALSE)
endif (NOT World_LIBRARIES)
WORLD_ROOT is set in my Eclipse Hello project as an Environment Variable with the directory set to "/Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/World". Ah-ha! Could it be that CMake doesn't know what my Eclipse Environment Variables are?
Here is the contents of my Hello CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.6)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
find_package(World REQUIRED)
include_directories("${World_INCLUDE_DIRS}")
add_executable(hello Hello.cpp)
target_link_libraries(hello ${World_LIBRARIES})
Here is the contents of my World CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.6)
project(World)
include_directories("${CMAKE_SOURCE_DIR}")
add_library(namer World.cpp World.h)
Sure enough, it's not finding the paths to the World project. This is in my CMakeCache.txt file:
//Value Computed by CMake
Project_BINARY_DIR:STATIC=/Users/pdl/Development/Patricia's New World Sandbox/hello_world_build
//Value Computed by CMake
Project_SOURCE_DIR:STATIC=/Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/Hello/src
//Path to a file.
World_INCLUDE_DIRS:PATH=World_INCLUDE_DIRS-NOTFOUND
//Path to a library.
World_LIBRARIES:FILEPATH=World_LIBRARIES-NOTFOUND
My first problem was that I had accidentally ran make in a different build directory. I deleted all build directories and tried again. Then I received the following error:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
World_INCLUDE_DIRS
used as include directory in directory /Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/Hello/src
World_LIBRARIES
linked by target "hello" in directory /Users/pdl/Development/Patricia's New World Sandbox/HelloWorldCMake/Hello/src
-- Configuring incomplete, errors occurred!
Contemplating this error, it occurred to me that CMake, of course, is not aware of my Eclipse Environment Variables.
Related
I feel like this question has been asked a bunch of times, but none of the answers I have found seem to be working for me. I'm extremely new to CMake and C/C++ as I come from the world of Java, and am struggling to understand cmake and how it works.
Anyways, basically I have the folder structure below. This is an esp-idf project, so I don't know if that has anything to do with what I'm running into.
main
-CMakeLists.txt
-main.cpp
-wifi.cpp
Metriful
-CMakeLists.txt
-Metriful_sensor.cpp
-Metriful_sensor.h
-Wifi_functions.h
-Wifi_functions.cpp
CMakeLists.txt
Makefile
Now, all I want to do is include the Metriful subdirectory so I can use the functions provided by the "library". Right now my CMakeLists.txt in the root directory looks like this:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ESP_32_WROOM32_SENSOR_-_Metriful)
include_directories("Metriful")
This doesn't seem to work though as including "Metriful_sensor.h" in my main.cpp still fails:
cmake -G Ninja .. <
-- ccache will be used for faster recompilation
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file C:/Users/User/PlatformIO/ESP32_WROOM32_Sensor_-_Metriful/sdkconfig
-- Could NOT find Perl (missing: PERL_EXECUTABLE)
CMake Warning (dev) at C:/Users/User/esp/esp-idf/components/mbedtls/CMakeLists.txt:114 (target_sources):
Policy CMP0076 is not set: target_sources() command converts relative paths
to absolute. Run "cmake --help-policy CMP0076" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.
A private source from a directory other than that of target "mbedcrypto"
has a relative path.
This warning is for project developers. Use -Wno-dev to suppress it.
-- App "ESP_32_WROOM32_SENSOR_-_Metrifu" version: 637cfde-dirty
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld
-- Adding linker script C:/Users/User/PlatformIO/ESP32_WROOM32_Sensor_-_Metriful/build/esp-idf/esp32/esp32_out.ld
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp32/ld/esp32.project.ld.in
-- Adding linker script C:/Users/User/esp/esp-idf/components/esp32/ld/esp32.peripherals.ld
-- Components: app_trace app_update asio bootloader bootloader_support bt cbor cmock coap console cxx driver efuse esp-tls esp32 esp_adc_cal esp_common esp_eth esp_event esp_gdbstub esp_hid esp_http_client esp_http_server esp_https_ota esp_https_server esp_hw_support esp_ipc esp_local_ctrl esp_netif esp_pm esp_ringbuf esp_rom esp_serial_slave_link esp_system esp_timer esp_websocket_client esp_wifi espcoredump esptool_py expat fatfs freemodbus freertos hal heap idf_test jsmn json libsodium log lwip main mbedtls mdns mqtt newlib nghttp nvs_flash openssl partition_table perfmon protobuf-c protocomm pthread sdmmc soc spi_flash spiffs tcp_transport tcpip_adapter tinyusb ulp unity vfs wear_levelling wifi_provisioning wpa_supplicant xtensa
-- Component paths: C:/Users/User/esp/esp-idf/components/app_trace C:/Users/User/esp/esp-idf/components/app_update C:/Users/User/esp/esp-idf/components/asio C:/Users/User/esp/esp-idf/components/bootloader C:/Users/User/esp/esp-idf/components/bootloader_support C:/Users/User/esp/esp-idf/components/bt C:/Users/User/esp/esp-idf/components/cbor C:/Users/User/esp/esp-idf/components/cmock C:/Users/User/esp/esp-idf/components/coap C:/Users/User/esp/esp-idf/components/console C:/Users/User/esp/esp-idf/components/cxx C:/Users/User/esp/esp-idf/components/driver C:/Users/User/esp/esp-idf/components/efuse C:/Users/User/esp/esp-idf/components/esp-tls C:/Users/User/esp/esp-idf/components/esp32 C:/Users/User/esp/esp-idf/components/esp_adc_cal C:/Users/User/esp/esp-idf/components/esp_common C:/Users/User/esp/esp-idf/components/esp_eth C:/Users/User/esp/esp-idf/components/esp_event C:/Users/User/esp/esp-idf/components/esp_gdbstub C:/Users/User/esp/esp-idf/components/esp_hid C:/Users/User/esp/esp-idf/components/esp_http_client C:/Users/User/esp/esp-idf/components/esp_http_server C:/Users/User/esp/esp-idf/components/esp_https_ota C:/Users/User/esp/esp-idf/components/esp_https_server C:/Users/User/esp/esp-idf/components/esp_hw_support C:/Users/User/esp/esp-idf/components/esp_ipc C:/Users/User/esp/esp-idf/components/esp_local_ctrl C:/Users/User/esp/esp-idf/components/esp_netif C:/Users/User/esp/esp-idf/components/esp_pm C:/Users/User/esp/esp-idf/components/esp_ringbuf C:/Users/User/esp/esp-idf/components/esp_rom C:/Users/User/esp/esp-idf/components/esp_serial_slave_link C:/Users/User/esp/esp-idf/components/esp_system C:/Users/User/esp/esp-idf/components/esp_timer C:/Users/User/esp/esp-idf/components/esp_websocket_client C:/Users/User/esp/esp-idf/components/esp_wifi C:/Users/User/esp/esp-idf/components/espcoredump C:/Users/User/esp/esp-idf/components/esptool_py C:/Users/User/esp/esp-idf/components/expat C:/Users/User/esp/esp-idf/components/fatfs C:/Users/User/esp/esp-idf/components/freemodbus C:/Users/User/esp/esp-idf/components/freertos C:/Users/User/esp/esp-idf/components/hal C:/Users/User/esp/esp-idf/components/heap C:/Users/User/esp/esp-idf/components/idf_test C:/Users/User/esp/esp-idf/components/jsmn C:/Users/User/esp/esp-idf/components/json C:/Users/User/esp/esp-idf/components/libsodium C:/Users/User/esp/esp-idf/components/log C:/Users/User/esp/esp-idf/components/lwip C:/Users/User/PlatformIO/ESP32_WROOM32_Sensor_-_Metriful/main C:/Users/User/esp/esp-idf/components/mbedtls C:/Users/User/esp/esp-idf/components/mdns C:/Users/User/esp/esp-idf/components/mqtt C:/Users/User/esp/esp-idf/components/newlib C:/Users/User/esp/esp-idf/components/nghttp C:/Users/User/esp/esp-idf/components/nvs_flash C:/Users/User/esp/esp-idf/components/openssl C:/Users/User/esp/esp-idf/components/partition_table C:/Users/User/esp/esp-idf/components/perfmon C:/Users/User/esp/esp-idf/components/protobuf-c
C:/Users/User/esp/esp-idf/components/protocomm C:/Users/User/esp/esp-idf/components/pthread C:/Users/User/esp/esp-idf/components/sdmmc C:/Users/User/esp/esp-idf/components/soc C:/Users/User/esp/esp-idf/components/spi_flash C:/Users/User/esp/esp-idf/components/spiffs C:/Users/User/esp/esp-idf/components/tcp_transport C:/Users/User/esp/esp-idf/components/tcpip_adapter C:/Users/User/esp/esp-idf/components/tinyusb C:/Users/User/esp/esp-idf/components/ulp C:/Users/User/esp/esp-idf/components/unity C:/Users/User/esp/esp-idf/components/vfs C:/Users/User/esp/esp-idf/components/wear_levelling C:/Users/User/esp/esp-idf/components/wifi_provisioning C:/Users/User/esp/esp-idf/components/wpa_supplicant C:/Users/User/esp/esp-idf/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/User/PlatformIO/ESP32_WROOM32_Sensor_-_Metriful/build
Terminal will be reused by tasks, press any key to close it.
> Executing task: cmake --build . <
[1/9] Performing build step for 'bootloader'
ninja: no work to do.
[2/7] Building CXX object esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj
ccache C:\Users\User\.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -I../main -IC:/Users/User/esp/esp-idf/components/newlib/platform_include -IC:/Users/User/esp/esp-idf/components/freertos/include -IC:/Users/User/esp/esp-idf/components/freertos/port/xtensa/include -IC:/Users/User/esp/esp-idf/components/esp_hw_support/include -IC:/Users/User/esp/esp-idf/components/esp_hw_support/port/esp32/. -IC:/Users/User/esp/esp-idf/components/heap/include -IC:/Users/User/esp/esp-idf/components/log/include -IC:/Users/User/esp/esp-idf/components/lwip/include/apps -IC:/Users/User/esp/esp-idf/components/lwip/include/apps/sntp -IC:/Users/User/esp/esp-idf/components/lwip/lwip/src/include -IC:/Users/User/esp/esp-idf/components/lwip/port/esp32/include -IC:/Users/User/esp/esp-idf/components/lwip/port/esp32/include/arch -IC:/Users/User/esp/esp-idf/components/soc/include -IC:/Users/User/esp/esp-idf/components/soc/esp32/. -IC:/Users/User/esp/esp-idf/components/soc/esp32/include -IC:/Users/User/esp/esp-idf/components/hal/esp32/include -IC:/Users/User/esp/esp-idf/components/hal/include -IC:/Users/User/esp/esp-idf/components/esp_rom/include -IC:/Users/User/esp/esp-idf/components/esp_rom/esp32 -IC:/Users/User/esp/esp-idf/components/esp_common/include -IC:/Users/User/esp/esp-idf/components/esp_system/include -IC:/Users/User/esp/esp-idf/components/esp32/include -IC:/Users/User/esp/esp-idf/components/driver/include -IC:/Users/User/esp/esp-idf/components/driver/esp32/include -IC:/Users/User/esp/esp-idf/components/esp_ringbuf/include -IC:/Users/User/esp/esp-idf/components/efuse/include -IC:/Users/User/esp/esp-idf/components/efuse/esp32/include -IC:/Users/User/esp/esp-idf/components/xtensa/include -IC:/Users/User/esp/esp-idf/components/xtensa/esp32/include -IC:/Users/User/esp/esp-idf/components/espcoredump/include -IC:/Users/User/esp/esp-idf/components/esp_timer/include -IC:/Users/User/esp/esp-idf/components/esp_ipc/include -IC:/Users/User/esp/esp-idf/components/esp_pm/include -IC:/Users/User/esp/esp-idf/components/vfs/include -IC:/Users/User/esp/esp-idf/components/esp_wifi/include -IC:/Users/User/esp/esp-idf/components/esp_wifi/esp32/include -IC:/Users/User/esp/esp-idf/components/esp_event/include -IC:/Users/User/esp/esp-idf/components/esp_netif/include -IC:/Users/User/esp/esp-idf/components/esp_eth/include -IC:/Users/User/esp/esp-idf/components/tcpip_adapter/include -IC:/Users/User/esp/esp-idf/components/app_trace/include -IC:/Users/User/esp/esp-idf/components/mbedtls/port/include -IC:/Users/User/esp/esp-idf/components/mbedtls/mbedtls/include -IC:/Users/User/esp/esp-idf/components/mbedtls/esp_crt_bundle/include -IC:/Users/User/esp/esp-idf/components/app_update/include -IC:/Users/User/esp/esp-idf/components/spi_flash/include -IC:/Users/User/esp/esp-idf/components/bootloader_support/include -IC:/Users/User/esp/esp-idf/components/nvs_flash/include -IC:/Users/User/esp/esp-idf/components/pthread/include -IC:/Users/User/esp/esp-idf/components/esp_gdbstub/include -IC:/Users/User/esp/esp-idf/components/esp_gdbstub/xtensa -IC:/Users/User/esp/esp-idf/components/esp_gdbstub/esp32 -IC:/Users/User/esp/esp-idf/components/wpa_supplicant/include -IC:/Users/User/esp/esp-idf/components/wpa_supplicant/port/include -IC:/Users/User/esp/esp-idf/components/wpa_supplicant/include/esp_supplicant -IC:/Users/User/esp/esp-idf/components/perfmon/include -IC:/Users/User/esp/esp-idf/components/asio/asio/asio/include -IC:/Users/User/esp/esp-idf/components/asio/port/include -IC:/Users/User/esp/esp-idf/components/cbor/port/include -IC:/Users/User/esp/esp-idf/components/unity/include -IC:/Users/User/esp/esp-idf/components/unity/unity/src -IC:/Users/User/esp/esp-idf/components/cmock/CMock/src -IC:/Users/User/esp/esp-idf/components/coap/port/include -IC:/Users/User/esp/esp-idf/components/coap/port/include/coap -IC:/Users/User/esp/esp-idf/components/coap/libcoap/include -IC:/Users/User/esp/esp-idf/components/coap/libcoap/include/coap2 -IC:/Users/User/esp/esp-idf/components/console -IC:/Users/User/esp/esp-idf/components/nghttp/port/include -IC:/Users/User/esp/esp-idf/components/nghttp/nghttp2/lib/includes -IC:/Users/User/esp/esp-idf/components/esp-tls -IC:/Users/User/esp/esp-idf/components/esp-tls/esp-tls-crypto -IC:/Users/User/esp/esp-idf/components/esp_adc_cal/include -IC:/Users/User/esp/esp-idf/components/esp_hid/include -IC:/Users/User/esp/esp-idf/components/tcp_transport/include -IC:/Users/User/esp/esp-idf/components/esp_http_client/include -IC:/Users/User/esp/esp-idf/components/esp_http_server/include -IC:/Users/User/esp/esp-idf/components/esp_https_ota/include -IC:/Users/User/esp/esp-idf/components/protobuf-c/protobuf-c -IC:/Users/User/esp/esp-idf/components/protocomm/include/common -IC:/Users/User/esp/esp-idf/components/protocomm/include/security -IC:/Users/User/esp/esp-idf/components/protocomm/include/transports -IC:/Users/User/esp/esp-idf/components/mdns/include -IC:/Users/User/esp/esp-idf/components/esp_local_ctrl/include -IC:/Users/User/esp/esp-idf/components/sdmmc/include -IC:/Users/User/esp/esp-idf/components/esp_serial_slave_link/include -IC:/Users/User/esp/esp-idf/components/esp_websocket_client/include -IC:/Users/User/esp/esp-idf/components/expat/expat/expat/lib -IC:/Users/User/esp/esp-idf/components/expat/port/include -IC:/Users/User/esp/esp-idf/components/wear_levelling/include -IC:/Users/User/esp/esp-idf/components/fatfs/diskio -IC:/Users/User/esp/esp-idf/components/fatfs/vfs -IC:/Users/User/esp/esp-idf/components/fatfs/src -IC:/Users/User/esp/esp-idf/components/freemodbus/common/include -IC:/Users/User/esp/esp-idf/components/idf_test/include -IC:/Users/User/esp/esp-idf/components/idf_test/include/esp32 -IC:/Users/User/esp/esp-idf/components/jsmn/include -IC:/Users/User/esp/esp-idf/components/json/cJSON -IC:/Users/User/esp/esp-idf/components/libsodium/libsodium/src/libsodium/include -IC:/Users/User/esp/esp-idf/components/libsodium/port_include -IC:/Users/User/esp/esp-idf/components/mqtt/esp-mqtt/include -IC:/Users/User/esp/esp-idf/components/openssl/include -IC:/Users/User/esp/esp-idf/components/spiffs/include -IC:/Users/User/esp/esp-idf/components/ulp/include -IC:/Users/User/esp/esp-idf/components/wifi_provisioning/include -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -std=gnu++11
-fno-exceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.3-dirty\" -DESP_PLATFORM -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -c ../main/main.cpp
../main/main.cpp:3:10: fatal error: Metriful_sensor.h: No such file or directory
#include "Metriful_sensor.h"
^~~~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
You're likely to get a lot of answers from CMake users but ESP-IDF is different enough that a lot of answers aren't compatible between the two
IDF uses a component model built on top of CMake, so most normal include commands don't do anything
You want to look at idf_component_register
You probably want to register Metriful as a new component, and since it depends on Arduino you might need some extra steps.
If you want to keep your current directory structure, in your top
level CMake (the one with cmake_minimum_required at the top) add the line:
set(EXTRA_COMPONENT_DIRS "Metriful")
Otherwise make a folder named components next to your main folder and put Metriful inside that folder:
- main
main.cpp
your.h
- components
-Metriful
Metriful.cpp
Metriful.h
Register Metriful as an IDF-Component if it isn't already.
Check Metriful/CMakeList.txt for idf_component_register and if it doesn't contain it replace the contents with
idf_component_register(
SRCS "Metriful/MetrifulC.cpp" "Metriful/MetrifulA.cpp"
INCLUDE_DIRS "."
REQUIRES arduino
)
Note: You need to add each .cpp in Metriful manually to this file, same with your main as you add new files to it
Add Metriful as a requirement of your main.
In main/CMakeList.txt add a line to your idf_component_register
REQUIRES Metriful
Note the name Metriful will be case-sensitive and must match the folder name for Metriful
At this point everything will work if you already added Arduino to your ESP-IDF project. If you didn't follow these instructions: https://github.com/espressif/arduino-esp32/blob/master/docs/esp-idf_component.md
Also want to put this out there, Metriful seems to be an Arduino based library. If you're new to the ESP32, using ESP-IDF directly might be troublesome, since you'll likely be using a lot of Arduino based libraries.
The Arduino library works in ESP-IDF, but there are often incompatiblities that you need to work through when ESP-IDF updates.
Is there a specific reason you have for using ESP-IDF directly? Just remember Platform.IO lets you generate a compilation database, so you can use most coding environments if that's what you're after.
The ESP-IDF build system is built on top of CMake. This means you can use all the standard features of CMake in your files. However, the the ESP-IDF system predefines many functions, and makes many assumptions about the layout of your project, supposedly to make things "easier". Instead of reading CMake documentation, start by reading and understanding the ESP-IDF build system documentation:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html
It looks to me like there is a particular layout expected for subcomponents, including the format of the CMakeLists.txt file. Specifically, move Metriful under a new directory called components, or add Metriful to EXTRA_COMPONENT_DIRS near the top of your root CMakeLists.txt
If Metriful is not written as an esp-idf component, this may not work. However, the document also describes how to link to "pure CMake" components, which will look something like this (at the end of your root CMakeLists.txt).
# Create and import the library targets
add_subdirectory(Metriful)
# Publicly link `foo` to `main` component
target_link_libraries(main PUBLIC metriful)
The metriful argument in target_link_libraries must be the name of the library created in the subdirectory via add_library().
I am trying to integrate the Clang-Tidy static analysis tool into my build system.
I am getting a few issues with my setup.
Step cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. is not generating compile_commands.json file.
Hence, clang-tidy is giving below error.
>cmake --build . result
Could not auto-detect compilation database from directory "C:/dev/my-project/build/compile_commands.json"
No compilation database found in C:\dev\my-project\build\compile_commands.json or any parent directory
fixed-compilation-database: Error while opening fixed database: no such file or directory
json-compilation-database: Error while opening JSON database: no such file or directory
Running without flags.
Error while processing C:\dev\my-project\src\.
CUSTOMBUILD : error : unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error] [C:\dev\my-project\build\analyze_clang_tidy.vcxproj]
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
Clang-tidy.cmake file
set(CLANG_TIDY_CHECKS "-checks='${CLANG_TIDY_CHECKS}'")
add_custom_target(analyze_clang_tidy ALL
COMMAND ${CLANG_TIDY}
-p ${CMAKE_BINARY_DIR}/compile_commands.json
${CLANG_TIDY_CHECKS}
-header-filter='.*'
${CMAKE_CURRENT_SOURCE_DIR}/src/
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Static code analysis with Clang-Tidy"
)
Please also find the configuration result
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Default build type: Debug
iD MSVC
-- ccache found and enabled
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev/my-project/build
I have a simple hello world int main() {...} in my ../src/ folder.
Please suggest to me how to generate the compile_commands.json file using CMake with VS code on windows.
Thank you!
See https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
Specifically this Note:
Note This option is implemented only by Makefile Generators and the Ninja. It is ignored on other generators.
Instead, you could write a python script which would generate that format for you, similar to this tool: https://github.com/nickdiego/compiledb
Or, actually, you don't need compile_commands.json. You can define CMAKE_<LANG>_CLANG_TIDY variable to trigger clang-tidy automatically: https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html
See how I did this for my project 1 2 3
Recently I start to learn about machine learning and download a library that work with it: GEGELATI for C++, in Visual Studio. Link to the library: https://github.com/gegelati/gegelati. I also download the example "stick-game" from the same page. I follow all the points to build the library and the example, but it throw an error: "can't find gegelati.h". When I saw that, I remember the advice the "cmake .." command gave me when I build the library in the project:
*CMake Warning at CMakeLists.txt:68 (find_package):
By not providing "FindGEGELATI.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "GEGELATI",
but CMake did not find one.
Could not find a package configuration file provided by "GEGELATI" with any
of the following names:
GEGELATIConfig.cmake
gegelati-config.cmake
Add the installation prefix of "GEGELATI" to CMAKE_PREFIX_PATH or set
"GEGELATI_DIR" to a directory containing one of the above files. If
"GEGELATI" provides a separate development package or SDK, be sure it has
been installed.*
If you need to know, this is the code in my CMakeList.txt: https://drive.google.com/file/d/1hDkC6coCWaQNb1Cv1QzrJbUMucjYE68y/view?usp=sharing
To solve the problem, I decided to copy the gegelati.h and GEGELATIConfig.cmake files (from the folder where I installed gegelati), but when I tried to compile again, the error E1696 showed up; it can't open gegelati.h.
Finally, I tried to put the gegelati files directly in the "stick-game/lib/gegelatilib" folder and
include its path in the "AdditionalIncludeDirectories". I put an image about this (sorry, it is in Spanish):
The new program output throw me 19 'LNK2019' errors and 8 'LNK2001' errors. Example of two:
Error LNK2019 símbolo externo "public: unsigned int __thiscall Instructions::Set::getNbInstructions(void)const " (?getNbInstructions#Set#Instructions##QBEIXZ) sin resolver al que se hace referencia en la función _main
Error LNK2001 símbolo externo "public: virtual class Learn::LearningEnvironment * __thiscall Learn::LearningEnvironment::clone(void)const " (?clone#LearningEnvironment#Learn##UBEPAV12#XZ) sin resolver
Also, at the beginning, when I install doxygen for use gegelati, it throws some errors:
*Checking Build System
Generating doxygen documentation in C:/Users/Acel Guilts/gegelati/bin/doc
CUSTOMBUILD : warning : tag INPUT: input source 'C:/Users/Acel' does not exist [C:\Users\Acel Guilts\gegelati\bin\doc\d
oc.vcxproj]
CUSTOMBUILD : warning : tag INPUT: input source 'Guilts/gegelati/gegelatilib' does not exist [C:\Users\Acel Guilts\gege
lati\bin\doc\doc.vcxproj]
CUSTOMBUILD : warning : tag INPUT: input source 'C:/Users/Acel' does not exist [C:\Users\Acel Guilts\gegelati\bin\doc\d
oc.vcxproj]
CUSTOMBUILD : warning : tag INPUT: input source 'Guilts/gegelati/doc' does not exist [C:\Users\Acel Guilts\gegelati\bin
\doc\doc.vcxproj]
CUSTOMBUILD : error : source C:/Users/Acel is not a readable file or directory... skipping. [C:\Users\Acel Guilts\gegel
ati\bin\doc\doc.vcxproj]
CUSTOMBUILD : error : source Guilts/gegelati/gegelatilib is not a readable file or directory... skipping. [C:\Users\Ace
l Guilts\gegelati\bin\doc\doc.vcxproj]
CUSTOMBUILD : error : source C:/Users/Acel is not a readable file or directory... skipping. [C:\Users\Acel Guilts\gegel
ati\bin\doc\doc.vcxproj]
CUSTOMBUILD : error : source Guilts/gegelati/doc is not a readable file or directory... skipping. [C:\Users\Acel Guilts
\gegelati\bin\doc\doc.vcxproj]*
Do you have any idea about how to solve the problem?
The installation process of GEGELATI for the latest version of Microsoft Visual Studio on Windows (x64) can be done with the following steps:
Download the application of your choice from the GEGELATI-APPS repository (or any other application built with the library).
Download the latest binary of the GEGELATI library from here. Make sure to select the gegelatilib-x.y.z.zip at the bottom of the page.
Unzip the content of gegelatilib-x.y.z.zip into the lib folder of your application. For example, for the stick-game application, the folder will be stick-game/lib/gegelatilib-0.2.1, and it should contain the following subfolders: bin, CMake, doc, include, lib.
Open a terminal in the stick-game/bin folder, and simply type:
cmake ..
This should produce the following output:
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 6.1.7601.
-- The C compiler identification is MSVC 19.26.28806.0
-- The CXX compiler identification is MSVC 19.26.28806.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Copy GEGELATI DLLs into <YOUR_PATH>/stick-game/bin
-- Configuring done
-- Generating done
-- Build files have been written to: <YOUR_PATH>/stick-game/bin
Now you can open the project by opening the stick-game/bin/stick-game.sln solution. To launch the application from Visual Studio, right-click on the stick-game project in the Solution Explorer and select Set as Startup Project.
Alternatively
Still in the terminal, from the bin directory:
cmake --build . --target stick-game --config Release
Then
.\Release\stick-game.exe
Best,
Karol
Download GEGELATI here and generate it Cmake solution
Download stick-game Project here and generate it Cmake solution
Add path of gegelati.h to Additional include directories. In my case G:\CMake\Sources\gegelati-master\gegelatilib\include\ (a better solution is to use relative path with ../../.. but it is not our problem)
Check that you edit for current configuration (see red arrow)
Find path of the generated GEGELATI libraries, in my case : G:\CMake\Build\gegelati\lib\Debug
6. Add this path (G:\CMake\Build\gegelati\lib\Debug) to Additional library Directories
Add gtestd.lib and GEGELATId.lib in input:
It should be good now!
I have a small library that I have made (mostly wrappers for a more obtuse library underneath) which I have been compiling and using no problem in a contained project. I am now using this library in another project and have attempted to change the CMakeLists.txt appropriately (see below).
cmake_minimum_required (VERSION 3.5)
set(project "foobar")
project(${project} LANGUAGES CXX)
set(${project}_VERSION_MAJOR 0)
set(${project}_VERSION_MINOR 1)
add_library(${project} SHARED
./driver/foo.h
./driver/foo.c
./bar.cpp
./bar.hpp)
set_source_files_properties(./driver/foo.c PROPERTIES LANGUAGE CXX)
target_compile_features(${project}
PUBLIC
cxx_std_11)
target_include_directories(${project} PUBLIC ./driver/ .)
set_target_properties(${project} PROPERTIES LINKER_LANGUAGE CXX)
add_executable(bno055-test
./testingProject.cpp
)
target_link_libraries(test ${project})
install(
TARGETS ${project}
RUNTIME DESTINATION bin)
The error I have encountered is with the line set_source_files_properties(./driver/foo.c PROPERTIES LANGUAGE CXX). When it comes to compiling this C file with the C++ flag above I get many warnings of the type clang-8: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]. This is expected, as I am using deprecated methods and should not be compiling this file using the C++ flag. However, whenever I remove this line, or alter it to specify C instead of C++, my entire project no longer builds and fails with error:
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_C_COMPILE_OBJECT
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
Makefile:283: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
"/usr/bin/make -j4 all" terminated with exit code 2. Build might be incomplete.
I'm not familiar enough with CMake to see why this line of code and error are related like this. Is there some alternative piece of code I should include to create the missing variable CMAKE_C_COMPILE_OBJECT?
I assume that when I initially created this project using Eclipse this line was automatically generated and I am unclear as to why it now creates a problem when I had been compiling these files with the same CMakeLists.txt before (without library linking).
This is with clang#8.0.0 on Ubuntu 16.04.
Any help would be much appreciated! Apologies if I have missed something simple!
Is there some alternative piece of code I should include to create the missing variable CMAKE_C_COMPILE_OBJECT?
No, as the CMake error states, this is an "internal CMake variable" which should be initialized by CMake. It is not something you should have to set yourself. It should be set indirectly when you call project(). However, you only tell CMake you are using C++ (with CXX option) in the project() command. If you want CMake to make use of C and C++, you need to add both:
project(${project} LANGUAGES C CXX)
Even better, CMake enables C and C++ by default, so you can simply do:
project(${project})
Windows 64bit using cmake to compile c++ project: github.com/iHateInventNames/synergy-through-usb
I fixed a previous issue in this post: Compile issues: LIBUSB_1 with cmake project on Windows
So when I hit cmake now I get the following error:
> cmake .
-- Found libusb-1.0:
-- - Includes: C:/local/libs/libusbx
-- - Libraries: C:/local/libs/libusbx/libusb-1.0.lib
You have called ADD_LIBRARY for library cryptopp without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
-- Generating done
-- Build files have been written to: C:/local/projects/synergy-usb/synergy-through-usb-master
What does this mean? how can I solve it / move on?
Links to the install instructions
both goto 404 errors...
http://synergy-project.org/projects/synergy/wiki/Readme/?hl=pm
http://synergy-project.org/projects/synergy/wiki/Compiling/?hl=pm
Based on a quick browse through the project's CMakeLists, it would seem you're supposed to unpack tools/cryptopp562.zip into a directory called tools/cryptopp562 before running CMake. This should definitely have been mentioned in the projects' installation instructions, if any.
More precisely, the file tools/CMakeLists.txt contains this code:
set(cpp_dir cryptopp562)
file(GLOB cpp_src ${cpp_dir}/*.cpp)
# ...
add_library(cryptopp STATIC ${cpp_src})
This means that the variable cpp_src is filled with source files taken from directory cryptopp562 (relative to the CMakeList's directory, i.e. tools), and is then used to define the source files of library cryptopp. However, the project's distribution only contains tools/cryptopp562.zip. Unpacking that into directory tools/cryptopp562 should provide the missing files.