What is CMake equivalent for a prebuilt third-party library?
What is CMake equivalent for a prebuilt third-party library?
I am porting a make-based project to build using Cmake because I have updated to v4.x IDF. I know this may not be required, but Cmake seems to be favored by Espressif now. I have a third-party library (for a Bosch environmenal sensor).
The current make component.mk file has just this one line:
COMPONENT_ADD_LDFLAGS=$(COMPONENT_PATH)/libalgobsec.a
I am very new to Cmake and don't have a good idea what the equivalent should be in the CMakeLists.txt file.
Can someone tell me the syntax to use in my CMakeLists.txt file? Or at least what keywords I should be looking at?
Thanks!
The current make component.mk file has just this one line:
COMPONENT_ADD_LDFLAGS=$(COMPONENT_PATH)/libalgobsec.a
I am very new to Cmake and don't have a good idea what the equivalent should be in the CMakeLists.txt file.
Can someone tell me the syntax to use in my CMakeLists.txt file? Or at least what keywords I should be looking at?
Thanks!
Re: What is CMake equivalent for a prebuilt third-party library?
Hi jsam589,
You can do something like this in the component CMakeLists.txt file:
EDIT: Changed COMPONENT_TARGET to COMPONENT_LIB.
The first line adds the component directory (which contains the binary library) to the linker search path, and the second line will populate the linker command line with "-lalgobsec".
If "libalgobsec" depends on some other libraries, add these after "algobsec" on the second invocation of "target_link_libraries".
Angus
You can do something like this in the component CMakeLists.txt file:
Code: Select all
target_link_libraries(${COMPONENT_LIB} "-L ${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${COMPONENT_LIB} algobsec)
The first line adds the component directory (which contains the binary library) to the linker search path, and the second line will populate the linker command line with "-lalgobsec".
If "libalgobsec" depends on some other libraries, add these after "algobsec" on the second invocation of "target_link_libraries".
Angus
Re: What is CMake equivalent for a prebuilt third-party library?
I tried pasting those two lines in verbatim, but then the build failed and said this command is not scriptable.
Could there be a different version of the command, or something that would go inside idf_component_register(...) which would be allowed?
Thanks!
CMake Error at /home/jsam/ESP40/idf_40b1_z/esp-idf/tools/cmake/component.cmake:225 (message):
CMake Error at
/home/jsam/Inspect2nd/CompSnd2/components/bme_bsec_lib/CMakeLists.txt:3
(target_link_libraries):
target_link_libraries command is not scriptable
Call Stack (most recent call first):
Could there be a different version of the command, or something that would go inside idf_component_register(...) which would be allowed?
Thanks!
CMake Error at /home/jsam/ESP40/idf_40b1_z/esp-idf/tools/cmake/component.cmake:225 (message):
CMake Error at
/home/jsam/Inspect2nd/CompSnd2/components/bme_bsec_lib/CMakeLists.txt:3
(target_link_libraries):
target_link_libraries command is not scriptable
Call Stack (most recent call first):
Re: What is CMake equivalent for a prebuilt third-party library?
Hi jsam,
Very sorry, I used the wrong variable name. Have edited the post.
This is cribbed from the esp_wifi component, which has to do the same thing (but in a more complex way):
https://github.com/espressif/esp-idf/bl ... ts.txt#L20
The PUBLIC keyword shown in the link is unnecessary in your case, I think. Also, make sure these two lines are placed after idf_component_register().
If it still doesn't work, could you please post the full CMakeLists.txt file you're using, and confirm the exact IDF version?
Very sorry, I used the wrong variable name. Have edited the post.
This is cribbed from the esp_wifi component, which has to do the same thing (but in a more complex way):
https://github.com/espressif/esp-idf/bl ... ts.txt#L20
The PUBLIC keyword shown in the link is unnecessary in your case, I think. Also, make sure these two lines are placed after idf_component_register().
If it still doesn't work, could you please post the full CMakeLists.txt file you're using, and confirm the exact IDF version?
Re: What is CMake equivalent for a prebuilt third-party library?
I tried update the CMakeLists.txt file but still getting errors, although slightly different now. It may be that this is totally not the correct way to handle a third-party pre-built library, but this is how we have been successfully doing it with 'make' and v3.x IDF.
My current IDF is v4.0-beta1, which obtained with "git clone -b v4.0-beta1 --recursive"
The 3 lines below are exactly what I currently am putting in the CMakeLists.txt. The component directory is named components/bme_bsec_lib/ and contains only library file libalgobsec.a and CMakeLists.txt.
idf_component_register()
target_link_libraries(${COMPONENT_LIB} "-L ${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${COMPONENT_LIB} algobsec)
Today's errors are:
CMake Error at components/bme_bsec_lib/CMakeLists.txt:2 (target_link_libraries):
INTERFACE library can only be used with the INTERFACE keyword of
target_link_libraries
CMake Error at components/bme_bsec_lib/CMakeLists.txt:3 (target_link_libraries):
INTERFACE library can only be used with the INTERFACE keyword of
target_link_libraries
My current IDF is v4.0-beta1, which obtained with "git clone -b v4.0-beta1 --recursive"
The 3 lines below are exactly what I currently am putting in the CMakeLists.txt. The component directory is named components/bme_bsec_lib/ and contains only library file libalgobsec.a and CMakeLists.txt.
idf_component_register()
target_link_libraries(${COMPONENT_LIB} "-L ${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${COMPONENT_LIB} algobsec)
Today's errors are:
CMake Error at components/bme_bsec_lib/CMakeLists.txt:2 (target_link_libraries):
INTERFACE library can only be used with the INTERFACE keyword of
target_link_libraries
CMake Error at components/bme_bsec_lib/CMakeLists.txt:3 (target_link_libraries):
INTERFACE library can only be used with the INTERFACE keyword of
target_link_libraries
Re: What is CMake equivalent for a prebuilt third-party library?
Hi jsam589,
Sorry, I should have asked for the full details about the component before replying.
The root cause of this error is that the component doesn't have any source files (no "idf_register_component(SRCS ...)"). CMake calls this as an "interface" library target rather than a regular library target. We try to smooth over this distinction on the IDF side but when using CMake commands like target_link_libraries() then it needs to be followed.
Try this:
You may need to explicitly tell CMake that algobsec depends on libc, libm, libgcc (assuming it calls some libc functions):
Similarly if the library has dependencies on other libraries in the build, you may need to add these as well.
Angus
Sorry, I should have asked for the full details about the component before replying.
The root cause of this error is that the component doesn't have any source files (no "idf_register_component(SRCS ...)"). CMake calls this as an "interface" library target rather than a regular library target. We try to smooth over this distinction on the IDF side but when using CMake commands like target_link_libraries() then it needs to be followed.
Try this:
Code: Select all
idf_component_register()
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${COMPONENT_LIB} INTERFACE algobsec)
Code: Select all
idf_component_register()
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L ${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(${COMPONENT_LIB} INTERFACE algobsec c m gcc)
Angus
Re: What is CMake equivalent for a prebuilt third-party library?
It is building successfully now! Thanks for your efforts to find the correct syntax!
Re: What is CMake equivalent for a prebuilt third-party library?
I need a little more understanding of what is happening here. When I use the three lines as shown (IDF v4.0-beta1 and cmake), I don't get any build errors. However, I don't see any evidence that anything actually happened with the library. Under IDF 3.3 and make, I get a new library created, libbme_bsec_lib.a, in the build output directory. Building with IDF v4.0-beta1, I get the folder build/esp-idf/bme_bsec_lib/, but it only has make and cmake files in it. No library files or even soft link back to original library. How can I be sure anything is being performed? Thanks.
Re: What is CMake equivalent for a prebuilt third-party library?
Hi buddy. I've been trying for three months. i don't get any results. Do you have any working examples?
https://esp32.com/viewtopic.php?f=13&t=12733
https://esp32.com/viewtopic.php?f=13&t=12733
Re: What is CMake equivalent for a prebuilt third-party library?
Hi @pinock,
I did get success with mine. I will try to help you with your issue. Give me a day or so and I will try to replicate with your library and hello world example. Question: Which version of IDF are you using? I assume you are trying to use CMake and CMakeLists.txt, correct?
I did get success with mine. I will try to help you with your issue. Give me a day or so and I will try to replicate with your library and hello world example. Question: Which version of IDF are you using? I assume you are trying to use CMake and CMakeLists.txt, correct?
Who is online
Users browsing this forum: ok-home and 128 guests