Unit 2 - Example 2.8 - CMakeList: Order matters

Hello,

I noticed that the order in which the default CMakeList had been written was not suitable for this exercise. The default order was:

...
include_directories
add_dependencies
add_executable
target_link_libraries
...

What is important to note here is that the add_dependencies block is adding the object-file of our cpp file, which has not been created yet, and is created on the line add_executable. As a result, the compilation terminates with an output similar to the following:

-- ==> add_subdirectory(my_package)
CMake Error at my_package/CMakeLists.txt:129 (add_dependencies):
  Cannot add target-level dependencies to non-existent target "simple".

  The add_dependencies works for top-level logical targets created by the
  add_executable, add_library, or add_custom_target commands.  If you want to
  add file-level dependencies see the DEPENDS option of the add_custom_target
  and add_custom_command commands.


-- Configuring incomplete, errors occurred!
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/catkin_ws/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed

To resolve this, simply move the add_executableblock before the add_dependencies block, as was explicitly mentioned in In the Build section of your CMakeLists.txt file, add the following lines: section in the example.

This is only for your information.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.