Skip to content

Commit

Permalink
Possibly fix some of the linker errors
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Wilson <[email protected]>
  • Loading branch information
scott-wilson committed Aug 9, 2024
1 parent 2739199 commit 8ee921e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bindings/cpp/include/openchecks/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
#include "openchecks/status.h"

namespace OPENCHECKS_NAMESPACE {
class CheckHint {
class OPENCHECKS_API CheckHint {
public:
enum Value : OpenChecksCheckHint {
None = OPENCHECKS_CHECK_HINT_NONE,
Expand Down
56 changes: 56 additions & 0 deletions bindings/cpp/include/openchecks/core.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
#pragma once

#define OPENCHECKS_NAMESPACE openchecks

/// Borrowed from OpenImageIO's export.h
///
/// On Windows, when compiling code that will end up in a DLL, symbols
/// must be marked as 'exported' (i.e. __declspec(dllexport)) or they
/// won't be visible to programs linking against the DLL.
///
/// In addition, when compiling the application code that calls the DLL,
/// if a routine is marked as 'imported' (i.e. __declspec(dllimport)),
/// the compiler can be smart about eliminating a level of calling
/// indirection. But you DON'T want to use __declspec(dllimport) when
/// calling a function from within its own DLL (it will still compile
/// correctly, just not with maximal efficiency). Which is quite the
/// dilemma since the same header file is used by both the library and
/// its clients. Sheesh!
///
/// But on Linux/OSX as well, we want to only have the DSO export the
/// symbols we designate as the public interface. So we link with
/// -fvisibility=hidden to default to hiding the symbols. See
/// http://gcc.gnu.org/wiki/Visibility
///
/// We solve this awful mess by defining these macros:
///
/// OPENCHECKS_API - used for the OpenChecks public API. Normally, assumes
/// that it's being seen by a client of the library, and
/// therefore declare as 'imported'. But if
/// OPENCHECKS_EXPORT is defined (as is done by CMake
/// when compiling the library itself), change the
/// declaration to 'exported'.
/// OPENCHECKS_EXPORT - explicitly exports a symbol that isn't part of the
/// public API but still needs to be visible.
/// OPENCHECKS_LOCAL - explicitly hides a symbol that might otherwise be
/// exported
///
///

#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef OPENCHECKS_STATIC
#define OPENCHECKS_IMPORT
#define OPENCHECKS_EXPORT
#else
#define OPENCHECKS_IMPORT __declspec(dllimport)
#define OPENCHECKS_EXPORT __declspec(dllexport)
#endif
#define OPENCHECKS_LOCAL
#else
#define OPENCHECKS_IMPORT __attribute__((visibility("default")))
#define OPENCHECKS_EXPORT __attribute__((visibility("default")))
#define OPENCHECKS_LOCAL __attribute__((visibility("hidden")))
#endif

#define OPENCHECKS_API OPENCHECKS_EXPORT
// #if defined(OPENCHECKS_EXPORTS)
// #else
// #define OPENCHECKS_API OPENCHECKS_IMPORT
// #endif
2 changes: 1 addition & 1 deletion bindings/cpp/include/openchecks/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace _private {
void destroy_str_fn(struct OpenChecksString *str) { delete[] str->string; }
} // namespace _private

template <class T> class Item : private OpenChecksItem {
template <class T> class OPENCHECKS_API Item : private OpenChecksItem {
public:
Item(const T &value, const std::string &type_hint)
: _value(value), _type_hint(type_hint) {
Expand Down
2 changes: 1 addition & 1 deletion bindings/cpp/include/openchecks/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {
#include "openchecks/item.h"

namespace OPENCHECKS_NAMESPACE {
template <class T> class Items : private OpenChecksItems {
template <class T> class OPENCHECKS_API Items : private OpenChecksItems {
public:
Items();

Expand Down
3 changes: 2 additions & 1 deletion bindings/cpp/include/openchecks/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ extern "C" {
namespace OPENCHECKS_NAMESPACE {
template <class T> class BaseCheck;

template <class T> class CheckResult : private OpenChecksCheckResult {
template <class T>
class OPENCHECKS_API CheckResult : private OpenChecksCheckResult {
public:
friend class BaseCheck<T>;
CheckResult(OPENCHECKS_NAMESPACE::Status status, const std::string &message,
Expand Down
12 changes: 7 additions & 5 deletions bindings/cpp/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ rust_c_artifacts = custom_target(
'--manifest-path', cargo_toml,
'--project-build-root', meson.project_build_root(),
'--current-build-dir', meson.current_build_dir(),
]
],
)
copenchecks_include_dirs = include_directories('../c/include')
copenchecks_dep = declare_dependency(
Expand All @@ -64,12 +64,11 @@ cppopenchecks_lib = library(
dependencies: [copenchecks_dep],
)


pkg = import('pkgconfig')
pkg.generate(
name: meson.project_name(),
description: 'A simple checks framework',
libraries: [cppopenchecks_lib]
libraries: [cppopenchecks_lib],
)

cmake = import('cmake')
Expand All @@ -78,7 +77,10 @@ cmake.write_basic_package_version_file(
version: meson.project_version(),
)
conf = configuration_data()
conf.set_quoted('PACKAGE_INCLUDE_INSTALL_DIR', '${PACKAGE_PREFIX_DIR}' / get_option('includedir'))
conf.set_quoted(
'PACKAGE_INCLUDE_INSTALL_DIR',
'${PACKAGE_PREFIX_DIR}' / get_option('includedir'),
)
cmake.configure_package_config_file(
name: meson.project_name(),
input: 'cmake/cppopenchecks.cmake.in',
Expand All @@ -87,7 +89,7 @@ cmake.configure_package_config_file(

cppopenchecks_dep = declare_dependency(
include_directories: include_directories('include'),
link_with: cppopenchecks_lib
link_with: cppopenchecks_lib,
)

if build_tests
Expand Down

0 comments on commit 8ee921e

Please sign in to comment.