1

I am working with CMake for my first time and have some understanding problems. Can anyone explain to me what the ERROR means, and why and how to fix it?

For my project, I downloaded the git-libraries "libubox-master" and "ubus-head" and put them into the folders "libubox" and "ubus" respectively in my project directory. Those libraries already have different CMakeList.txt files. In my project directory, I created the files client.c, server.c, server.h and CMakeLists.txt on my own.

My folder structure:

project/
--------cmake-build-debug/ ...
--------libubox/ ... provided files and folders, including CMakeFiles
--------ubus/ ... provided files and folders, including CMakeFiles
--------client.c
--------CMakeLists.txt
--------server.c
--------server.h

My CMakeList.txt file looks like:

   cmake_minimum_required(VERSION 3.7)
   project (ubusDemo)

   add_subdirectory(libubox)
   add_subdirectory(ubus)

   add_executable(Client client.c)
   add_executable(Server server.c)

So it's just a simple file - did I forget something necessary?

The error message I got:

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:
blob_library
    linked by target "ubusd" in directory /home/matthias/Workspace/ubusDemo/ubus
    linked by target "cli" in directory /home/matthias/Workspace/ubusDemo/ubus
    linked by target "server" in directory /home/matthias/Workspace/ubusDemo/ubus/examples
ubox_include_dir
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/lua
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
   used as include directory in directory /home/matthias/Workspace/ubusDemo/ubus/examples
ubox_library
    linked by target "ubus" in directory /home/matthias/Workspace/ubusDemo/ubus
    linked by target "ubusd" in directory /home/matthias/Workspace/ubusDemo/ubus
    linked by target "cli" in directory /home/matthias/Workspace/ubusDemo/ubus
    linked by target "server" in directory /home/matthias/Workspace/ubusDemo/ubus/examples
    linked by target "client" in directory /home/matthias/Workspace/ubusDemo/ubus/examples

Where do I have to make changes? Just in my CMakeLists.txt file, or do I have to add some dependencies in the other CMakeLists.txt files?

And how can I use some header files from e.g. libubox like the blob.h in my client.c File? Is it correct to write #include <libubox/blob.h>?

Unfortunately, I haven't work with Makefiles (neither CMake nor Make) before. I hope, someone can help me.

Kevin
  • 16,549
  • 8
  • 60
  • 74
doerflia
  • 65
  • 2
  • 5
  • You have to set the variables `blob_library` `ubox_include_dir` and `ubox_library`. Then you should link the libraries to your targets. – Thomas Sablik Jul 22 '20 at 10:16
  • @Thomas Sablik: where do I have to set these variables? – doerflia Jul 22 '20 at 11:53
  • How do you configure your project? You can either run CMake and set the variables with `-D` or use `ccmake` or `cmake-gui`. You can edit the file `CMakeCache.txt`. You can also set them statically in your CMake file with `set`. – Thomas Sablik Jul 22 '20 at 12:36

1 Answers1

0

After searching for these unset variables in each of the external repositories, I found them here in the ubus CMake file:

IF(BUILD_STATIC)
  FIND_LIBRARY(ubox_library NAMES ubox.a)
  FIND_LIBRARY(blob_library NAMES blobmsg_json.a)
ELSE(BUILD_STATIC)
  FIND_LIBRARY(ubox_library NAMES ubox)
  FIND_LIBRARY(blob_library NAMES blobmsg_json)
ENDIF(BUILD_STATIC)

FIND_PATH(ubox_include_dir libubox/usock.h)
INCLUDE_DIRECTORIES(${ubox_include_dir})

This code in ubus is looking for the headers and built library files provided by the libubox package. It assumes that libubox is already installed on your machine, and that the searched components can be found in the standard system paths.

Using add_subdirectory() to include libubox in your CMake project will not build it soon enough; rather, libubox needs to be built and installed when you call add_subdirectory(ubus).

So, you will have to manually build and install the libubox package separately, before running your CMake project. Or, you can try to let CMake handle these steps within your project, with something like ExternalProject_Add() and execute_process, or FetchContent, as documented in some of the answers to this question. If you choose the latter, I encourage you to research each of these to determine which solution works best for your project.

Also, if just getting started with CMake, the CMake tag has a few useful CMake tutorials and resources.

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • So, In my case, ExternalProject_Add() seems like the best solution. – doerflia Jul 22 '20 at 13:23
  • @squaresskittles, it seems, the creation of the target structure in my build_dir/ and cmake-bild-debug/ directory for libubox is working correcty. In lib/ are some .a and .so files created. In include/libubox/ I found some .h files like expeacted either. But now, another error appears: in server.c and in client.c: fatal error: ubus/libubus.h: file or directory could not be found. Isn't #include correct? The headers of however could be found during the build-process. Excuse my English, I hope you understand what I mean. – doerflia Jul 22 '20 at 13:42