[CMake] Proper way to find system copy of libxml2 on macOS

Konstantin Tokarev annulen at yandex.ru
Wed Oct 12 12:04:57 EDT 2016



12.10.2016, 18:48, "Eric Noulard" <eric.noulard at gmail.com>:
> 2016-10-12 17:28 GMT+02:00 Konstantin Tokarev <annulen at yandex.ru>:
>> Hello,
>>
>> In my cmake project I need to use system version of libxml2 on macOS (/usr/lib/libxml2.dylib), however in case it is installed in MacPorts the latter version is picked by find_package. On the other hand I'd like to avoid hardcoding absolute path, just in case Apple changes some path or file name in future OS version.
>>
>> I've tried
>>
>> find_package(LibXml2 2.8.0 REQUIRED PATHS "/usr" NO_DEFAULT_PATH)
>>
>> however it fails to find anything at all. Any ideas?
>
> My guess is that your find_package call end up in "Module mode"  because there is a FindLibXml2.cmake module bundled with cmake does not honor all options of the find_package when in this mode.
>
> So I bet FindLibXml2.cmake does not handle the given
> "PATHS "/usr" NO_DEFAULT_PATH" part.
>
> Which are handled by find_package when running in "Config mode".
>
> I suggest you to try patch and update the FindLibXml2.cmake module.

Could anyone point me to module example that handles NO_DEFAULT_PATH correctly?

> Or simply craft your own
>
> find_library(...) call.if you only need the libxml2.

That's not an elegant solution as I need to find include dir as well, and also do the same for libxslt which is in the same boat.

> Eric
>
>> --
>> Regards,
>> Konstantin
>> --
>>
>> 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
>
> --
> Eric


-- 
Regards,
Konstantin


More information about the CMake mailing list