[CMake] find_library finds same library over and again

Hendrik Sattler post at hendrik-sattler.de
Thu Nov 3 07:44:39 EDT 2011


Am 03.11.2011 12:42, schrieb Hendrik Sattler:
> Am 03.11.2011 12:26, schrieb John R. Cary:
>> Feels like I am doing something wrong.
>>
>> Looking for multiple libraries:
>>
>> $ cat CMakeLists.txt
>> set(mylibdir /contrib/netcdf-4.1.2-ser/lib)
>> foreach (name netcdf_c++ netcdff netcdf)
>>   message("Looking for ${name} in ${mylibdir}.")
>>   find_library(mylib NAMES ${name} PATHS ${mylibdir} 
>> NO_DEFAULT_PATH)
>>   if (mylib)
>>     message("Found: ${mylib}.")
>>     list(APPEND mylibs ${mylib})
>>   else ()
>>     message("Not found.")
>>   endif ()
>> endforeach ()
>>
>> But continues to find the first each time:
>
> From the documentation:
> "A cache entry named by <VAR> is created to store the result of this
> command. If the library is found the result is stored in the variable
> and the search will not be repeated unless the variable is cleared."

Note that clearing the variable is NOT the suggested way, instead use a 
name that depends on the loop-item.

HS



More information about the CMake mailing list