No longer require MODULE_EXPORTS and fix related issues#435
Merged
marktsuchida merged 3 commits intomainfrom Jan 24, 2024
Merged
No longer require MODULE_EXPORTS and fix related issues#435marktsuchida merged 3 commits intomainfrom
marktsuchida merged 3 commits intomainfrom
Conversation
This uses obsolete CMake constructs (not "modern CMake"). And it will (continue to) bit-rot in the absense of regular testing.
MODULE_EXPORTS is defined in MMDeviceAdapter.props, but some device
adapter projects (old ones, and copied or cargo-culted ones) redundantly
defined it.
```sh
find DeviceAdapters -name '*.vcxproj' -print0 \
| xargs -0 gsed -i 's/MODULE_EXPORTS;//'
```
(`gsed` being GNU sed)
The new macro has (roughly) the opposite meaning as the (intent of) MODULE_EXPORTS: it should be defined when building MMCore and undefined when building device adapters. The source is now _capable_ of excluding the module interface functions when building MMCore (and the MMCore Meson build does so). Symbol visibility is set for GCC/Clang so that -fvisibility=hidden can be used when building device adapters (but this is not done for now). No changes to device adapters is required.
1 task
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.
MMDevice (in
ModuleInterface.h) conditionally definedMODULE_APIbased on whetherMODULE_EXPORTSwas defined. The intent was (presumably) that device adapters would defineMODULE_EXPORTSand therefore expose the module interface functions such asInitializeModuleData()(defined by the device adapter) andGetNumberOfDevices()(defined inModuleInterface.cpp), whereasMODULE_EXPORTSwould not be defined when building MMCore so that those functions are not included.In practice, there were a few issues:
MODULE_EXPORTS, so the device module interface functions were being included inMMCoreJ_wrap.dll(this is harmless).MODULE_EXPORTSwas not defined,MODULE_APIwas incorrectly defined to__declspec(dllimport), which is irrelevant when libraries are loaded viaLoadLibrary(). This also meant thatModuleInterface.cppdid not compile on Windows withoutMODULE_EXPORTSdefined.MODULE_EXPORTSwas never defined in any case (and had no effect either). The module interface functions were being included inlibMMCoreJ_wrap(again, harmless).MODULE_EXPORTSis too generic.So this PR replaces
MODULE_EXPORTSwith another macro,MMDEVICE_CLIENT_BUILD, with roughly the opposite meaning. Device adapters no longer need to define any macro, whereas building MMCore should defineMMDEVICE_CLIENT_BUILD.In addition,
MODULE_APIis now defined for GCC/Clang to explicitly give the functions default visibility, so that we can use-fvisibility=hiddenwhen building device adapters in the future (doing so has a number of advantages but is not urgent).To work around the way our Visual Studio and Autotools builds work (i.e., the common MMDevice static library), it is still possible to build MMCore using an MMDevice static library built without
MMDEVICE_CLIENT_BUILD, as long asMMDEVICE_CLIENT_BUILDis defined when including the MMDevice headers during the MMCore build. This is similar to howMODULE_EXPORTSwas previously being used on Windows.MMCoreJ_wrapwill expose unnecessary symbols, but this is the same as the previous situation.Note that device adapters (including any that are outside of this repo) do not need to change: defining
MODULE_EXPORTSnow has no effect but also does not do any harm.It would be nice to also rename
MODULE_APIto something likeMMDEVICE_API, but that would require changing the source code of all device adapters; probably not worth the disruption at this time. I did make it so thatMODULE_APIis not defined whenMMDEVICE_CLIENT_BUILDis defined.Finally, none of this affects the device interface version.
Manual testing
CreateDeviceCreateDeviceCreateDeviceMMDEVICE_CLIENT_BUILDadded)