Skip to content

Commit cd45f8a

Browse files
committed
[src] Add config.h - use init plugin mechanism - register symbols using *_API macro
1 parent ec312a3 commit cd45f8a

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(CollisionAlgorithm VERSION 0.1 LANGUAGES CXX)
33

4-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
5-
64
find_package(Sofa.Simulation.Core REQUIRED)
75
find_package(Sofa.Component.StateContainer REQUIRED)
86
find_package(Sofa.Component.Constraint.Lagrangian.Solver REQUIRED)
@@ -11,6 +9,9 @@ find_package(Sofa.GL REQUIRED)
119
set(COLLISIONALGORITHM_SRC "src/${PROJECT_NAME}")
1210

1311
set(HEADER_FILES
12+
${COLLISIONALGORITHM_SRC}/config.h.in
13+
${COLLISIONALGORITHM_SRC}/initCollisionAlgorithm.h
14+
1415
${COLLISIONALGORITHM_SRC}/BaseAABBBroadPhase.h
1516
${COLLISIONALGORITHM_SRC}/BaseAlgorithm.h
1617
${COLLISIONALGORITHM_SRC}/BaseElement.h
@@ -61,7 +62,7 @@ set(HEADER_FILES
6162
)
6263

6364
set(SOURCE_FILES
64-
${COLLISIONALGORITHM_SRC}/initPlugin.cpp
65+
${COLLISIONALGORITHM_SRC}/initCollisionAlgorithm.cpp
6566

6667
${COLLISIONALGORITHM_SRC}/CollisionPipeline.cpp
6768

src/CollisionAlgorithm/config.h.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <sofa/config.h>
4+
#include <sofa/config/sharedlibrary_defines.h>
5+
6+
#define COLLISIONALGORITHM_VERSION @PROJECT_VERSION@
7+
8+
#ifdef SOFA_BUILD_COLLISIONALGORITHM
9+
# define SOFA_TARGET @PROJECT_NAME@
10+
# define SOFA_COLLISIONALGORITHM_API SOFA_EXPORT_DYNAMIC_LIBRARY
11+
#else
12+
# define SOFA_COLLISIONALGORITHM_API SOFA_IMPORT_DYNAMIC_LIBRARY
13+
#endif
14+
15+
namespace sofa::collisionalgorithm
16+
{
17+
constexpr const char* MODULE_NAME = "@PROJECT_NAME@";
18+
constexpr const char* MODULE_VERSION = "@PROJECT_VERSION@";
19+
}

src/CollisionAlgorithm/initPlugin.cpp renamed to src/CollisionAlgorithm/initCollisionAlgorithm.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <CollisionAlgorithm/initCollisionAlgorithm.h>
2+
13
#include <sofa/core/ObjectFactory.h>
24
#include <sofa/helper/system/FileRepository.h>
35
#include <sofa/helper/system/PluginManager.h>
@@ -34,28 +36,25 @@ extern void registerPointGeometry(sofa::core::ObjectFactory* factory);
3436
extern void registerEdgeGeometry(sofa::core::ObjectFactory* factory);
3537
extern void registerTriangleGeometry(sofa::core::ObjectFactory* factory);
3638
extern void registerTetrahedronGeometry(sofa::core::ObjectFactory* factory);
37-
} // namespace sofa::collisionalgorithm
38-
39-
namespace sofa::component
40-
{
41-
42-
// Here are just several convenient functions to help user to know what contains the plugin
4339

4440
extern "C"
4541
{
46-
void initExternalModule();
47-
const char* getModuleName();
48-
const char* getModuleVersion();
49-
const char* getModuleLicense();
50-
const char* getModuleDescription();
51-
void registerObjects(sofa::core::ObjectFactory* factory);
42+
SOFA_COLLISIONALGORITHM_API void initExternalModule();
43+
SOFA_COLLISIONALGORITHM_API const char* getModuleName();
44+
SOFA_COLLISIONALGORITHM_API const char* getModuleVersion();
45+
SOFA_COLLISIONALGORITHM_API const char* getModuleLicense();
46+
SOFA_COLLISIONALGORITHM_API const char* getModuleDescription();
47+
SOFA_COLLISIONALGORITHM_API void registerObjects(sofa::core::ObjectFactory* factory);
5248
}
5349

5450
void initCollisionAlgorithm()
5551
{
5652
static bool first = true;
5753
if (first)
5854
{
55+
// make sure that this plugin is registered into the PluginManager
56+
sofa::helper::system::PluginManager::getInstance().registerPlugin(MODULE_NAME);
57+
5958
first = false;
6059
#ifdef PLUGIN_DATA_DIR
6160
sofa::helper::system::DataRepository.addLastPath(std::string(QUOTE(PLUGIN_DATA_DIR)));
@@ -70,7 +69,7 @@ void initExternalModule()
7069
initCollisionAlgorithm();
7170
}
7271

73-
const char* getModuleName() { return "CollisionAlgorithm"; }
72+
const char* getModuleName() { return MODULE_NAME; }
7473

7574
const char* getModuleVersion()
7675
{
@@ -87,7 +86,6 @@ const char* getModuleDescription() { return "Plugin for collision detection"; }
8786

8887
void registerObjects(sofa::core::ObjectFactory* factory)
8988
{
90-
using namespace sofa::collisionalgorithm;
9189
// Register CollisionPipeline
9290
registerCollisionLoop(factory);
9391
// Register Algorithms
@@ -107,4 +105,4 @@ void registerObjects(sofa::core::ObjectFactory* factory)
107105
registerTetrahedronGeometry(factory);
108106
}
109107

110-
} // namespace sofa::component
108+
} // namespace collisionalgorithm
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
#include <CollisionAlgorithm/config.h>
3+
4+
namespace collisionalgorithm
5+
{
6+
void SOFA_COLLISIONALGORITHM_API initCollisionAlgorithm();
7+
} // namespace collisionalgorithm

0 commit comments

Comments
 (0)