# Check whether INSTALL target exists

**URL:** https://discourse.cmake.org/t/check-whether-install-target-exists/10168
**Category:** Usage
**Created:** [February 23, 2024, 11:42am UTC](https://discourse.cmake.org/t/check-whether-install-target-exists/10168 "2024-02-23T11:42:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [February 23, 2024, 11:42am UTC](https://discourse.cmake.org/t/check-whether-install-target-exists/10168/1 "2024-02-23T11:42:38Z")

</div>

Context: I am writing a CMake library for use by a number of my colleagues. Any of their projects may generate a number of executables and libraries, not all of which they want to install, so I make them set CMake variables to denote which ones they want installed and which ones they don’t want installed. Sometimes they forget to set any at all, and are then surprised when there is no INSTALL target for them to select in Visual studio. I’d like to be able to generate a warning message, and remind them of what they need to do.

My question, then…

Is it possible to tell whether a project has an INSTALL target?

I know that there’s an “if (TARGET \<target-name\>)” command, but this doesn’t work. According to the documentation,

```auto
True if the given name is an existing logical target name created by 
a call to the add_executable(), add_library(), or add_custom_target() 
command that has already been invoked (in any directory).

```

…but this isn’t applicable for standard targets that CMake generates itself.

I had another idea, which was to have my batch script that invokes CMake check whether a “cmake\_install.cmake” file was generated in the binaries directory, but it looks like one is created even if there is nothing for it to install.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 27, 2024, 2:10pm UTC](https://discourse.cmake.org/t/check-whether-install-target-exists/10168/2 "2024-02-27T14:10:11Z")

</div>

I don’t think there’s a way to know if a target has any associated `install()` rules (and if so, what bits are installed). We might need to make `EXPORT` “objects” that can be queried for this.

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [February 27, 2024, 11:15pm UTC](https://discourse.cmake.org/t/check-whether-install-target-exists/10168/3 "2024-02-27T23:15:45Z")

</div>

Thank you; I’ll try to find a workaround, or just make sure that the documentation covers this eventuality.
