I've been trying to add the following module mqtt_cpp to my project, but as always with cmake I struggle. This time I've tried lots of things suggested on similar problems here on stackoverflow but without success. I keep getting the same errors. Something seems to work as the mqtt_cpp lib searches my machine for the required boost version which I first had to install. What I have tried so far is adding some of the following lines (not all at once of course) to the CMakeLists.txt files on root level or the one in my lib folder where I have this library as a git submodule under ./lib/mqtt_cpp.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/mqtt_cpp)
add_library(mqtt_cpp_iface SHARED IMPORTED) # or STATIC instead of SHARED
set_target_properties(mqtt_cpp_iface PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/mqtt_cpp/include"
)
include_directories(${CMAKE_SOURCE_DIR}/lib/mqtt_cpp/include)
link_directories(${CMAKE_SOURCE_DIR}/mqtt_cpp)
The error I'm getting is the following:
CMake Error at CMakeLists.txt:37 (find_package):
By not providing "Findmqtt_cpp_iface.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"mqtt_cpp_iface", but CMake did not find one.
Could not find a package configuration file provided by "mqtt_cpp_iface"
with any of the following names:
mqtt_cpp_ifaceConfig.cmake
mqtt_cpp_iface-config.cmake
Add the installation prefix of "mqtt_cpp_iface" to CMAKE_PREFIX_PATH or set
"mqtt_cpp_iface_DIR" to a directory containing one of the above files. If
"mqtt_cpp_iface" provides a separate development package or SDK, be sure it
has been installed.
In the mqtt_cpp readme it is advised to have your CMakeLists.txt something like this which I have tried to replicate
set(LIBNAME "your_project_name")
add_library(${LIBNAME} <your dependencies here>)
find_package(mqtt_cpp_iface REQUIRED)
target_link_libraries(${LIBNAME} LINK_PUBLIC mqtt_cpp_iface::mqtt_cpp_iface)
My CMakeLists.txt files
./CMakeLists.txt:
# See https://cmake.org/examples/
cmake_minimum_required (VERSION 2.8.11)
project(neodisplay)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
add_subdirectory(lib)
add_subdirectory(src)
add_executable(NeoDisplay main.cpp)
target_link_libraries(NeoDisplay LINK_PUBLIC src)
target_link_libraries(NeoDisplay PRIVATE Threads::Threads)
target_link_libraries(NeoDisplay LINK_PUBLIC mqtt_cpp_iface::mqtt_cpp_iface)
find_package(rxcpp CONFIG)
find_package(mqtt_cpp_iface REQUIRED)
./lib/CMakeLists.txt
add_subdirectory(ws2812-rpi)
add_subdirectory(mqtt_cpp)