[cmake-developers] Fix for re-running FindPythonLibs with multiple configurations
Richard Christie
r.christie at auckland.ac.nz
Thu Mar 31 22:31:35 EDT 2016
Hi Brad,
Thanks for the quick and helpful response!
I've had a quick education on CMake variable scoping, and now realise that the cached PYTHON_LIBRARY variable, which contains either the user-specified library or the found release library, becomes eclipsed by a local PYTHON_LIBRARY variable, set in SELECT_LIBRARY_CONFIGURATIONS() when FindPythonLibs is run, and in multi-configuration builds the variable becomes a list containing:
"optimized;PYTHON_LIBRARY_RELEASE;debug;PYTHON_LIBRARY_DEBUG". This would not be a problem except that FindPythonLibs assigns it to PYTHON_LIBRARY_RELEASE, which then feeds into the new PYTHON_LIBRARY list.
So I've attached an improved fix, which is much simpler: it determines whether PYTHON_LIBRARY is a list and extracts the optimized library out of it. It would be nice if it were more elegant or a standard function were available to do this as needed elsewhere.
The obvious question is whether our re-running of find_package(PythonLibs) is bad practice... It comes about because one CMakeLists does a first check on whether python is available, then another builds SWIG interfaces using it. OTOH the way the PYTHON_LIBRARY variable is manipulated is quite unexpected, however I imagine there are a lot of behaviours in these scripts which you're stuck with for legacy reasons...
Regards,
Richard
-----Original Message-----
From: Brad King [mailto:brad.king at kitware.com]
Sent: Friday, 1 April 2016 2:38 a.m.
To: Richard Christie
Cc: cmake-developers at cmake.org
Subject: Re: [cmake-developers] Fix for FindPythonLibs with multiple configurations
Hi Richard,
> The attached patch fixes this nesting issue.
Thanks for working on this. Please look at revising this to avoid exposing the _ANYCONFIG variable. Use a "_Python_..." internal variable that is unset, or find another way to do it without the variable, such as `(PYTHON_RELEASE_LIBRARY OR PYTHON_DEBUG_LIBRARY)`.
> idiom for dealing with pre-specified multi-configuration libraries
I don't think our find modules ever consider the possibility of pre-specified multi-config libraries. Each cache entry is meant to hold a single find_library result and the module puts them together. The leaking across multiple calls was not intentional.
Therefore this is not a concern for me.
Thanks,
-Brad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-re-running-FindPythonLibs-for-multi-config.patch
Type: application/octet-stream
Size: 1269 bytes
Desc: 0001-Fix-re-running-FindPythonLibs-for-multi-config.patch
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160401/ad1240bb/attachment.obj>
More information about the cmake-developers
mailing list