Skip to content

Commit

Permalink
Hide symbols from shared libraries by default and support DLL creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Feb 15, 2024
1 parent f2f9398 commit ea6feb4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ endif()

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

include(GenerateExportHeader)
add_library(rsl
src/parameter_validators.cpp
src/random.cpp
)
add_library(rsl::rsl ALIAS rsl)
target_compile_features(rsl PUBLIC cxx_std_17)
target_include_directories(rsl PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
target_include_directories(rsl PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
)
target_link_libraries(rsl PUBLIC
Eigen3::Eigen
fmt::fmt
rclcpp::rclcpp
tcb_span::tcb_span
tl_expected::tl_expected
)
set_target_properties(rsl PROPERTIES CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN YES)
generate_export_header(rsl EXPORT_FILE_NAME include/rsl/export.hpp)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(rsl PUBLIC RSL_STATIC_DEFINE)
endif()

add_subdirectory(docs)

Expand All @@ -41,7 +50,7 @@ endif()
include(CMakePackageConfigHelpers)

install(
DIRECTORY include/
DIRECTORY include/ ${PROJECT_BINARY_DIR}/include/
DESTINATION include/rsl
)
install(
Expand Down
3 changes: 2 additions & 1 deletion include/rsl/parameter_validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <rsl/algorithm.hpp>
#include <rsl/static_string.hpp>
#include <rsl/static_vector.hpp>
#include <rsl/export.hpp>

#include <rcl_interfaces/msg/set_parameters_result.hpp>
#include <rclcpp/parameter.hpp>
Expand Down Expand Up @@ -298,7 +299,7 @@ template <typename T>
/**
* @brief Convert the result of a validator function into a SetParametersResult msg
*/
[[nodiscard]] auto to_parameter_result_msg(tl::expected<void, std::string> const& result)
[[nodiscard]] RSL_EXPORT auto to_parameter_result_msg(tl::expected<void, std::string> const& result)
-> rcl_interfaces::msg::SetParametersResult;

} // namespace rsl
6 changes: 4 additions & 2 deletions include/rsl/random.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <rsl/export.hpp>

#include <Eigen/Geometry>
#include <cassert>
#include <random>
Expand All @@ -22,7 +24,7 @@ namespace rsl {
*
* @return Seeded random number generator
*/
auto rng(std::seed_seq seed_sequence = {}) -> std::mt19937&;
RSL_EXPORT auto rng(std::seed_seq seed_sequence = {}) -> std::mt19937&;

/**
* @brief Get a uniform real number in a given range
Expand Down Expand Up @@ -63,6 +65,6 @@ template <typename IntType>
* @brief Generate a random unit quaternion of doubles
* @return Random unit quaternion
*/
[[nodiscard]] auto random_unit_quaternion() -> Eigen::Quaterniond;
[[nodiscard]] RSL_EXPORT auto random_unit_quaternion() -> Eigen::Quaterniond;

} // namespace rsl
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ find_package(Catch2 3.5.0 REQUIRED)
find_package(range-v3 REQUIRED)

# Test library
include(GenerateExportHeader)
add_executable(test-rsl
algorithm.cpp
monad.cpp
Expand Down

0 comments on commit ea6feb4

Please sign in to comment.