ESP-IDF Native Component #494
-
Does anyone have an idea or suggestions on how to integrate this library as a native idf component without using PlatformIO? I made a way for it to compile but I am not a CMake expert, thus while linking the main file there were some undefined references. First, I added the project as a submodule, then create a parent CMakeLists.txt kind of following the idf example: # Since we are wrapping the library inside a component,
# the component has to be registered first:
idf_component_register()
# To build a third-party library, ExternalProject CMake module can be used.
# ExternalProject offers many features which are impossible to demonstrate
# in a single example. Please refer to its documentation for more info:
# https://cmake.org/cmake/help/latest/module/ExternalProject.html
include(ExternalProject)
# Define the location where agisostack-plus-plus will be installed:
set(AGISOSTACK_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/agisostack-plus-plus_install)
# This function find the submodule in the project, calls CMake to configure it,
# builds the project and installs it to the specified location:
externalproject_add(agisostack-plus-plus_proj
# Find the source files in the project third party folder
SOURCE_DIR ${PROJECT_DIR}/src/third_party/AgIsoStack-plus-plus/AgIsoStack-plus-plus
# Specify arguments to be passed when running CMake for this subproject.
# Note that ExternalProject_Add also works with non-CMake projects, so this
# is just an example.
CMAKE_ARGS
# Use the same CMake toolchain file as for the main project.
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
# agisostack-plus-plus-specific settings: disable building everything except for the static library
-DBUILD_TESTING=FALSE
-DBUILD_EXAMPLES=FALSE
-DCAN_DRIVER="TWAI"
# Pass the install directory to the subproject.
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
# These options are set so that Ninja immediately outputs
# the subproject build to the terminal. Otherwise it looks like the
# build process "hangs" while the subproject is being built.
USES_TERMINAL_DOWNLOAD TRUE
USES_TERMINAL_CONFIGURE TRUE
USES_TERMINAL_BUILD TRUE
# Specify the installation directory for the subproject
INSTALL_DIR ${AGISOSTACK_INSTALL_DIR}
# Let CMake know that the library is generated by the subproject build step.
BUILD_BYPRODUCTS "${AGISOSTACK_INSTALL_DIR}/lib/libHardwareIntegration.a" "${AGISOSTACK_INSTALL_DIR}/lib/libIsobus.a" "${AGISOSTACK_INSTALL_DIR}/lib/libUtility.a"
)
# Now that the subproject build is set up, we need to consume the results
# of the build: the header file and the static library.
# To do this, define an imported CMake library:
add_prebuilt_library(agisostack-plus-plus_lib "${AGISOSTACK_INSTALL_DIR}/lib/libHardwareIntegration.a" "${AGISOSTACK_INSTALL_DIR}/lib/libIsobus.a" "${AGISOSTACK_INSTALL_DIR}/lib/libUtility.a"
PRIV_REQUIRES cxx)
target_include_directories(agisostack-plus-plus_lib INTERFACE "${AGISOSTACK_INSTALL_DIR}/include")
add_dependencies(agisostack-plus-plus_lib agisostack-plus-plus_proj)
# Link the imported library to the current component.
target_link_libraries(${COMPONENT_LIB} INTERFACE agisostack-plus-plus_lib) I can see the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For those having the same issues, the solution for now is to include the repository as a submodule and on the parent directory add the necessary files to the CMakeLists.txt using set(agisostack_priv_requires "cxx driver")
set(agisostack_include_dirs "AgIsoStack-plus-plus/hardware_integration/include" "AgIsoStack-plus-plus/isobus/include" "AgIsoStack-plus-plus/utility/include")
set(hardware_interface_sources "AgIsoStack-plus-plus/hardware_integration/src/can_hardware_interface.cpp"
"AgIsoStack-plus-plus/hardware_integration/src/mcp2515_can_interface.cpp"
"AgIsoStack-plus-plus/hardware_integration/src/spi_interface_esp.cpp"
"AgIsoStack-plus-plus/hardware_integration/src/spi_transaction_frame.cpp"
"AgIsoStack-plus-plus/hardware_integration/src/twai_plugin.cpp"
)
file(GLOB_RECURSE isobus_sources ${COMPONENT_DIR}/AgIsoStack-plus-plus/isobus/src/*.*)
file(GLOB_RECURSE utility_sources ${COMPONENT_DIR}/AgIsoStack-plus-plus/utility/src/*.*)
idf_component_register(SRCS ${hardware_interface_sources} ${isobus_sources} ${utility_sources}
INCLUDE_DIRS "${agisostack_include_dirs}"
PRIV_REQUIRES "${agisostack_priv_requires}"
) When using a driver different than the ESP TWAI, changes are needed in the |
Beta Was this translation helpful? Give feedback.
For those having the same issues, the solution for now is to include the repository as a submodule and on the parent directory add the necessary files to the CMakeLists.txt using
idf_component_register