Linking external libraries and interfaces with CMake
Posted: Tue Oct 19, 2021 7:36 pm
When using CMake to build a desktop programme, you can link in external libraries. For example, if I wanted to link in the jsoncpp library on linux (libjsoncpp-dev), my root CMakeLists.txt might look like:
With building using the IDF (I am on 4v3), we don't have the add_executable(...) command in our project, but I can see it in the project.cmake file in the IDF tools. https://github.com/espressif/esp-idf/bl ... cmake#L443
What would be the proper way to include & link external libraries into an IDF project?
Using jsoncpp as an example here which is a full library but I also want to use the GSL from Microsoft which is a header only interface.
When I say the "proper" way, I mean the CMake way. So that I can have a `libraries` directory in my project, with `git submodules` of all the libraries I want. As opposed to just copy and pasting source and header files from a library into my project, which is not as maintainable nor as elegant for open source projects.
Ref
jsoncpp: https://github.com/open-source-parsers/jsoncpp
GSL: https://github.com/microsoft/GSL
- project(myprogram)
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(JSONCPP jsoncpp)
- link_libraries(${JSONCPP_LIBRARIES})
- add_executable(myprogram myprogram.cpp)
- target_link_libraries(myprogram ${JSONCPP_LIBRARIES}) # this must come after add_executable(...)
With building using the IDF (I am on 4v3), we don't have the add_executable(...) command in our project, but I can see it in the project.cmake file in the IDF tools. https://github.com/espressif/esp-idf/bl ... cmake#L443
What would be the proper way to include & link external libraries into an IDF project?
Using jsoncpp as an example here which is a full library but I also want to use the GSL from Microsoft which is a header only interface.
When I say the "proper" way, I mean the CMake way. So that I can have a `libraries` directory in my project, with `git submodules` of all the libraries I want. As opposed to just copy and pasting source and header files from a library into my project, which is not as maintainable nor as elegant for open source projects.
Ref
jsoncpp: https://github.com/open-source-parsers/jsoncpp
GSL: https://github.com/microsoft/GSL