larsch / cmake-precompiled-header

Visual Studio and GCC precompiled header macro for CMake
160 stars 42 forks source link

PCHs outside the current source directory #19

Open dutow opened 6 years ago

dutow commented 6 years ago

There are projects which have include files outside the current source directory. For example if the project has an include and an src folder, and the current CMake file is in the src folder.

In these cases, the pch file has to be referenced as ../include/pch.h.

While this works with the FORCEINCLUDE option (it doesn't without that), it also creates files outside the _pch_binary_dir.

I think the best approach to resolve this would be the addition of another optional parameter, PCH_PATH, such as:

add_precompiled_header( target ../include/foo/bar/pch.h PCH_PATH foo/bar/pch.h )

Most likely this parameter should be required if the header path starts with "..", or if it an absolute path.

This would solve both this issue, and the other I reported.