Remove the TMC_IMPL macro requirement + enable building into a Windows DLL#207
Open
Remove the TMC_IMPL macro requirement + enable building into a Windows DLL#207
Conversation
774225a to
80c5259
Compare
80c5259 to
294ca23
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Similar to how Asio does it, there are now 3 ways to build and link to TMC:
(nothing defined): everything is
inlineand the library is header-only.TMC_STANDALONE_COMPILATION is defined: This is equivalent to the old behavior. The portions of TMC that require standalone compilation will be compiled in the translation unit that defines the TMC_IMPL macro. Other translation units should also define TMC_STANDALONE_COMPILATION, but should not define TMC_IMPL.
TMC_WINDOWS_DLL is defined: Behaves similarly to TMC_STANDALONE_COMPILATION, except that functions and data in the compilation unit that defines TMC_IMPL will be decorated with
__declspec(dllexport), so that you can build the implementation file into a DLL. Other translation units should also define TMC_WINDOWS_DLL, but should not define TMC_IMPL. In those translation units, the headers will decorate the necessary functions and data with__declspec(dllimport)so that they can be linked to the built DLL.This change is backward compatible - any library that previously defined TMC_IMPL will still work, but the macro will be ignored by default and the header-only "inline" version will be used. Worst case, users may get an unused macro warning. Users can restore the prior functionality of separate compilation by defining TMC_STANDALONE_COMPILATION.
During the development of this feature I identified an issue when building with MSVC + Release. This issue was present prior to making any changes. This may be a bug in the library or it could be a miscompilation (it wouldn't be the first time). Using clang-cl.exe works. I'll be investigating this next before pursuing any other features.