ManuelSchneid3r
ManuelSchneid3r

Reputation: 16121

How to Use Precompiled Headers Across a Library and Its Plugins in CMake With Export Headers?

I am working on a CMake/C++ project which consists of an app, a core library and multiple plugins. The core library uses an export header (generated by CMake’s GenerateExportHeader module) to manage symbol visibility. The library and plugins both utilize precompiled headers (PCH) for faster builds.

The issue arises when building the plugins. The PCH for the core library is compiled with PROJNAME_EXPORTS defined (to export symbols). The PCH for the plugins is compiled without PROJNAME_EXPORTS defined (to import symbols). This leads to this warning during the plugin build:

cc1plus: warning: /build/CMakeFiles/proj.dir/cmake_pch.hxx.gch: not used because `PROJNAME_EXPORTS' not defined [-Winvalid-pch]

This behavior is expected because the export header controls different visibility macros for import and export contexts.

My Questions: Is it possible to reuse the core library's PCH in its plugins while accounting for the differing export definition? If not, is there a recommended approach to manage precompiled headers in this scenario, ensuring that both the core library and its plugins benefit from PCH without symbol visibility issues?

Upvotes: 0

Views: 36

Answers (0)

Related Questions