Pass multiple values inside find_package in cmake

Viewed 305

I have defined a variable in CMakeLists.txt as follows:

set(MY_PROJECT_DEPENDENCIES boost-core boost-optional sqlite3)

I want to check if there are found using find_package() as follows:

find_package(MY_PROJECT_DEPENDENCIES REQUIRED).

But this does not work. Any workaround for the same?

Edit: As drescherjm suggested using a foreach loop works perfectly. Here is the code snippet:

macro(find_packages)
  foreach(package ${ARGN})
    find_package(${package} REQUIRED)
  endforeach()
endmacro()

Call it using:

find_packages(${MY_PROJECT_DEPENDENCIES})```
1 Answers

your problem is MY_PROJECT_DEPENDENCIES is a list, and you tried to use find_package on those list, but find_package is expecting PackageName separately

so your workaround is to call find_package for every packages (using loops on the those list) and define this in the macro for easy using.

Related