# Can NOT find out dynamic header file generated by configure\_file.

**URL:** <https://discourse.cmake.org/t/can-not-find-out-dynamic-header-file-generated-by-configure-file/10722>\
**Category:** Code\
**Created:** [April 23, 2024, 11:09am UTC](https://discourse.cmake.org/t/can-not-find-out-dynamic-header-file-generated-by-configure-file/10722 "2024-04-23T11:09:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evilroach](https://discourse.cmake.org/user_avatar/discourse.cmake.org/evilroach/32/2805_2.png) [@evilroach](https://discourse.cmake.org/u/evilroach)\
**Post date:** [April 23, 2024, 11:09am UTC](https://discourse.cmake.org/t/can-not-find-out-dynamic-header-file-generated-by-configure-file/10722/1 "2024-04-23T11:09:26Z")

</div>

I have a dynamic header `Version.hpp` generated by `configure_file` command of cmake-3.25.

I can normally use it at the top of the source tree as is, but can **NOT** use it in a subdirectory of the tree.

Like this:  
The top level CMakeLists.txt:

```auto
cmake_minimum_required( VERSION 3.16.0 )
set( PROJECT_VERSION_MAJOR 1 )
set( PROJECT_VERSION_MINOR 2 )
set( PROJECT_VERSION_PATCH 3 )
set( PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} )
set( PROJECT_DESCRIPTION "try-cmake" )
project( try-cmake VERSION ${PROJECT_VERSION} DESCRIPTION ${PROJECT_DESCRIPTION} LANGUAGES CXX )
configure_file( Version.hpp.in Version.hpp )
# include_directories( "." )
set( CMAKE_INCLUDE_CURRENT_DIR ON )
add_executable( try-cfg Main.cpp )
install( TARGETS try-cfg RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
add_subdirectory( unit-test )

```

And the CMakeList.txt in subdirectory `unit-test`:

```auto
cmake_minimum_required( VERSION 3.16.0 )

# This line does not work
include_directories( ".." )
# and this neither
set( CMAKE_INCLUDE_CURRENT_DIR ON )

add_executable( ut ut-main.cpp )
install( TARGETS ut RUNTIME DESTINATION test )

```

And the source `Main.cpp` in the top( can be compiled):

```auto
#include <iostream>
#include <iomanip>
#include "Version.hpp"
using namespace std;
int main() {
	cout << "Product Version:" << PROJECT_VERSION << endl;
};

```

And the source `ut-main.cpp` at a subdir(can **NOT** be compiled):

```auto
#include <iostream>
#include <iomanip>
#include "Version.hpp"
using namespace std;
int main() {
	cout << "Unit Test Version:" << PROJECT_VERSION << endl;
};

```

The error text:

> fatal error: Version.hpp: No such file or directory  
> 3 | #include “Version.hpp”  
> | ^ ~~~~~~~~~~~~  
> compilation terminated.

Thanks!

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [April 23, 2024, 5:04pm UTC](https://discourse.cmake.org/t/can-not-find-out-dynamic-header-file-generated-by-configure-file/10722/2 "2024-04-23T17:04:14Z")

</div>

Does that work?

```auto
add_executable(ut ut-main.cpp)

target_include_directories(ut
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/..
        # or
        #${CMAKE_SOURCE_DIR} # probably not a good idea, if your top-level project might be used as a sub-project elsewhere
)

```

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [April 24, 2024, 10:27am UTC](https://discourse.cmake.org/t/can-not-find-out-dynamic-header-file-generated-by-configure-file/10722/3 "2024-04-24T10:27:03Z")

</div>

[See too the CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/Installing%20and%20Testing.html)
