Skip to content

Commit

Permalink
Add OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION cmake option
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Feb 6, 2025
1 parent 061f942 commit 620c6a5
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 15 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,31 @@ By default, any application linking to osimCommon will create an
written by OpenSim (incl. during static initialization) are written to
both this file and the standard output streams." OFF)

option(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
"Disable OpenSim from registering bundled `Object` types at static
initialization time.
By default, the static initializer for each OpenSim library will
call `RegisterTypes_osimCommon`. This has the handy side-effect of
making all available `Object` types available at (post-static-init)
runtime, so that (e.g.) downstream code can immediately load XML
files. However, it has the drawback that downstream code cannot
control when, or in which order, registration happens, which can
(e.g.) prevent setting up application-level logging before registering
things.
If this is set to `ON` (i.e. disable static type registration) then
downstream code *must* manually register the OpenSim types it plans
on using by calling `RegisterTypes_osimLIBRARY` (e.g. `RegisterTypes_osimActuators`),
or by manually registering each type (e.g. `Object::registerType(PhysicalOffsetFrame());`)." OFF)
mark_as_advanced(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)

if(OPENSIM_DISABLE_LOG_FILE)
add_definitions(-DOPENSIM_DISABLE_LOG_FILE=1)
endif()
if(OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION)
add_definitions(-DOPENSIM_DISABLE_STATIC_TYPE_REGISTRATION=1)
endif()

set(OPENSIM_BUILD_INDIVIDUAL_APPS_DEFAULT OFF)
if(WIN32)
Expand Down
5 changes: 3 additions & 2 deletions OpenSim/Actuators/RegisterTypes_osimActuators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
using namespace OpenSim;
using namespace std;

static osimActuatorsInstantiator instantiator;

#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimActuatorsInstantiator instantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
4 changes: 3 additions & 1 deletion OpenSim/Analyses/RegisterTypes_osimAnalyses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
using namespace OpenSim;
using namespace std;

static osimAnalysesInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimAnalysesInstantiator instantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
7 changes: 4 additions & 3 deletions OpenSim/Common/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,8 @@ extern "C" OSIMCOMMON_API void RegisterTypes_osimCommon();
void osimCommonInstantiator::registerDllClasses()
{
RegisterTypes_osimCommon();
}

static osimCommonInstantiator instantiator;
}
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimCommonInstantiator instantiator;
#endif
/// @endcond
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
using namespace std;
using namespace OpenSim;

static osimExampleComponentsInstantiator osimExampleComponentsInstantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimExampleComponentsInstantiator osimExampleComponentsInstantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

using namespace OpenSim;

static osimMocoCustomEffortGoalInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimMocoCustomEffortGoalInstantiator instantiator;
#endif

OSIMMOCOCUSTOMEFFORTGOAL_API void RegisterTypes_osimMocoCustomEffortGoal() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
using namespace OpenSim;
using namespace std;

static dllObjectInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static dllObjectInstantiator instantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
using namespace OpenSim;
using namespace std;

static dllPluginObjectInstantiator dInstantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static dllPluginObjectInstantiator dInstantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
4 changes: 3 additions & 1 deletion OpenSim/Moco/RegisterTypes_osimMoco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@

using namespace OpenSim;

static osimMocoInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimMocoInstantiator instantiator;
#endif

OSIMMOCO_API void RegisterTypes_osimMoco() {
try {
Expand Down
5 changes: 4 additions & 1 deletion OpenSim/OpenSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ class osimInstantiator
}
};

static osimInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimInstantiator instantiator;
#endif

#endif // _opensim_h_
4 changes: 3 additions & 1 deletion OpenSim/Simulation/RegisterTypes_osimSimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
using namespace std;
using namespace OpenSim;

static osimSimulationInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimSimulationInstantiator instantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down
6 changes: 4 additions & 2 deletions OpenSim/Tools/RegisterTypes_osimTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
using namespace std;
using namespace OpenSim;

static osimToolsInstantiator instantiator;
#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimToolsInstantiator instantiator;
#endif

//_____________________________________________________________________________
/**
Expand Down Expand Up @@ -125,4 +127,4 @@ osimToolsInstantiator::osimToolsInstantiator()
void osimToolsInstantiator::registerDllClasses()
{
RegisterTypes_osimTools();
}
}

0 comments on commit 620c6a5

Please sign in to comment.