Skip to content

Commit

Permalink
Hide symbols in backend libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jan 11, 2025
1 parent cdf8404 commit aac33c8
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions .utils/make/intrometry.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ update_mcap:
-not -wholename "${MCAP_DIR}/cpp" \
-not -wholename "${MCAP_DIR}" \
| xargs rm -rf
cp pjmsg_mcap/src/3rdparty/mcap_visibility.hpp ${MCAP_DIR}/cpp/mcap/include/mcap/visibility.hpp

update_fastcdr:
-git remote add fastcdr https://github.com/eProsima/Fast-CDR.git --no-tags
Expand Down
6 changes: 5 additions & 1 deletion frontend/include/intrometry/backend/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include <memory>

#define INTROMETRY_PUBLIC __attribute__((visibility("default")))
#define INTROMETRY_HIDDEN __attribute__((visibility("hidden")))


namespace intrometry::backend
{
template <typename... t_String>
Expand All @@ -29,7 +33,7 @@ namespace intrometry::backend
std::string getDateString();


class RateTimer
class INTROMETRY_HIDDEN RateTimer
{
protected:
class Implementation;
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace

namespace intrometry::backend
{
uint64_t now()
INTROMETRY_HIDDEN uint64_t now()
{
return (std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}


uint32_t getRandomUInt32()
INTROMETRY_HIDDEN uint32_t getRandomUInt32()
{
std::mt19937 gen((std::random_device())());

Expand All @@ -47,7 +47,7 @@ namespace intrometry::backend
}


std::string getRandomId(const std::size_t length)
INTROMETRY_HIDDEN std::string getRandomId(const std::size_t length)
{
std::mt19937 gen((std::random_device())());

Expand All @@ -61,7 +61,7 @@ namespace intrometry::backend
}


std::string normalizeId(const std::string &input_id)
INTROMETRY_HIDDEN std::string normalizeId(const std::string &input_id)
{
std::string result;
result.resize(input_id.size());
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace intrometry::backend
}


std::string getDateString()
INTROMETRY_HIDDEN std::string getDateString()
{
const std::time_t date_now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::stringstream date_stream;
Expand Down
7 changes: 7 additions & 0 deletions pjmsg_mcap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ else()
endif()
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN hidden)


find_package(intrometry_frontend REQUIRED)
find_package(thread_supervisor REQUIRED)
find_package(ariles2-namevalue2 REQUIRED)


add_subdirectory(src/3rdparty/)

if(CCWS_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CCWS_CLANG_TIDY}" CACHE STRING "" FORCE)
endif()


add_library(${PROJECT_NAME} SHARED
src/intrometry.cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME pjmsg_mcap)
#target_link_options(${PROJECT_NAME} PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/linker_version_script.map")
target_link_libraries(${PROJECT_NAME}
PUBLIC intrometry::frontend
PRIVATE intrometry::backend
Expand Down
5 changes: 3 additions & 2 deletions pjmsg_mcap/include/intrometry/pjmsg_mcap/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#include <filesystem>

#include <intrometry/sink.h>
#include <intrometry/backend/utils.h>


namespace intrometry::pjmsg_mcap
{
namespace sink
{
class Parameters
class INTROMETRY_PUBLIC Parameters
{
public:
/**
Expand Down Expand Up @@ -50,7 +51,7 @@ namespace intrometry::pjmsg_mcap
/**
* @brief Publish data.
*/
class Sink : public SinkPIMPLBase<sink::Parameters, sink::Implementation>
class INTROMETRY_PUBLIC Sink : public SinkPIMPLBase<sink::Parameters, sink::Implementation>
{
public:
using SinkPIMPLBase::SinkPIMPLBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# define MCAP_PUBLIC MCAP_IMPORT
# endif
#else
# define MCAP_EXPORT __attribute__((visibility("default")))
# define MCAP_EXPORT __attribute__((visibility("hidden")))
# define MCAP_IMPORT
# if __GNUC__ >= 4
# define MCAP_PUBLIC __attribute__((visibility("default")))
# define MCAP_PUBLIC __attribute__((visibility("hidden")))
# else
# define MCAP_PUBLIC
# endif
Expand Down
24 changes: 24 additions & 0 deletions pjmsg_mcap/src/3rdparty/mcap_visibility.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#if defined _WIN32 || defined __CYGWIN__
# ifdef __GNUC__
# define MCAP_EXPORT __attribute__((dllexport))
# define MCAP_IMPORT __attribute__((dllimport))
# else
# define MCAP_EXPORT __declspec(dllexport)
# define MCAP_IMPORT __declspec(dllimport)
# endif
# ifdef MCAP_IMPLEMENTATION
# define MCAP_PUBLIC MCAP_EXPORT
# else
# define MCAP_PUBLIC MCAP_IMPORT
# endif
#else
# define MCAP_EXPORT __attribute__((visibility("hidden")))
# define MCAP_IMPORT
# if __GNUC__ >= 4
# define MCAP_PUBLIC __attribute__((visibility("hidden")))
# else
# define MCAP_PUBLIC
# endif
#endif
4 changes: 4 additions & 0 deletions pjmsg_topic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ else()
endif()
endif()

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN hidden)


find_package(intrometry_frontend REQUIRED)
find_package(rclcpp REQUIRED)
find_package(plotjuggler_msgs REQUIRED)
Expand Down
5 changes: 3 additions & 2 deletions pjmsg_topic/include/intrometry/pjmsg_topic/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#pragma once

#include <intrometry/sink.h>
#include <intrometry/backend/utils.h>


namespace intrometry::pjmsg_topic
{
namespace sink
{
class Parameters
class INTROMETRY_PUBLIC Parameters
{
public:
/**
Expand All @@ -42,7 +43,7 @@ namespace intrometry::pjmsg_topic
/**
* @brief Publish data.
*/
class Sink : public SinkPIMPLBase<sink::Parameters, sink::Implementation>
class INTROMETRY_PUBLIC Sink : public SinkPIMPLBase<sink::Parameters, sink::Implementation>
{
public:
using SinkPIMPLBase::SinkPIMPLBase;
Expand Down

0 comments on commit aac33c8

Please sign in to comment.