After building and installing the library with CMake, I find CMake package files to use in lib/cmake/snmp++/snmp++*.cmake.
In my executable’s CMake project I discover the library with:
find_package(snmp++ REQUIRED PATHS "${DEPENDENCY_DIR}/snmp++/lib/cmake/snmp++")
# XXX hack to set the include directory
set_target_properties(snmp++::snmp++_static PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${DEPENDENCY_DIR}/snmp++/include" # not set in package >:(
)
mind the additional hack above needed to get the includes right for the subsequent dependency setup:
add_executable(my_executable
source/main.cpp
)
target_link_libraries(my_executable
agent++_static
snmp++::snmp++_static
)
First hint to the the issue is SNMP++'s installed CMake package lib/cmake/snmp++/snmp++Targets.cmake and lib/cmake/snmp++/snmp++Targets-debug.cmake which say:
# Create imported target snmp++::snmp++_static
add_library(snmp++::snmp++_static STATIC IMPORTED)
set_target_properties(snmp++::snmp++_static PROPERTIES
INTERFACE_LINK_LIBRARIES "/usr/lib/arm-linux-gnueabihf/libssl.so;/usr/lib/arm-linux-gnueabihf/libcrypto.so"
)
# Import target "snmp++::snmp++_static" for configuration "Debug"
set_property(TARGET snmp++::snmp++_static APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(snmp++::snmp++_static PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/libsnmp++_static.a"
)
Mind how no include directory for the library user is set (which is what my hack above did for my user project).
Root cause of the issue seems to be SNMP++'s CMakeLists.txt where no public include directory is set up for the library. It should list somehing like:
target_include_directories(snmp++::snmp++_static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
Which will then cause the CMake package install to include the corresponding part. Same for the dynamic library.