I am working with a codebase containing classes shared between multiple projects. Until now those classes had simply been stored in common folders and referenced in-place. In the interest of versioning these dependencies, I've started grouping them into Conan packages and using CMake.
Before this effort, each project had a stdafx.h which contained everything needed by that project and whatever shared classes it used. Now, I am trying to create a precompiled header for each Conan package, so they build independently.
The hiccup is the following scenario:
ClassA.h
//If I don't include LibraryPrecompiledHeader.h here or in example.cpp,
//the method signature below will not compile.
class ClassA
{
public:
HRESULT Method1(LPCTSTR str);
};
ClassA.cpp
#include "LibraryPrecompiledHeader.h"
...
LibraryPrecompiledHeader.h
#pragma once
#include <atlstr.h>
#include <atlcoll.h>
Example.cpp (Conan test class consuming the library)
#include "LibraryPrecompiledHeader.h" //It will not build without including this here
//or in ClassA.h
#include "ClassA.h"
...
I can think of several ways to make this work, none of which I like:
- Include
LibraryPrecompiledHeader.h
in Example.cpp. That would mean any consumer of the library would have to do the same every time a class from the library is needed. - Include
LibraryPrecompiledHeader.h
in the ClassA.h. This has yielded conflicts later when a project uses multiple packages, each with their own precompiled headers. Specifically, I'm running into an issue of windows.h being included multiple times by various ATL & MFC headers.
Update: This problem is not specific to pre-compiled headers. If I simply include atlstr.h directly, I still must include it in either ClassA.h or example.cpp. It turns out MFC & ATL are both trying to pull in Windows.h. The MFC includes must come first to avoid the windows.h double include, which is difficult to guarantee if each package only includes what it needs.
- Create One-Precompiled-Header-To-Rule-Them-All and use it everywhere. This means having a huge precompiled header included on even the smallest of libraries.
- Include the dependencies for the library in the precompiled header of the class that eventually consumes them. This tightly couples the consumer to the library implementation.
Is there something I am missing?