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

Konstantin Tokarev annulen at yandex.ru
Wed Oct 12 12:07:38 EDT 2016



12.10.2016, 19:04, "rleigh at codelibre.net" <rleigh at codelibre.net>:
> On 2016-10-12 15:28, Konstantin Tokarev wrote:
>>  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?
>
> Use
>
>    find_package(LibXml2 2.8.0 REQUIRED)
>
> and then use CMAKE_PREFIX_PATH to define the search locations (in your
> environment or on the command-line; not in the script).

That would be great if CMake didn't add Fink and MacPorts paths to
CMAKE_SYSTEM_PREFIX_PATH out of the box unconditionally.

> If you
> hardcode paths in the script, you make it break on other systems.
> That might not be a consideration in this case, but the less
> assumptions you make, the more flexible it will be.

Of course, this hack would be guarded with if (APPLE), and other systems
would continue using normal find_package call.

>
> Regards,
> Roger

-- 
Regards,
Konstantin


More information about the CMake mailing list