0
$\begingroup$

Rosanswers logo

I am trying to create a library package which also includes header files to include from another package, but the other package is not able to find them. The CMakelist.txt from the library package looks like this:

cmake_minimum_required(VERSION 3.5)

project(device_engine)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

include_directories(
  include
)

ament_export_dependencies(rosidl_default_runtime)

add_library(device_engine
  src/action.cpp
  src/resource.cpp
  src/device_engine.cpp
  src/event_log_object.cpp
  src/log_handler.cpp
  src/log_handler_cout.cpp
)

ament_target_dependencies(device_engine)

install(TARGETS
  device_engine
  DESTINATION lib/${PROJECT_NAME}
  PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}/
  )

install(DIRECTORY include/${PROJECT_NAME}/
  DESTINATION include/${PROJECT_NAME}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".git" EXCLUDE)

ament_package()

The header files are copied correctly to install/device_engine/include/device_engine/ but it seems that the variable ${device_engine_INCLUDE_DIRS} is empty when calling find_package(device_engine) from the other package including the header files with the following CMakelists.txt:

cmake_minimum_required(VERSION 3.5)

project(mac_gateway)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(happtec_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(device_engine REQUIRED)

include_directories(
  include
  ${device_engine_INCLUDE_DIRS}
)

message(STATUS "Variables: ${device_engine_INCLUDE_DIRS}")

ament_export_dependencies(rosidl_default_runtime)

add_executable(mac_gateway
  src/resource_test_1.cpp
  src/main.cpp
)

target_link_libraries(mac_gateway device_engine)

ament_target_dependencies(mac_gateway device_engine rclcpp std_msgs std_srvs happtec_msgs)

install(TARGETS
  mac_gateway
  DESTINATION lib/${PROJECT_NAME})

ament_package()

The only error I get is that when compiling this, it is unable to find the header files. find_package(device_engine) does not produce any error.

What am I missing?


Originally posted by ahlyder on ROS Answers with karma: 65 on 2018-10-15

Post score: 2

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I think you need to tell ament about the header files. In the first CMake file, try adding ament_export_include_directories(include) before the line with ament_export_dependencies.


Originally posted by jacobperron with karma: 1870 on 2018-10-17

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by ahlyder on 2018-10-18:
You're right - thank you! That, and removing the from target_link_libraries(mac_gateway device_engine) from the package using the include files fixed the issue.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.