How to include a generated header without referencing the buidl directory manually?

I have a idl-file. During the build a header gets generated in the intermediate directory. How can I include this header in my source?

Currently I am including the header with the path to the intermediate directory. This is suboptimal and fails if another build directory is chosen. I am looking for a way to avoid listing the build/intermediate directory in the include.

My minimal version looks like this:

// CMakeList.txt
cmake_minimum_required (VERSION 3.1.2)
project (IDL-TestCase)
add_executable (idl-testcase  main.cpp foo.idl)

// main.cpp
#include "../out/idl-testcase.dir/Debug/foo.h"  // How to avoid the build directory?

int main() { /* code using IFoo */ }

// foo.idl
import "oaidl.idl";

interface IFoo
    HRESULT foo();

Thank you for your consideration.

Add the appropriate binary directory to your include search path, e.g.



target_include_directories(idl-testcase PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

If the files are not directly in the binary dir, but some subdirectory thereof, modify the path accordingly,. In your case, it seems ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> might be required.

results in out/Debug. That means the idl-testcase.dir part of out/idl-testcase.dir/Debug/foo.h is still missing. It seems the “intermediate directory” (idl-testcase.dir) is difficult to get hold of. So I use


Ideally I would get rid of the idl-testcase.dir though.