[CMake] Using find_package() portably?
Carsten Fuchs
carsten.fuchs at cafu.de
Sat Nov 25 05:46:44 EST 2017
Hello Johannes,
Am 2017-11-22 um 12:03 schrieb Johannes Zarl-Zierl:
> The problem in this specific case is that CMake ships with a FindJPEG module
> that does not define modern import libs, but uses the old way of defining
> <PACKAGE>_LIBRARIES and <PACKAGE>_INCLUDE_DIRS.
> IMO this highlights one of the main problems with find modules: nobody really
> maintains them.
>
> If JPEG had proper imported targets, your code could look like this:
> [...]
> You just have to make sure that your shipped libjpeg creates the proper
> namespaced target:
> add_library(JPEG ...)
> add_library(JPEG::JPEG ALIAS JPEG)
Thanks for your reply, but how can I proceed from here?
In order to be able to write in the parent script something that works
in either case, that is,
target_link_libraries(main_program <either JPEG::JPEG or ${JPEG...} or ???>)
it seems that I either
- have to make a copy of FindJPEG.cmake, customize it to define
target JPEG::JEPG and ship it along with my project,
- or write my `../ExtLibs/libjpeg/CMakeLists.txt` so that it globally
defines JPEG_LIBRARIES and JPEG_INCLUDE_DIRS
Is that right?
Best regards,
Carsten
More information about the CMake
mailing list