Hello, thank you for maintaining this fork! It's a big help for CMake users like myself.
The issue I'm addressing affects CMake users who consume glew using the add_subdirectory or FetchContent API's. Those API's create a single project/solution with all targets (that is, glew and a users targets together). When they're all together in the same solution, CMake will define GLEW_BUILD for each target that links with glew. This is a problem because if GLEW_BUILD is defined, then glew.h will declare GLEWAPI as __declspec(dllexport) instead of __declspec(dllimport) which causes linker errors for consumers.
The solution is to use PRIVATE instead of PUBLIC when defining GLEW_BUILD. The documentation for target_compiler_definitions does a poor job of explaining it, but this discussion clears it up. Basically, using PUBLIC defines the definition for the target you specify and for all targets linking against it whereas PRIVATE only defines the definition for the specified target. I believe GLEW_BUILD should only be defined for libglew_shared.
Hello, thank you for maintaining this fork! It's a big help for CMake users like myself.
The issue I'm addressing affects CMake users who consume glew using the add_subdirectory or FetchContent API's. Those API's create a single project/solution with all targets (that is, glew and a users targets together). When they're all together in the same solution, CMake will define
GLEW_BUILD
for each target that links with glew. This is a problem because ifGLEW_BUILD
is defined, thenglew.h
will declareGLEWAPI
as__declspec(dllexport)
instead of__declspec(dllimport)
which causes linker errors for consumers.The solution is to use
PRIVATE
instead ofPUBLIC
when definingGLEW_BUILD
. The documentation for target_compiler_definitions does a poor job of explaining it, but this discussion clears it up. Basically, usingPUBLIC
defines the definition for the target you specify and for all targets linking against it whereasPRIVATE
only defines the definition for the specified target. I believeGLEW_BUILD
should only be defined forlibglew_shared
.