I've changed climatology_pi plugininstall.cmake at these lines.
- target_link_libraries(${PACKAGE_NAME} PRIVATE ${wxWidgets_LIBRARIES} ${EXTRA_LIBS})
- target_link_libraries(${PACKAGE_NAME} PRIVATE ${OPENGL_LIBRARIES})
- target_link_libraries(${PACKAGE_NAME} PRIVATE ${OPENGL_LIBRARIES})
- target_link_libraries(${PACKAGE_NAME} PRIVATE ${BZIP2_LIBRARIES} ${ZLIB_LIBRARY})
- target_link_libraries(${PACKAGE_NAME} PRIVATE ${ZLIB_LIBRARIES})
I realize making this change means I need to change all of the plugins to match.
Which is some work.
==================
From AI
Target typing (PRIVATE, PUBLIC, INTERFACE) is used so CMake knows how far to propagate include paths and link dependencies.
For: target_link_libraries(${PACKAGE_NAME} PRIVATE ${OPENGL_LIBRARIES})
the very brief reason is:
PRIVATE ensures the plugin links to OpenGL, but does not expose OpenGL to anything that depends on the plugin.
It keeps the dependency local, preventing accidental propagation of GL headers/libs into other targets.
PUBLIC: propagate usage requirements to dependents and to this target.
PRIVATE: apply usage requirements only to this target; do not propagate.
INTERFACE: propagate usage requirements to dependents only; nothing applies to this target itself.
Why PRIVATE is appropriate
OpenGL is a pure implementation detail of the plugin’s rendering path. Nothing that links against your plugin should inherit or be forced to include:
GL headers
GL library link flags
GL compile definitions
If you used PUBLIC, you would export OpenGL to any consumer of the plugin target — which is wrong, because:
Plugins are leaf nodes; nothing depends on them.
OpenGL is not part of the plugin’s public API.
Propagating GL can cause ABI conflicts with OpenCPN’s own GL handling.
The rule of thumb for OpenCPN plugins
OpenGL → always PRIVATE
wxWidgets → usually PRIVATE
Plugin API headers → PUBLIC or INTERFACE (because consumers need them)
I've changed climatology_pi plugininstall.cmake at these lines.
I realize making this change means I need to change all of the plugins to match.
Which is some work.
==================
From AI
Target typing (PRIVATE, PUBLIC, INTERFACE) is used so CMake knows how far to propagate include paths and link dependencies.
For: target_link_libraries(${PACKAGE_NAME} PRIVATE ${OPENGL_LIBRARIES})
the very brief reason is:
PRIVATE ensures the plugin links to OpenGL, but does not expose OpenGL to anything that depends on the plugin.
It keeps the dependency local, preventing accidental propagation of GL headers/libs into other targets.
PUBLIC: propagate usage requirements to dependents and to this target.
PRIVATE: apply usage requirements only to this target; do not propagate.
INTERFACE: propagate usage requirements to dependents only; nothing applies to this target itself.
Why PRIVATE is appropriate
OpenGL is a pure implementation detail of the plugin’s rendering path. Nothing that links against your plugin should inherit or be forced to include:
GL headers
GL library link flags
GL compile definitions
If you used PUBLIC, you would export OpenGL to any consumer of the plugin target — which is wrong, because:
Plugins are leaf nodes; nothing depends on them.
OpenGL is not part of the plugin’s public API.
Propagating GL can cause ABI conflicts with OpenCPN’s own GL handling.
The rule of thumb for OpenCPN plugins
OpenGL → always PRIVATE
wxWidgets → usually PRIVATE
Plugin API headers → PUBLIC or INTERFACE (because consumers need them)