# Rely on target in the upper directory using cmake to use precompiled headers

**URL:** https://discourse.cmake.org/t/rely-on-target-in-the-upper-directory-using-cmake-to-use-precompiled-headers/9770
**Category:** Code
**Created:** [January 4, 2024, 12:01pm UTC](https://discourse.cmake.org/t/rely-on-target-in-the-upper-directory-using-cmake-to-use-precompiled-headers/9770 "2024-01-04T12:01:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![oleg](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/ebca7d/32.png) [@oleg](https://discourse.cmake.org/u/oleg)
#### Post date: [January 4, 2024, 12:01pm UTC](https://discourse.cmake.org/t/rely-on-target-in-the-upper-directory-using-cmake-to-use-precompiled-headers/9770/1 "2024-01-04T12:01:44Z")

</div>

I have a root cmake which produces me main binary with precompiled headers:

```auto
cmake_minimum_required(VERSION 3.16)
project(main_app)

add_executable( main_app src/main_app.cpp )

target_precompile_headers( main_app PUBLIC src/pch.h )
set( CMAKE_PCH_INSTANTIATE_TEMPLATES ON )

target_link_libraries( main_app boost_random )
add_subdirectory( tests )

```

I have also ‘tests’ subdirectory which has it’s own CMakeLists.txt and I am trying to rely on the target that is in the root directory to use already generated precompiled headers like this:

```auto
...
target_precompile_headers( some_test REUSE_FROM main_app )
...

```

But I am receiving an error that says in general that it could not find target ‘main\_app’.

When I am doing that from the same CMakeLists.txt, everything is working, but I do not know how to rely on the target that is in the root/upper directory. Please advice how to resolve this issue, thanks in advance

---

<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: [January 11, 2024, 2:13pm UTC](https://discourse.cmake.org/t/rely-on-target-in-the-upper-directory-using-cmake-to-use-precompiled-headers/9770/2 "2024-01-11T14:13:21Z")

</div>

That’s certainly odd. Can you provide the context around `some_test` so that others can try to reproduce the problem?
