[CMake] Using find_package() portably?

R0b0t1 r030t1 at gmail.com
Mon Dec 4 19:27:31 EST 2017


On Monday, December 4, 2017, Carsten Fuchs <carsten.fuchs at cafu.de> wrote:
> Thanks to all!
>
> Well, I guess I'm among the people mentioned by Lectem at
https://www.mail-archive.com/cmake-developers@cmake.org/msg18267.html
>
> I'll try to dig my way through it, but at this point I consider staying
with SCons under Linux, where finding packages is important and the command
line is used anyway, and using CMake under Windows only, where quasi all
external libraries are shipped along with the project and the real goal is
to obtain a Visual Studio solution. (I already have a complete build with
SCons that works under Windows and Linux for my project which is of average
complexity.)
>

Hello,

Are you able to link to your project? I am interested in how you have set
up your build system.

Cheers,
    R0b0t1

> Best regards,
> Carsten
>
> $ ls Cafu/ExtLibs/ -1
> bullet
> Cg
> fbx
> fmod
> freealut
> freetype
> glfw
> jpeg
> libogg
> libpng
> libvorbis
> lua
> lwo
> MersenneTwister.h
> minizip
> mpg123
> noise
> openal-soft
> openal-win
> pstdint.h
> tclap
> wxWidgets
> zlib
>
>
>
> Am 29.11.2017 um 21:17 schrieb Florent Castelli:
>>
>> On 29/11/2017 12:02, Johannes Zarl-Zierl wrote:
>>>
>>> Hello Carsten,
>>>
>>> On Samstag, 25. November 2017 11:46:44 CET Carsten Fuchs wrote:
>>>>
>>>> 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
???>)
>>>
>>> Well, that's one way, but that doesn't really provide any benefit above
the
>>> original solution (i.e. just define the JPEG_INCLUDES and JPEG_LIBRARIES
>>> variables accordingly).
>>>
>>>> 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,
>>>
>>> Either that or you define it yourself:
>>> find_package(JPEG)
>>> if (JPEG_FOUND)
>>
>> I'd say "if(JPEG_FOUND AND NOT TARGET JPEG::JPEG)"
>> If someone improves FindJPEG.cmake, you won't break your build.
>>
>>>   add_library(JPEG::JPEG UNKNOWN IMPORTED)
>>>   set_property(
>>>    TARGET JPEG::JPEG
>>>    PROPERTY IMPORTED_LOCATION ${JPEG_LIBRARIES}
>>>    )
>>>   set_property(
>>>    TARGET JPEG::JPEG PROPERTY
>>>    INTERFACE_INCLUDE_DIRECTORIES ${JPEG_INCLUDES}
>>>   )
>>> endif()
>>>
>>> I admit it's not a huge benefit over just using the variables. The
advantages:
>>> - you get slightly better error handling
>>> - your target_link_libraries commands are slightly more readable.
>>>
>>>>     - or write my `../ExtLibs/libjpeg/CMakeLists.txt` so that it
globally
>>>> defines JPEG_LIBRARIES and JPEG_INCLUDE_DIRS
>>>
>>> That will work, too.
>>>
>>>
>>> Cheers,
>>>    Johannes
>>>
>>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171204/0416037e/attachment.html>


More information about the CMake mailing list