ExternalProject_Add Component not linked with main application

turgu1
Posts: 5
Joined: Sat Feb 17, 2018 5:12 pm

ExternalProject_Add Component not linked with main application

Postby turgu1 » Sun Apr 19, 2020 2:51 am

Hello all, I'm new to that CMake system and I must say that I'm very puzzled with it. I have a very very simple application (the HelloWorld app) to which I added a component (named oberon) that build a library in the component folder (liboberon.a). When doing the build process (idf.py build) the component is built properly (the liboberon.a is generated) but it doesn't appears in the ld command to link the application. I modified the main.c source code to add a call to a member of the component library, but the linker fail.

Any Clue??

Thanks!

The component is located in the components/oberon folder.

The main CMakeLists.tx is as follow:

Code: Select all

cmake_minimum_required(VERSION 3.5.2)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(trials)
The CMakeLists.txt in the components/oberon folder is as follow:

Code: Select all

# External build process for oberon, runs in source dir and produces liboberon.a
idf_component_register()

ExternalProject_Add(oberon_build
    PREFIX ${COMPONENT_DIR}
    BINARY_DIR ${COMPONENT_DIR}
    TMP_DIR ${COMPONENT_DIR}/build/tmp
    STAMP_DIR ${COMPONENT_DIR}/build/stamp
    SOURCE_DIR ${COMPONENT_DIR}/src
    CONFIGURE_COMMAND ""
    BUILD_COMMAND make liboberon.a
    INSTALL_COMMAND ""
    )

 # Add liboberon.a to the build process
 add_library(oberon STATIC IMPORTED GLOBAL)
 add_dependencies(oberon oberon_build)
 set_target_properties(oberon PROPERTIES IMPORTED_LOCATION
      ${COMPONENT_DIR}/liboberon.a)
 set_directory_properties( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
      "${COMPONENT_DIR}/liboberon.a")

turgu1
Posts: 5
Joined: Sat Feb 17, 2018 5:12 pm

Re: ExternalProject_Add Component not linked with main application

Postby turgu1 » Sun Apr 19, 2020 9:06 pm

I've advanced a bit today on this problem. If I add the following line at the end of the component's CMakeLists.txt, I'm able to link only if the library is already available:

Code: Select all

target_link_libraries(${COMPONENT_LIB} INTERFACE oberon)
If I reinitialize everything and try to do a complete build, I get a complaint that the library doesn't exists. So the question is: What can I put in the component CMakeLists.txt such that the building process can build the component through the ExternalProject_Add AND be linked with the main application?

Thanks

Guy

turgu1
Posts: 5
Joined: Sat Feb 17, 2018 5:12 pm

SOLVED: Re: ExternalProject_Add Component not linked with main application

Postby turgu1 » Mon Apr 20, 2020 2:35 pm

Hello again,

The problem is solved. Not easy to find but it worked: I've added two parameters to the ExternelProject_Add: BUILD_BYPRODUCTS and BUILD_ALWAYS. The resulting CMakeLists.txt is as follow:

Code: Select all

# External build process for oberon, runs in source dir and produces liboberon.a
idf_component_register()

ExternalProject_Add(oberon_build
    PREFIX ${COMPONENT_DIR}
    BINARY_DIR ${COMPONENT_DIR}
    TMP_DIR ${COMPONENT_DIR}/build/tmp
    STAMP_DIR ${COMPONENT_DIR}/build/stamp
    SOURCE_DIR ${COMPONENT_DIR}/src
    BUILD_BYPRODUCTS ${COMPONENT_DIR}/liboberon.a
    BUILD_ALWAYS 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND make liboberon.a
    INSTALL_COMMAND ""
    )

# Add liboberon.a to the build process
 
add_library(oberon STATIC IMPORTED GLOBAL)
add_dependencies(oberon oberon_build)

set_target_properties(oberon PROPERTIES IMPORTED_LOCATION
     ${COMPONENT_DIR}/liboberon.a)

set_target_properties(oberon PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
     ${COMPONENT_DIR})

target_link_libraries(${COMPONENT_LIB} INTERFACE oberon)

set_directory_properties( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
     "${COMPONENT_DIR}/liboberon.a")
Cheers!

Guy

Who is online

Users browsing this forum: No registered users and 338 guests