# find\_package COMPONENTS with variable cmake list

**URL:** https://discourse.cmake.org/t/find-package-components-with-variable-cmake-list/4971
**Category:** Usage
**Created:** [February 7, 2022, 6:30pm UTC](https://discourse.cmake.org/t/find-package-components-with-variable-cmake-list/4971 "2022-02-07T18:30:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rhodanos](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/r/df788c/32.png) [@rhodanos](https://discourse.cmake.org/u/rhodanos)
#### Post date: [February 7, 2022, 6:30pm UTC](https://discourse.cmake.org/t/find-package-components-with-variable-cmake-list/4971/1 "2022-02-07T18:30:31Z")

</div>

Hi everybody,

I would like to define a basic find component system for all of my projects which has some default componet values set but may be edited by the user in cmake gui if the need arises.

So far I thought I would define a cmake CACHE STRING variable with the default components e.g.  
set(QT\_COMPONENTS “Core Gui Widgets” CACHE STRING “Project default QT components”)

and then call find\_package using the component string  
find\_package(Qt5 REQUIRED COMPONENTS “${QT\_COMPONENTS}”)

So far I’ve tried the following three different ways to call COMPONENTS:  
“${QT\_COMPONENTS}”  
${QT\_COMPONENTS}  
QT\_COMPONENTS

But, no call seems to be correct. I can’t seem to get the find\_package function evaluate the QT\_COMPONENTS property.

Printing “${QT\_COMPONENTS}” results in → Core Gui Widgets, which seems to be fine.  
In the gui I get the new variable “Qt5Core Gui Widgets Network\_DIR-NOTFOUND” so my string does not seem to be handled as separate values with witespaces.

Is there a way this will work?

Best regards,  
Matthias

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [February 7, 2022, 9:20pm UTC](https://discourse.cmake.org/t/find-package-components-with-variable-cmake-list/4971/2 "2022-02-07T21:20:13Z")

</div>

set(QT\_COMPONENTS “Core;Gui;Widgets” CACHE STRING “Project default QT components”)

or

set(QT\_COMPONENTS Core Gui Widgets CACHE STRING “Project default QT components”)

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [February 7, 2022, 9:22pm UTC](https://discourse.cmake.org/t/find-package-components-with-variable-cmake-list/4971/3 "2022-02-07T21:22:47Z")

</div>

If you need the CACHE variable to be space-separated, use string() to replace spaces with semicolons.
