From 70b6770389a8d84bdfd91b7497f83d24e92c987c Mon Sep 17 00:00:00 2001 From: Joel Falcou Date: Fri, 15 Aug 2025 11:19:28 +0200 Subject: [PATCH] Setup visibility handling for librotgen components See merge request oss/rotgen!13 --- CMakeLists.txt | 6 +++- include/rotgen/common/export.hpp | 40 +++++++++++++++++++++++++++ include/rotgen/config.hpp | 3 +- include/rotgen/impl/block_model.hpp | 8 +++--- include/rotgen/impl/map_model.hpp | 8 +++--- include/rotgen/impl/map_operators.hpp | 4 +-- include/rotgen/impl/matrix_model.hpp | 8 +++--- src/block_model.cpp | 6 ++-- src/info.cpp | 3 +- src/map_model.cpp | 6 ++-- src/matrix_model.cpp | 6 ++-- 11 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 include/rotgen/common/export.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index eb622e5..476ba59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,13 +60,17 @@ find_package (Eigen3 3.4 REQUIRED NO_MODULE) ##====================================================================================================================== ## Setup the library's build ##====================================================================================================================== +if(NOT MSVC) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) +endif() + add_library(rotgen SHARED ${SOURCES}) + set_target_properties(rotgen PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(rotgen PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) target_compile_options(rotgen PUBLIC -std=c++20 -Werror -Wall -Wextra -Wshadow -Wunused-variable) target_compile_definitions(rotgen PUBLIC ${ROTGEN_COMPILE_DEFS}) -set_target_properties(rotgen PROPERTIES EXPORT_NAME rotgen) add_library(rotgen::rotgen ALIAS rotgen) target_include_directories(rotgen PUBLIC diff --git a/include/rotgen/common/export.hpp b/include/rotgen/common/export.hpp new file mode 100644 index 0000000..9dce182 --- /dev/null +++ b/include/rotgen/common/export.hpp @@ -0,0 +1,40 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#ifdef ROTGEN_STATIC_DEFINE +# define ROTGEN_EXPORT +# define ROTGEN_NO_EXPORT +#else +# ifndef ROTGEN_EXPORT +# ifdef rotgen_EXPORTS + /* We are building this library */ +# define ROTGEN_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define ROTGEN_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef ROTGEN_NO_EXPORT +# define ROTGEN_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef ROTGEN_DEPRECATED +# define ROTGEN_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef ROTGEN_DEPRECATED_EXPORT +# define ROTGEN_DEPRECATED_EXPORT ROTGEN_EXPORT ROTGEN_DEPRECATED +#endif + +#ifndef ROTGEN_DEPRECATED_NO_EXPORT +# define ROTGEN_DEPRECATED_NO_EXPORT ROTGEN_NO_EXPORT ROTGEN_DEPRECATED +#endif + diff --git a/include/rotgen/config.hpp b/include/rotgen/config.hpp index 363b4d8..99c34b2 100644 --- a/include/rotgen/config.hpp +++ b/include/rotgen/config.hpp @@ -9,6 +9,7 @@ #include #include +#include namespace rotgen { @@ -44,7 +45,7 @@ namespace rotgen namespace detail { - std::ostream& dynamic_info(std::ostream& os); + ROTGEN_EXPORT std::ostream& dynamic_info(std::ostream& os); } } diff --git a/include/rotgen/impl/block_model.hpp b/include/rotgen/impl/block_model.hpp index b08c6f5..0c8935d 100644 --- a/include/rotgen/impl/block_model.hpp +++ b/include/rotgen/impl/block_model.hpp @@ -11,7 +11,7 @@ This file is a X-File to generate various block_impl_* declarations variant */ //================================================================================================== -class CLASSNAME +class ROTGEN_EXPORT CLASSNAME { public: CLASSNAME(SOURCENAME& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj); @@ -72,9 +72,9 @@ class CLASSNAME SOURCENAME mul(TYPE s) const; SOURCENAME div(TYPE s) const; - friend std::ostream& operator<<(std::ostream&,CLASSNAME const&); - friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,CLASSNAME const&); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); const TYPE* data() const; TYPE* data(); diff --git a/include/rotgen/impl/map_model.hpp b/include/rotgen/impl/map_model.hpp index 80cc75b..d2b7b13 100644 --- a/include/rotgen/impl/map_model.hpp +++ b/include/rotgen/impl/map_model.hpp @@ -11,7 +11,7 @@ This file is a X-File to generate various map_impl_* declarations variant */ //================================================================================================== -class CLASSNAME +class ROTGEN_EXPORT CLASSNAME { public: CLASSNAME(TYPE CONST* ptr, Index r, Index c); @@ -82,7 +82,7 @@ class CLASSNAME SOURCENAME mul(TYPE s) const; SOURCENAME div(TYPE s) const; - friend std::ostream& operator<<(std::ostream&,CLASSNAME const&); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,CLASSNAME const&); const TYPE* data() const; #if !defined(USE_CONST) @@ -93,8 +93,8 @@ class CLASSNAME void setConstant(TYPE); #endif - friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); private: struct payload; diff --git a/include/rotgen/impl/map_operators.hpp b/include/rotgen/impl/map_operators.hpp index c6a6d78..2e825c7 100644 --- a/include/rotgen/impl/map_operators.hpp +++ b/include/rotgen/impl/map_operators.hpp @@ -8,7 +8,7 @@ #pragma once #define ROTGEN_DEF_RELOP_PAIR(OP, T1, T2) \ -bool operator OP (T1 const&, T2 const&); \ +ROTGEN_EXPORT bool operator OP (T1 const&, T2 const&); \ inline bool operator OP (T2 const& a, T1 const& b) { return b OP a; } \ /**/ @@ -31,8 +31,6 @@ namespace rotgen { ROTGEN_DEF_RELOP(==) ROTGEN_DEF_RELOP(!=) - // ROTGEN_DEF_RELOP(+) - // ROTGEN_DEF_RELOP(-) } #undef ROTGEN_DEF_RELOP_PAIR diff --git a/include/rotgen/impl/matrix_model.hpp b/include/rotgen/impl/matrix_model.hpp index a842390..05a522b 100644 --- a/include/rotgen/impl/matrix_model.hpp +++ b/include/rotgen/impl/matrix_model.hpp @@ -11,7 +11,7 @@ This file is a X-File to generate various matrix_impl_* declarations variant */ //================================================================================================== -class CLASSNAME +class ROTGEN_EXPORT CLASSNAME { public: CLASSNAME(std::size_t rows = 0, std::size_t cols = 0); @@ -67,9 +67,9 @@ class CLASSNAME CLASSNAME& operator*=(TYPE d); CLASSNAME& operator/=(TYPE d); - friend std::ostream& operator<<(std::ostream&,CLASSNAME const&); - friend bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,CLASSNAME const&); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); const TYPE* data() const; TYPE* data(); diff --git a/src/block_model.cpp b/src/block_model.cpp index d31f344..ea47ebc 100644 --- a/src/block_model.cpp +++ b/src/block_model.cpp @@ -126,17 +126,17 @@ struct CLASSNAME::payload //================================================================================================== // Operators //================================================================================================== - std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) + ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) { return os << m.storage_->data; } - bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) + ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data == rhs.storage_->data; } - bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) + ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data != rhs.storage_->data; } diff --git a/src/info.cpp b/src/info.cpp index e6e13ff..a068266 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -7,10 +7,11 @@ */ //================================================================================================== #include +#include namespace rotgen::detail { - std::ostream& dynamic_info(std::ostream& os) + ROTGEN_EXPORT std::ostream& dynamic_info(std::ostream& os) { if constexpr(rotgen::is_forcing_dynamic_status) return os << "[ROTGEN] - Fully Dynamic mode" << std::endl; else return os << "[ROTGEN] - Flexible mode with" << std::endl; diff --git a/src/map_model.cpp b/src/map_model.cpp index 2c6f030..0e9418a 100644 --- a/src/map_model.cpp +++ b/src/map_model.cpp @@ -146,17 +146,17 @@ //================================================================================================== // Operators //================================================================================================== - std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) + ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) { return os << m.storage_->data; } - bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) + ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data == rhs.storage_->data; } - bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) + ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data != rhs.storage_->data; } diff --git a/src/matrix_model.cpp b/src/matrix_model.cpp index 24ed5ca..fa8fb9e 100644 --- a/src/matrix_model.cpp +++ b/src/matrix_model.cpp @@ -130,17 +130,17 @@ TYPE CLASSNAME::lp_norm(int p) const //================================================================================================== // Operators //================================================================================================== -std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) { return os << m.storage_->data; } -bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) +ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data == rhs.storage_->data; } -bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) +ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) { return lhs.storage_->data != rhs.storage_->data; }