GenerateExportHeader shouldn't generate empty macros for static target
As described in the GenerateExportHeader documentation, the macros in the generated export header file are defined without values for a static target. This is unfortunate behavior, if you change the type of your target according to the BUILD_SHARED_LIBS
variable.
An example project is described in @alexreinking's blog post, example code can be found in this repository. The original issue was also created in this repository.
What essentially happens is this: If you build the shared variant of the library, the export header is correctly generated. For the static variant, the macros are defined without value (as intended ATM). When you now install both variants into the same install prefix, the different export headers overwrite each other.
Defining the macros without value for a static target seems unnecessary, as there is already another mechanism in place to deactivate the macros for the static target, which is the ${BASE_NAME}_STATIC_DEFINE
target definition. This is also documented.
The header file starts with the relevant code block:
#ifdef ${BASE_NAME}_STATIC_DEFINE
# define ${BASE_NAME}_EXPORT
# define ${BASE_NAME}_NO_EXPORT
#else
...
It would be great, if GenerateExportHeader could always generate the same export header, no matter to which type of target it is applied. The only mechanism of deactivating the macros for a static target should be the already documented compile definition ${BASE_NAME}_STATIC_DEFINE
.