Skip to content

Commit

Permalink
[build] Set up symbol visibility for dart core
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Apr 2, 2024
1 parent 5ba1e72 commit db2dee9
Show file tree
Hide file tree
Showing 133 changed files with 507 additions and 278 deletions.
18 changes: 9 additions & 9 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ IncludeCategories:
Priority: 22
- Regex: '^<dart\/utils\/.*\.h(pp)?>$'
Priority: 23
- Regex: '^<dart\/simulation\/.*\.h(pp)?>$'
- Regex: '^<dart\/Export.hpp>$'
Priority: 24
- Regex: '^<dart\/constraint\/.*\.h(pp)?>$'
- Regex: '^<dart\/simulation\/.*\.h(pp)?>$'
Priority: 25
- Regex: '^<dart\/collision\/.*\.h(pp)?>$'
- Regex: '^<dart\/constraint\/.*\.h(pp)?>$'
Priority: 26
- Regex: '^<dart\/dynamics\/.*\.h(pp)?>$'
- Regex: '^<dart\/collision\/.*\.h(pp)?>$'
Priority: 27
- Regex: '^<dart\/optimizer\/.*\.h(pp)?>$'
- Regex: '^<dart\/dynamics\/.*\.h(pp)?>$'
Priority: 28
- Regex: '^<dart\/lcpsolver\/.*\.h(pp)?>$'
- Regex: '^<dart\/optimizer\/.*\.h(pp)?>$'
Priority: 29
- Regex: '^<dart\/integration\/.*\.h(pp)?>$'
- Regex: '^<dart\/lcpsolver\/.*\.h(pp)?>$'
Priority: 30
- Regex: '^<dart\/math\/.*\.h(pp)?>$'
- Regex: '^<dart\/integration\/.*\.h(pp)?>$'
Priority: 31
- Regex: '^<dart\/common\/.*\.h(pp)?>$'
- Regex: '^<dart\/math\/.*\.h(pp)?>$'
Priority: 32
- Regex: '^<dart\/common\/.*\.h(pp)?>$'
Priority: 33
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ on:

jobs:
build:
name: win-${{ matrix.build_type }}
name: win-${{ matrix.build_type }}-shared_libs=${{ matrix.build_shared_libs }}
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
toolset: [""]
build_type: [Release]
build_shared_libs: [OFF] # TODO(JS): Add ON once shared lib build is resolved
build_shared_libs: [ON, OFF]

steps:
- name: Checkout
Expand Down Expand Up @@ -73,7 +73,6 @@ jobs:
-G "Visual Studio 17 2022" ^
-A x64 ^
-Wno-dev ${{ matrix.toolset }} ^
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ^
-DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" ^
-DDART_MSVC_DEFAULT_OPTIONS=ON ^
-DDART_VERBOSE=ON ^
Expand Down
136 changes: 136 additions & 0 deletions cmake/dart_defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,142 @@ function(dart_print_options)
message(STATUS "")
endfunction()

# cmake-format: off
# dart_check_compiler_visibility(<output_variable>)
#
# Macro to check for visibility capability in compiler
# cmake-format: on
macro(dart_check_compiler_visibility variable)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden ${variable})
endmacro()

# dart_generate_export_header(
# TARGET_NAME <target_name>
# DESTINATION <dir_name>
# INCLUDE_DIR <dir_name>
# EXPORT_FILE_NAME <file_name>
# [BASE_NAME <base_name>]
# [EXPORT_ALL_SYMBOLS_BY_DEFAULT]
# )
#
# Function to create an export header for control of binary symbols visibility
#
function(dart_generate_export_header)
set(prefix _ARG)
set(options EXPORT_ALL_SYMBOLS_BY_DEFAULT)
set(oneValueArgs
TARGET_NAME
DESTINATION
EXPORT_FILE_NAME
BASE_NAME
BASE_DIR
)
set(multiValueArgs)
cmake_parse_arguments(
"${prefix}"
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)

# Check required argument
if(NOT _ARG_TARGET_NAME)
message(FATAL_ERROR "DEVELOPER ERROR: You must specify TARGET_NAME!")
return()
endif()
if(NOT _ARG_DESTINATION)
message(FATAL_ERROR "DEVELOPER ERROR: You must specify DESTINATION!")
return()
endif()
if(NOT _ARG_EXPORT_FILE_NAME)
message(FATAL_ERROR "DEVELOPER ERROR: You must specify EXPORT_FILE_NAME!")
return()
endif()

# Check if target is valid
if(NOT TARGET ${_ARG_TARGET_NAME})
message(
FATAL_ERROR
"DEVELOPER ERROR: Invalid target "
"\"${_ARG_TARGET_NAME}\" is passed! "
"Make sure this function is called after the target is defined by "
"add_library(<target> ...).")
return()
endif()

# Hide symbols by default
if(UNIX AND NOT _ARG_EXPORT_ALL_SYMBOLS_BY_DEFAULT)
dart_check_compiler_visibility(compiler_supports_visibility)
if(compiler_supports_visibility)
target_compile_options(${_ARG_TARGET_NAME} PRIVATE -fvisibility=hidden)
endif()
endif()

# Base name
if(_ARG_BASE_NAME)
set(base_name ${_ARG_BASE_NAME})
else()
set(base_name "${_ARG_TARGET_NAME}")
string(REPLACE "-" "_" base_name ${base_name})
endif()
string(TOUPPER ${base_name} base_name)

# Set up paths
set(export_file_path "${_ARG_DESTINATION}/${_ARG_EXPORT_FILE_NAME}")
set(export_detail_file_path "${_ARG_DESTINATION}/detail/${_ARG_EXPORT_FILE_NAME}")

# Generate CMake's default export header
include(GenerateExportHeader)
generate_export_header(
${_ARG_TARGET_NAME}
EXPORT_MACRO_NAME DETAIL_${base_name}_API
EXPORT_FILE_NAME ${export_detail_file_path}
DEPRECATED_MACRO_NAME _DART_DEPRECATED
)

# Generate final export header
file(
WRITE ${export_file_path}
"// This file is automatically generated by ${PROJECT_NAME}.\n"
"\n"
"#pragma once\n"
"\n"
"/**\n"
" * @brief Apply this macro to classes and functions that will need to be exposed\n"
" to the consumer libraries or programs.\n"
" */\n"
"#define ${base_name}_API \\\n"
" DETAIL_${base_name}_API\n"
"\n"
"#ifdef _MSC_VER\n"
" #define ${base_name}_TEMPL_INST_DECL_API\n"
"#else\n"
" #define ${base_name}_TEMPL_INST_DECL_API ${base_name}_API\n"
"#endif\n"
"\n"
"#ifdef _MSC_VER\n"
" #define ${base_name}_TEMPL_INST_DEF_API ${base_name}_API\n"
"#else\n"
" #define ${base_name}_TEMPL_INST_DEF_API\n"
"#endif\n"
"\n"
"#include \"detail/${_ARG_EXPORT_FILE_NAME}\"\n"
)

# Install generated export files
set(include_base_path ${CMAKE_INSTALL_INCLUDEDIR}/${org_name}/${project_name}${project_version_major})
set(export_install_path "${include_base_path}/${_ARG_BASE_DIR}")
set(detail_export_install_path "${export_install_path}/detail/")
install(FILES "${export_file_path}"
DESTINATION "${export_install_path}"
)
install(FILES "${export_detail_file_path}"
DESTINATION "${detail_export_install_path}"
)
endfunction()

function(dart_library)
set(prefix _ARG)
set(options
Expand Down
7 changes: 7 additions & 0 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ get_property(dart_core_sources GLOBAL PROPERTY DART_CORE_SOURCES)

# Add target
dart_add_library(dart ${dart_core_headers} ${dart_core_sources})
dart_generate_export_header(
TARGET_NAME dart
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
EXPORT_FILE_NAME Export.hpp
BASE_NAME DART
BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
)
target_include_directories(dart BEFORE
PUBLIC
$<BUILD_INTERFACE:${DART_SOURCE_DIR}>
Expand Down
5 changes: 4 additions & 1 deletion dart/collision/CollisionDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONDETECTOR_HPP_
#define DART_COLLISION_COLLISIONDETECTOR_HPP_

#include <dart/Export.hpp>

#include <dart/collision/CollisionOption.hpp>
#include <dart/collision/CollisionResult.hpp>
#include <dart/collision/Contact.hpp>
Expand All @@ -56,7 +58,8 @@ 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:
friend class CollisionObject;
Expand Down
8 changes: 5 additions & 3 deletions dart/collision/CollisionFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONFILTER_HPP_
#define DART_COLLISION_COLLISIONFILTER_HPP_

#include <dart/Export.hpp>

#include <dart/collision/detail/UnorderedPairs.hpp>

#include <dart/common/Deprecated.hpp>
Expand All @@ -47,7 +49,7 @@ namespace collision {

class CollisionObject;

class CollisionFilter
class DART_API CollisionFilter
{
public:
/// Destructor.
Expand All @@ -68,7 +70,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 @@ -90,7 +92,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
4 changes: 3 additions & 1 deletion dart/collision/CollisionGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONGROUP_HPP_
#define DART_COLLISION_COLLISIONGROUP_HPP_

#include <dart/Export.hpp>

#include <dart/collision/CollisionOption.hpp>
#include <dart/collision/CollisionResult.hpp>
#include <dart/collision/DistanceOption.hpp>
Expand All @@ -52,7 +54,7 @@
namespace dart {
namespace collision {

class CollisionGroup
class DART_API CollisionGroup
{
public:
/// Constructor
Expand Down
4 changes: 3 additions & 1 deletion dart/collision/CollisionObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONOBJECT_HPP_
#define DART_COLLISION_COLLISIONOBJECT_HPP_

#include <dart/Export.hpp>

#include <dart/collision/SmartPointer.hpp>

#include <dart/dynamics/SmartPointer.hpp>
Expand All @@ -42,7 +44,7 @@
namespace dart {
namespace collision {

class CollisionObject
class DART_API CollisionObject
{
public:
friend class CollisionGroup;
Expand Down
4 changes: 3 additions & 1 deletion dart/collision/CollisionOption.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONOPTION_HPP_
#define DART_COLLISION_COLLISIONOPTION_HPP_

#include <dart/Export.hpp>

#include <memory>

#include <cstddef>
Expand All @@ -42,7 +44,7 @@ namespace collision {

class CollisionFilter;

struct CollisionOption
struct DART_API CollisionOption
{
/// Flag whether the collision detector computes contact information (contact
/// point, normal, and penetration depth). If it is set to false, only the
Expand Down
4 changes: 3 additions & 1 deletion dart/collision/CollisionResult.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_COLLISIONRESULT_HPP_
#define DART_COLLISION_COLLISIONRESULT_HPP_

#include <dart/Export.hpp>

#include <dart/collision/Contact.hpp>

#include <unordered_set>
Expand All @@ -49,7 +51,7 @@ class ShapeFrame;

namespace collision {

class CollisionResult
class DART_API CollisionResult
{
public:
/// Add one contact
Expand Down
4 changes: 3 additions & 1 deletion dart/collision/Contact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#ifndef DART_COLLISION_CONTACT_HPP_
#define DART_COLLISION_CONTACT_HPP_

#include <dart/Export.hpp>

#include <dart/collision/SmartPointer.hpp>

#include <dart/dynamics/SmartPointer.hpp>
Expand All @@ -43,7 +45,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,
Expand Down
Loading

0 comments on commit db2dee9

Please sign in to comment.