Perlmint / glew-cmake

GLEW(https://github.com/nigels-com/glew, source updated nightly) with Cmake and pre-generated sources
Other
234 stars 95 forks source link

Define GLEW_BUILD only for libglew_shared and not consumer targets. #28

Closed hgs3 closed 4 years ago

hgs3 commented 4 years ago

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.

Perlmint commented 4 years ago

Thanks for PR with nice comment.