Skip to content

Commit

Permalink
Replace MODULE_EXPORTS with MMDEVICE_CLIENT_BUILD
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marktsuchida committed Jan 24, 2024
1 parent 41db679 commit 39a90f7
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 36 deletions.
4 changes: 2 additions & 2 deletions MMCore/MMCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>NOMINMAX;WIN32;_DEBUG;_LIB;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MMDEVICE_CLIENT_BUILD;NOMINMAX;WIN32;_DEBUG;_LIB;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
Expand All @@ -65,7 +65,7 @@
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PreprocessorDefinitions>NOMINMAX;WIN32;NDEBUG;_LIB;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>MMDEVICE_CLIENT_BUILD;NOMINMAX;WIN32;NDEBUG;_LIB;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
2 changes: 2 additions & 0 deletions MMCore/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AUTOMAKE_OPTIONS = foreign subdir-objects

AM_CPPFLAGS = -DMMDEVICE_CLIENT_BUILD

noinst_LTLIBRARIES = libMMCore.la

libMMCore_la_LIBADD = ../MMDevice/libMMDevice.la
Expand Down
7 changes: 4 additions & 3 deletions MMCore/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
project(
'MMCore',
'cpp',
meson_version: '>=1.1.0', # May relax
meson_version: '>=1.2.0',
default_options: [
'cpp_std=c++14',
'warning_level=3',
Expand All @@ -28,9 +28,10 @@ else
endif
mmdevice_proj = subproject(
'MMDevice',
# Propagate value of 'tests' option ('yield: true' in MMDeivce's 'tests'
# option did not seem to work; Meson 1.3.1).
default_options: {
'client_interface': true,
# Propagate value of 'tests' option ('yield: true' in MMDeivce's
# 'tests' option did not seem to work; Meson 1.3.1).
'tests': tests_option,
},
)
Expand Down
3 changes: 1 addition & 2 deletions MMCoreJ_wrap/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ AUTOMAKE_OPTIONS = foreign subdir-objects
# (We used to globally use -O by default, rather than -O2, on Linux, presumably
# for the above reason (though the intent was never documented). But there is
# nothing Linux-specific about this.)
# TODO The flag should come from configure.
AM_CXXFLAGS = -fno-strict-aliasing
AM_CPPFLAGS = $(JNI_CPPFLAGS)
AM_CPPFLAGS = $(JNI_CPPFLAGS) -DMMDEVICE_CLIENT_BUILD


# This ugly list of headers is necessary to trigger the rebuild of the
Expand Down
4 changes: 2 additions & 2 deletions MMDevice/MMDevice-SharedRuntime.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -77,7 +77,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
4 changes: 2 additions & 2 deletions MMDevice/MMDevice-StaticRuntime.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -78,7 +78,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
Expand Down
7 changes: 4 additions & 3 deletions MMDevice/MMDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@
#include <vector>


#ifdef MODULE_EXPORTS
#ifdef MMDEVICE_CLIENT_BUILD
// Hide deprecation warnings when building MMCore
# define MM_DEPRECATED(prototype) prototype
#else
# ifdef _MSC_VER
# define MM_DEPRECATED(prototype) __declspec(deprecated) prototype
# elif defined(__GNUC__)
# define MM_DEPRECATED(prototype) prototype __attribute__((deprecated))
# else
# define MM_DEPRECATED(prototype) prototype
# endif
#else
# define MM_DEPRECATED(prototype) prototype
#endif

#ifdef _WIN32
Expand Down
5 changes: 4 additions & 1 deletion MMDevice/ModuleInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

#include "ModuleInterface.h"

#ifndef MMDEVICE_CLIENT_BUILD

#include <algorithm>
#include <string>
#include <vector>


namespace {

struct DeviceInfo
Expand Down Expand Up @@ -135,3 +136,5 @@ void RegisterDevice(const char* deviceName, MM::DeviceType deviceType, const cha

g_registeredDevices.push_back(DeviceInfo(deviceName, deviceType, deviceDescription));
}

#endif // MMDEVICE_CLIENT_BUILD
37 changes: 19 additions & 18 deletions MMDevice/ModuleInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@

#include "MMDevice.h"

#ifdef _WIN32
#ifdef MODULE_EXPORTS
#define MODULE_API __declspec(dllexport)
#else
#define MODULE_API __declspec(dllimport)
#endif
#else
#define MODULE_API
#endif


/// Module interface version.
/**
* The Core ensures that any loaded device adapter modules have a matching
Expand All @@ -50,11 +39,20 @@
// GetModuleVersion() must never change.
#define MODULE_INTERFACE_VERSION 10


/*
* Exported module interface
*/
extern "C" {
#ifndef MMDEVICE_CLIENT_BUILD

// Make the module interface functions visible from outside the module.
#ifdef _MSC_VER
# define MODULE_API __declspec(dllexport)
#else
# define MODULE_API __attribute__((visibility("default")))
#endif

/*
* Exported module interface
*/

/// Initialize the device adapter module.
/**
* Device adapter modules must provide an implementation of this function.
Expand Down Expand Up @@ -103,10 +101,10 @@ extern "C" {
MODULE_API bool GetDeviceName(unsigned deviceIndex, char* name, unsigned bufferLength);
MODULE_API bool GetDeviceType(const char* deviceName, int* type);
MODULE_API bool GetDeviceDescription(const char* deviceName, char* name, unsigned bufferLength);
#endif // MMDEVICE_CLIENT_BUILD

#ifdef MMDEVICE_CLIENT_BUILD
// Function pointer types for module interface functions
// (Not for use by device adapters)
#ifndef MODULE_EXPORTS
typedef void (*fnInitializeModuleData)();
typedef MM::Device* (*fnCreateDevice)(const char*);
typedef void (*fnDeleteDevice)(MM::Device*);
Expand All @@ -116,9 +114,10 @@ extern "C" {
typedef bool (*fnGetDeviceName)(unsigned, char*, unsigned);
typedef bool (*fnGetDeviceType)(const char*, int*);
typedef bool (*fnGetDeviceDescription)(const char*, char*, unsigned);
#endif
#endif // MMDEVICE_CLIENT_BUILD
}

#ifndef MMDEVICE_CLIENT_BUILD

/*
* Functions for use by the device adapter module
Expand All @@ -135,3 +134,5 @@ extern "C" {
* \see InitializeModuleData()
*/
void RegisterDevice(const char* deviceName, MM::DeviceType deviceType, const char* description);

#endif // MMDEVICE_CLIENT_BUILD
9 changes: 7 additions & 2 deletions MMDevice/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ project(
],
)

build_mode_args = []
if get_option('client_interface')
build_mode_args += '-DMMDEVICE_CLIENT_BUILD'
endif

# We intentionally do NOT define NOMINMAX on Windows. MMDevice should compile
# correctly with or without Windows.h's min()/max() macros.

Expand Down Expand Up @@ -43,8 +48,7 @@ mmdevice_lib = static_library(
'MMDevice',
sources: mmdevice_sources,
include_directories: mmdevice_include_dir,
cpp_args: [
'-DMODULE_EXPORTS',
cpp_args: build_mode_args + [
'-D_CRT_SECURE_NO_WARNINGS', # TODO Eliminate the need
],
# MMDevice does not depend on any external library. This is a big advantage
Expand All @@ -58,6 +62,7 @@ mmdevice_lib = static_library(
subdir('unittest')

mmdevice = declare_dependency(
compile_args: build_mode_args,
include_directories: mmdevice_include_dir,
link_with: mmdevice_lib,
)
Expand Down
3 changes: 3 additions & 0 deletions MMDevice/meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
option('client_interface', type: 'boolean', value: false,
description: 'Build for use by MMCore, as opposed to by a device adapter',
)
option('tests', type: 'feature', value: 'enabled', yield: true,
description: 'Build unit tests',
)
1 change: 0 additions & 1 deletion buildscripts/VisualStudio/MMDeviceAdapter.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(MM_MMDEVICE_INCLUDEDIR);$(MM_BOOST_INCLUDEDIR);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
Expand Down

0 comments on commit 39a90f7

Please sign in to comment.