Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ visibility support #1040

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
97468c3
Add export.h and hide symbols by default
jslee02 Mar 22, 2018
7e82bcd
Apply export macros
jslee02 Mar 22, 2018
9129ad6
Add DART_HIDE_ALL_SYMBOLS option
jslee02 Mar 22, 2018
a38ca13
Code format
jslee02 Mar 22, 2018
4dd81fd
Export missing ASSIMP definitions -- for test
jslee02 Mar 22, 2018
e3fd90e
Rename DART_EXPORT to DART_API
jslee02 Mar 22, 2018
024ac5a
Use manually written export.hpp
jslee02 Mar 22, 2018
9141345
Use unique export preprocessors per component
jslee02 Mar 22, 2018
c5eb4be
Update export preprocessor per components accordingly
jslee02 Mar 22, 2018
12aec1a
Minor cleanup
jslee02 Mar 22, 2018
e3f17f2
Update changelog
jslee02 Mar 22, 2018
cc638e0
Fix installation of export headers
jslee02 Mar 23, 2018
ed9a5df
Fix use of CMake variable
jslee02 Mar 23, 2018
d8de131
Fix install path of export.h
jslee02 Mar 23, 2018
11330ed
Use template file for export.hpp
jslee02 Mar 23, 2018
cec1d7c
Change naming pattern: DART_DETAIL_ --> DETAIL_DART_
jslee02 Mar 23, 2018
698a4ed
Hide symbols by default when dart_add_export_file() is used
jslee02 Mar 23, 2018
3da6e78
Rename dart_add_export_file to dart_generate_export_header
jslee02 Mar 23, 2018
f43af8c
Merge branch 'release-6.4' into build/visibility
jslee02 Mar 24, 2018
7af2a71
Merge remote-tracking branch 'origin/release-6.5' into build/visibility
jslee02 Apr 28, 2018
73e98ec
Add missing DART_API
jslee02 Apr 28, 2018
ff49098
Fix accidentally pushed commit
jslee02 Apr 28, 2018
7dce12d
Update CHANGELOG.md
jslee02 Apr 28, 2018
98444dd
Fix warnings per clang 9.1.0
jslee02 Apr 28, 2018
5f9fd41
Add more missing DART_API
jslee02 Apr 29, 2018
91d089e
Merge remote-tracking branch 'origin/release-6.5' into build/visibility
jslee02 Apr 29, 2018
ee0063c
Use DETAIL_DART_DEPRECATED
jslee02 Apr 30, 2018
9facf40
Add missing header
jslee02 Apr 30, 2018
a521359
Merge branch 'release-6.5' into build/visibility
jslee02 May 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

* Added World::hasSkeleton(): [#1050](https://github.com/dartsim/dart/pull/1050)

* Build system

* Added preprocessors for controlling symbol visibility: [#1040](https://github.com/dartsim/dart/pull/1040)

### [DART 6.4.0 (2018-03-26)](https://github.com/dartsim/dart/milestone/39?closed=1)

* Common
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ set(DART_MINOR_VERSION "5")
set(DART_PATCH_VERSION "0")
set(DART_VERSION "${DART_MAJOR_VERSION}.${DART_MINOR_VERSION}.${DART_PATCH_VERSION}")
set(DART_PKG_DESC "Dynamic Animation and Robotics Toolkit.")
set(DART_PKG_EXTERNAL_DEPS "eigen, ccd, fcl, assimp, boost")
set(DART_PKG_EXTERNAL_DEPS "eigen, ccd, fcl, assimp, boost") # TODO: outdated

#===============================================================================
# Build options
Expand All @@ -85,6 +85,9 @@ option(DART_ENABLE_SIMD
option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
option(DART_CODECOV "Turn on codecov support" OFF)
option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF)
# Option for some bundle-like build system in order not to expose any DART
# binary symbols in their public ABI
option(DART_HIDE_ALL_SYMBOLS "Hide all binary symbols" OFF)

#===============================================================================
# Print intro
Expand Down
79 changes: 79 additions & 0 deletions cmake/DARTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,82 @@ function(dart_format_add)
endif()
endforeach()
endfunction()

#===============================================================================
# Macro to check for visibility capability in compiler
macro(check_compiler_visibility variable)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden ${variable})
endmacro()

#===============================================================================
# Function to create an export header for control of binary symbols visibility.
#
# dart_generate_export_header(
# <target_name>
# [EXPORT_ALL_SYMBOLS_BY_DEFAULT]
# [BASE_NAME <base_name>]
# [COMPONENT_PATH <component_path>]
# )
function(dart_generate_export_header target_name)
# Parse boolean, unary, and list arguments from input.
# Unparsed arguments can be found in variable ARG_UNPARSED_ARGUMENTS.
set(prefix _geh)
set(options EXPORT_ALL_SYMBOLS_BY_DEFAULT)
set(oneValueArgs BASE_NAME COMPONENT_PATH)
set(multiValueArgs "")
cmake_parse_arguments(
"${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
)

# Hide symbols by default
if(UNIX AND NOT _geh_EXPORT_ALL_SYMBOLS_BY_DEFAULT)
check_compiler_visibility(COMPILER_SUPPORTS_VISIBILITY)
if(COMPILER_SUPPORTS_VISIBILITY)
target_compile_options(${target_name} PRIVATE -fvisibility=hidden)
endif()
endif()

include(GNUInstallDirs)

# Base name
set(base_name "${target_name}")
string(REPLACE "-" "_" base_name ${base_name})
if(_geh_BASE_NAME)
set(base_name ${_geh_BASE_NAME})
endif()
string(TOUPPER ${base_name} base_name_upper)

# Componenet path
set(component_path "dart")
if(_geh_COMPONENT_PATH)
set(component_path "dart/${_geh_COMPONENT_PATH}")
endif()
set(component_detail_export_path "${component_path}/detail/export.h")

# Generate CMake's default export header
include(GenerateExportHeader)
generate_export_header(${target_name}
EXPORT_MACRO_NAME DETAIL_${base_name_upper}_API
EXPORT_FILE_NAME detail/export.h
DEPRECATED_MACRO_NAME DETAIL_${base_name_upper}_DEPRECATED
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/detail/export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${component_path}/detail
COMPONENT headers
)

# Generate final export header
set(header_guard_name ${base_name_upper}_EXPORT_HPP_)
Copy link
Member

@mxgrey mxgrey Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be much cleaner if we created a export.hpp.in and then called configure_file on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I wrote this lines because I thought each component requires individual export.hpp.in, but this is not true.

set(output_path "${CMAKE_CURRENT_BINARY_DIR}/export.hpp")
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/export.hpp.in"
"${output_path}"
@ONLY
)
install(
FILES ${output_path}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${component_path}
COMPONENT headers
)
endfunction()
14 changes: 14 additions & 0 deletions cmake/export.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Automatically generated file by CMake

#ifndef @header_guard_name@
#define @header_guard_name@

#include "@component_detail_export_path@"

#define @base_name_upper@_API\
DETAIL_@base_name_upper@_API

#define @base_name_upper@_DEPRECATED_API(version)\
DETAIL_@base_name_upper@_DEPRECATED_EXPORT

#endif // @header_guard_name@
7 changes: 7 additions & 0 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ if(DART_ENABLE_SIMD)
endif()
endif()

if (DART_HIDE_ALL_SYMBOLS)
target_compile_definitions(dart PUBLIC DART_STATIC_DEFINE)
endif()

# Default component
add_component_targets(
${PROJECT_NAME}
Expand All @@ -174,3 +178,6 @@ if(MSVC)
endif()

install(FILES dart.hpp DESTINATION include/dart/ COMPONENT headers)

# Generate export header
dart_generate_export_header(dart)
8 changes: 4 additions & 4 deletions dart/collision/CollisionDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace collision {

class CollisionObject;

class CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
class DART_API CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
{
public:

Expand Down Expand Up @@ -184,7 +184,7 @@ class CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
};

//==============================================================================
class CollisionDetector::CollisionObjectManager
class DART_API CollisionDetector::CollisionObjectManager
{
public:

Expand All @@ -206,7 +206,7 @@ class CollisionDetector::CollisionObjectManager
};

//==============================================================================
class CollisionDetector::ManagerForUnsharableCollisionObjects final :
class DART_API CollisionDetector::ManagerForUnsharableCollisionObjects final :
public CollisionDetector::CollisionObjectManager
{
public:
Expand Down Expand Up @@ -236,7 +236,7 @@ class CollisionDetector::ManagerForUnsharableCollisionObjects final :
};

//==============================================================================
class CollisionDetector::ManagerForSharableCollisionObjects final :
class DART_API CollisionDetector::ManagerForSharableCollisionObjects final :
public CollisionDetector::CollisionObjectManager
{
public:
Expand Down
7 changes: 4 additions & 3 deletions dart/collision/CollisionFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#ifndef DART_COLLISION_COLLISIONFILTER_HPP_
#define DART_COLLISION_COLLISIONFILTER_HPP_

#include "dart/export.hpp"
#include "dart/common/Deprecated.hpp"
#include "dart/collision/detail/UnorderedPairs.hpp"

Expand All @@ -46,7 +47,7 @@ namespace collision {

class CollisionObject;

class CollisionFilter
class DART_API CollisionFilter
{
public:
/// Returns true if the given two CollisionObjects should be checked by the
Expand All @@ -64,7 +65,7 @@ class CollisionFilter
const CollisionObject* object1, const CollisionObject* object2) const = 0;
};

class CompositeCollisionFilter : public CollisionFilter
class DART_API CompositeCollisionFilter : public CollisionFilter
{
public:
/// Adds a collision filter to this CompositeCollisionFilter.
Expand All @@ -86,7 +87,7 @@ class CompositeCollisionFilter : public CollisionFilter
std::unordered_set<const CollisionFilter*> mFilters;
};

class BodyNodeCollisionFilter : public CollisionFilter
class DART_API BodyNodeCollisionFilter : public CollisionFilter
{
public:
/// Add a BodyNode pair to the blacklist.
Expand Down
2 changes: 1 addition & 1 deletion dart/collision/CollisionGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
namespace dart {
namespace collision {

class CollisionGroup
class DART_API CollisionGroup
{
public:

Expand Down
2 changes: 1 addition & 1 deletion dart/collision/CollisionObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
namespace dart {
namespace collision {

class CollisionObject
class DART_API CollisionObject
{
public:

Expand Down
3 changes: 2 additions & 1 deletion dart/collision/CollisionOption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@

#include <cstddef>
#include <memory>
#include "dart/export.hpp"

namespace dart {
namespace collision {

class CollisionFilter;

struct CollisionOption
struct DART_API CollisionOption
{

/// Flag whether the collision detector computes contact information (contact
Expand Down
2 changes: 1 addition & 1 deletion dart/collision/CollisionResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ShapeFrame;

namespace collision {

class CollisionResult
class DART_API CollisionResult
{
public:

Expand Down
2 changes: 1 addition & 1 deletion dart/collision/Contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace dart {
namespace collision {

/// Contact information
struct Contact
struct DART_API Contact
{
/// Default constructor
Contact();
Expand Down
6 changes: 4 additions & 2 deletions dart/collision/DistanceFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_DISTANCEFILTER_HPP_
#define DART_COLLISION_DISTANCEFILTER_HPP_

#include "dart/export.hpp"

namespace dart {

namespace dynamics {
Expand All @@ -43,13 +45,13 @@ namespace collision {

class CollisionObject;

struct DistanceFilter
struct DART_API DistanceFilter
{
virtual bool needDistance(const CollisionObject* object1,
const CollisionObject* object2) const = 0;
};

struct BodyNodeDistanceFilter : DistanceFilter
struct DART_API BodyNodeDistanceFilter : DistanceFilter
{
bool needDistance(const CollisionObject* object1,
const CollisionObject* object2) const override;
Expand Down
5 changes: 3 additions & 2 deletions dart/collision/DistanceOption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@

#include <cstddef>
#include <memory>
#include "dart/export.hpp"

namespace dart {
namespace collision {

class DistanceFilter;
struct DistanceFilter;

struct DistanceOption
struct DART_API DistanceOption
{
/// Whether to calculate the nearest points.
///
Expand Down
3 changes: 2 additions & 1 deletion dart/collision/DistanceResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define DART_COLLISION_DISTANCE_RESULT_HPP_

#include <Eigen/Dense>
#include "dart/export.hpp"

namespace dart {

Expand All @@ -43,7 +44,7 @@ class ShapeFrame;

namespace collision {

struct DistanceResult
struct DART_API DistanceResult
{
/// Minimum \b singed distance between the checked Shape pairs.
///
Expand Down
3 changes: 2 additions & 1 deletion dart/collision/bullet/BulletCollisionDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <vector>
#include <assimp/scene.h>
#include <btBulletCollisionCommon.h>
#include "dart/collision/bullet/export.hpp"
#include "dart/collision/CollisionDetector.hpp"
#include "dart/collision/bullet/BulletCollisionGroup.hpp"

Expand All @@ -47,7 +48,7 @@ namespace collision {

class BulletCollisionObject;

class BulletCollisionDetector : public CollisionDetector
class DART_COLLISION_BULLET_API BulletCollisionDetector : public CollisionDetector
{
public:

Expand Down
4 changes: 2 additions & 2 deletions dart/collision/bullet/BulletCollisionGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
#include "dart/config.hpp"

#include <btBulletCollisionCommon.h>

#include "dart/collision/bullet/export.hpp"
#include "dart/collision/CollisionGroup.hpp"

namespace dart {
namespace collision {

class BulletCollisionGroup : public CollisionGroup
class DART_COLLISION_BULLET_API BulletCollisionGroup : public CollisionGroup
{
public:

Expand Down
4 changes: 2 additions & 2 deletions dart/collision/bullet/BulletCollisionObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
#include "dart/config.hpp"

#include <btBulletCollisionCommon.h>

#include "dart/collision/bullet/export.hpp"
#include "dart/collision/CollisionObject.hpp"

namespace dart {
namespace collision {

class CollisionObject;

class BulletCollisionObject : public CollisionObject
class DART_COLLISION_BULLET_API BulletCollisionObject : public CollisionObject
{
public:

Expand Down
5 changes: 3 additions & 2 deletions dart/collision/bullet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ add_component(${PROJECT_NAME} ${component_name})
add_component_targets(${PROJECT_NAME} ${component_name} ${target_name})
add_component_dependencies(${PROJECT_NAME} ${component_name} dart)

# Generate export header
dart_generate_export_header(${target_name} COMPONENT_PATH collision/bullet)

# Generate header for this namespace
dart_get_filename_components(header_names "collision_bullet headers" ${hdrs})
dart_generate_include_header_list(
Expand All @@ -81,8 +84,6 @@ configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/bullet.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/bullet.hpp
)

# Install
install(
FILES ${hdrs} ${CMAKE_CURRENT_BINARY_DIR}/bullet.hpp
DESTINATION include/dart/collision/bullet
Expand Down
Loading