[CMake] find_library and caching
Lucas Soltic
lucas.soltic at orange.fr
Sun Jun 15 16:27:14 EDT 2014
Le 15 juin 2014 à 20:19, Nils Gladitz <nilsgladitz at gmail.com> a écrit :
> On 15.06.2014 19:33, Lucas Soltic wrote:
>> I use a FindSomeLib.cmake script for my project, for which there is a variable (let's call it LINK_STATIC) to define if one wants to link against SomeLib statically. The default is to look for dynamic libraries.
>>
>> The issue is that when first running CMake's configure, the user may have forgotten to set LINK_STATIC, so the script finds the dynamic version of SomeLib and set a cache entry for it. Then in CMake's GUI the user realizes he wants static linking so he sets the LINK_STATIC flag, but at this point find_library has already cached the result and won't look again for static version of SomeLib.
>>
>> This ends up with the user thinking he's using static linking, which is not what's happening.
>> I saw in CMake's doc that in order to let find_library search again, I'd need to clear the library entry it has found. But if I do this at each CMake configure run, it removes the interest of the cache.
>>
>> Would anyone know about the preferred way to fix this caching issue?
>> I would be really grateful :)
>>
>
> Perhaps you could use distinct cache variables for static and shared libraries.
>
> e.g.
>
> find_library(FOO_STATIC_LIBRARY ...)
> find_library(FOO_SHARED_LIBRARY ...)
>
> set(FOO_LIBRARIES "")
>
> if(FOO_LINK_STATIC)
> list(APPEND FOO_LIBRARIES ${FOO_STATIC_LIBRARY})
> else()
> list(APPEND FOO_LIBRARIES ${FOO_SHARED_LIBRARY})
> endif()
>
> Nils
Oh my… really interesting idea! Thanks!!
Lucas
More information about the CMake
mailing list