Skip to content

Commit 620c6a5

Browse files
committed
Add OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION cmake option
1 parent 061f942 commit 620c6a5

File tree

12 files changed

+58
-15
lines changed

12 files changed

+58
-15
lines changed

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,31 @@ 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+
By default, the static initializer for each OpenSim library will
181+
call `RegisterTypes_osimCommon`. This has the handy side-effect of
182+
making all available `Object` types available at (post-static-init)
183+
runtime, so that (e.g.) downstream code can immediately load XML
184+
files. However, it has the drawback that downstream code cannot
185+
control when, or in which order, registration happens, which can
186+
(e.g.) prevent setting up application-level logging before registering
187+
things.
188+
189+
If this is set to `ON` (i.e. disable static type registration) then
190+
downstream code *must* manually register the OpenSim types it plans
191+
on using by calling `RegisterTypes_osimLIBRARY` (e.g. `RegisterTypes_osimActuators`),
192+
or by manually registering each type (e.g. `Object::registerType(PhysicalOffsetFrame());`)." OFF)
193+
mark_as_advanced(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)
194+
176195
if(OPENSIM_DISABLE_LOG_FILE)
177196
add_definitions(-DOPENSIM_DISABLE_LOG_FILE=1)
178197
endif()
198+
if(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)
199+
add_definitions(-DOPENSIM_DISABLE_STATIC_TYPE_REGISTRATION=1)
200+
endif()
179201

180202
set(OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT OFF)
181203
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)