Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to enforce cmake performs "traget_link_libraries" after a library has been created

I want to write some executable code which depends on some third-party libraries and a self-define library(mylib), Is there any way to enforce the target_link_libraries performs after mylib has been created?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The target doesn’t have to exist to link with it. Just target_link_libraries(... mylib) from the start, and define target mylib later.

When you forget about defining mylib target, you will get -lmylib: could not find library message from the linker, or messages about missing headers when compiling (depending if the target exports some include paths).

Is there any way to enforce the target_link_libraries performs after mylib has been created?

Yes, you can overwrite add_library function with a custom handler that checks the name of the library and executes specific action on it. For example 'Overwrite' cmake command using a macro and restore its default behavior .

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading