[question] How to use cmake interface library with target sources?
See original GitHub issueIn my CMakeLists.txt I create an interface library, add sources to it and then link it to an executable. When I try to consume it I get lots of undefined references. CMakeLists.txt example:
add_library(MyLib INTERFACE)
target_sources(MyLib INTERFACE util.cxx)
add_executable(SomeTarget main.cxx)
target_link_libraries(SomeTarget MyLib)
The project where I am creating the library and using it in the tests The conan recipe The project in which I try to use the library
I want conan to create a target like “MyLib” with the sources so I can link to it in the consuming project. I tried to use “self.cpp_info.srcdirs” but it did not work.
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to use 'target_sources' command with INTERFACE ...
I want to have a library containing all the code from src directory and an executable to run unit tests. After some research...
Read more >target_link_libraries — CMake 3.25.1 Documentation
Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated....
Read more >Enhanced source file handling with target_sources()
Taking a step back, what target_sources() is doing for us is to remove the need for variables by allowing us to use CMake...
Read more >Working with Targets - Modern CMake - GitHub Pages
Questions. How do targets work? Objectives. Know how to set up targets. Understand linking and INTERFACE properties. Make INTERFACE targets ...
Read more >target_sources(interface_lib INTERFACE $ ...
Currently there is no way to use interface libraries to affect the compilation of sources in an object library because CMake does not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @malachib
No, this didn’t get enough priority, so it was moved to 2.X (which means the backlog of new features to be addressed after 2.0 becomes generally available).
If you could elaborate a bit more what is your use case for doing pure sources target, instead of a compiled library, that would help for the future potential implementation and testing of this feature.
Hi @memsharded sure I would be happy to share.
The library estdlib supports a few embedded platforms, namely esp32/esp-idf , Raspberry Pi Pico and historically Arduino. These usually use gcc, but with wildly different versions. The library itself is designed for extremely high portability between MPUs and also includes a few platform-specific helpers, in particular FreeRTOS.
For esp-idf, it’s conceivable that compiling a static library on an older version of their GCC toolchain+SDK will be OK when linking against a newer GCC/LD, but that makes me nervous. More wise people than me probably could inform me one way or the other.
For Raspberry Pi Pico, INTERFACE is necessary because FreeRTOS may or may not be present - and if it is - additional include pathing supplied by the application must flow down into the library.
Finally, I’d like those with MPUs I haven’t vetted recently, or ever, to be able to nab the library and use it. Historically it worked great on AVR and Blackfin, but those toolchains I don’t even have installed now