Find_package multiple times

I have multiple shared libraries that I want to build and each of them should be linked to a different version of a static library.

In my CMakeLists.txt I have a loop over all shared libraries that I want to build and for each of them I have a folder which contains the correct version of the static library that I want to link it to.

So inside the foreach loop I have a find_package call where I set the ${STATIC_PACKAGE_NAME}_ROOT before to the corresponding folder.

However, that seems to not work as it just finds the first folder and in the second iteration it does not try to find it in the second path that I provide, but it uses the first static library version again.

I imagine that I would run into troubles anyways because the find_package would create the same target (from my static library) again, which is not allowed. Is there a way around this issue?

Thanks in advance,
Arno

You’ll probably have to manually clear out the cache variables (unset(var1 var2 CACHE)) found in find_package as well as any local-scoped output variables or book-keeping by find_package itself. I don’t think there’s a global control for the NO_CACHE argument to the find_* commands.