Skip to content

Commit f96fb71

Browse files
authored
Merge pull request #4012 from opensim-org/feature_opensim-disable-static-type-registration
Add OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION cmake option
2 parents 3aaae00 + d60aea1 commit f96fb71

File tree

12 files changed

+49
-15
lines changed

12 files changed

+49
-15
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,22 @@ By default, any application linking to osimCommon will create an
173173
written by OpenSim (incl. during static initialization) are written to
174174
both this file and the standard output streams." OFF)
175175

176+
option(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
177+
"Disable OpenSim from registering bundled `Object` types at static
178+
initialization time.
179+
180+
If this is set to `ON` (i.e. disable static type registration) then
181+
downstream code *must* manually register the OpenSim types it plans
182+
on using by calling `RegisterTypes_osimLIBRARY` (e.g. `RegisterTypes_osimActuators`),
183+
or by manually registering each type (e.g. `Object::registerType(PhysicalOffsetFrame());`)." OFF)
184+
mark_as_advanced(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)
185+
176186
if(OPENSIM_DISABLE_LOG_FILE)
177187
add_definitions(-DOPENSIM_DISABLE_LOG_FILE=1)
178188
endif()
189+
if(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)
190+
add_definitions(-DOPENSIM_DISABLE_STATIC_TYPE_REGISTRATION=1)
191+
endif()
179192

180193
set(OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT OFF)
181194
if(WIN32)

OpenSim/Actuators/RegisterTypes_osimActuators.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
using namespace OpenSim;
3838
using namespace std;
3939

40-
static osimActuatorsInstantiator instantiator;
41-
40+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
41+
static osimActuatorsInstantiator instantiator;
42+
#endif
4243

4344
//_____________________________________________________________________________
4445
/**

OpenSim/Analyses/RegisterTypes_osimAnalyses.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
using namespace OpenSim;
3232
using namespace std;
3333

34-
static osimAnalysesInstantiator instantiator;
34+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
35+
static osimAnalysesInstantiator instantiator;
36+
#endif
3537

3638
//_____________________________________________________________________________
3739
/**

OpenSim/Common/Object.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,8 @@ extern "C" OSIMCOMMON_API void RegisterTypes_osimCommon();
17471747
void osimCommonInstantiator::registerDllClasses()
17481748
{
17491749
RegisterTypes_osimCommon();
1750-
}
1751-
1752-
static osimCommonInstantiator instantiator;
1750+
}
1751+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
1752+
static osimCommonInstantiator instantiator;
1753+
#endif
17531754
/// @endcond

OpenSim/ExampleComponents/RegisterTypes_osimExampleComponents.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
using namespace std;
3434
using namespace OpenSim;
3535

36-
static osimExampleComponentsInstantiator osimExampleComponentsInstantiator;
36+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
37+
static osimExampleComponentsInstantiator osimExampleComponentsInstantiator;
38+
#endif
3739

3840
//_____________________________________________________________________________
3941
/**

OpenSim/Examples/Moco/exampleMocoCustomEffortGoal/RegisterTypes_osimMocoCustomEffortGoal.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
using namespace OpenSim;
2222

23-
static osimMocoCustomEffortGoalInstantiator instantiator;
23+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
24+
static osimMocoCustomEffortGoalInstantiator instantiator;
25+
#endif
2426

2527
OSIMMOCOCUSTOMEFFORTGOAL_API void RegisterTypes_osimMocoCustomEffortGoal() {
2628
try {

OpenSim/Examples/Plugins/CoupledBushingForceExample/RegisterTypes_osimPlugin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
using namespace OpenSim;
3131
using namespace std;
3232

33-
static dllObjectInstantiator instantiator;
33+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
34+
static dllObjectInstantiator instantiator;
35+
#endif
3436

3537
//_____________________________________________________________________________
3638
/**

OpenSim/Examples/SymbolicExpressionReporter/RegisterTypes_osimExpPlugin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
using namespace OpenSim;
3131
using namespace std;
3232

33-
static dllPluginObjectInstantiator dInstantiator;
33+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
34+
static dllPluginObjectInstantiator dInstantiator;
35+
#endif
3436

3537
//_____________________________________________________________________________
3638
/**

OpenSim/Moco/RegisterTypes_osimMoco.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464

6565
using namespace OpenSim;
6666

67-
static osimMocoInstantiator instantiator;
67+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
68+
static osimMocoInstantiator instantiator;
69+
#endif
6870

6971
OSIMMOCO_API void RegisterTypes_osimMoco() {
7072
try {

OpenSim/OpenSim.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ class osimInstantiator
4242
}
4343
};
4444

45-
static osimInstantiator instantiator;
45+
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
46+
static osimInstantiator instantiator;
47+
#endif
48+
4649
#endif // _opensim_h_

0 commit comments

Comments
 (0)