How to specify the name of the file to generate pre-compiled headers?

I have this in my CMakeList file:

target_precompile_headers(DeepSkyStacker PRIVATE
	stdafx.h
	)

I also have an existing file to generate the pre-compiled headers called stdafx.cpp

However CMake creates a file called cmake_pch.cxx (and indeed cmake_pch.hxx which includes the header I specified.

Can I get CMake to use the existing stdafx.cpp instead?

Thanks, David

No, that’s not how CMake’s precompiled headers work. You tell it which headers you want included in the set of precompiled headers, and it takes care of generating appropriate files for the toolchain you’re using, then injecting the precompiled headers into your build. You will need to remove stdafx.cpp from your project if you want to use CMake’s precompiled headers feature.

Note that you don’t need stdafx.h either. In your sources and headers, you should include just the headers each file actually needs. Then use target_precompile_headers() to specify the headers you want to include in the precompiled set (this would be the same list of headers you’re currently including in stdafx.h).