Skip to content

Add OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION cmake option #4012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -173,9 +173,22 @@ 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.

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)
5 changes: 3 additions & 2 deletions OpenSim/Actuators/RegisterTypes_osimActuators.cpp
Original file line number Diff line number Diff line change
@@ -37,8 +37,9 @@
using namespace OpenSim;
using namespace std;

static osimActuatorsInstantiator instantiator;

#ifndef OPENSIM_DISABLE_STATIC_TYPE_REGISTRATION
static osimActuatorsInstantiator instantiator;
#endif

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

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

//_____________________________________________________________________________
/**
7 changes: 4 additions & 3 deletions OpenSim/Common/Object.cpp
Original file line number Diff line number Diff line change
@@ -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
@@ -33,7 +33,9 @@
using namespace std;
using namespace OpenSim;

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

//_____________________________________________________________________________
/**
Original file line number Diff line number Diff line change
@@ -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 {
Original file line number Diff line number Diff line change
@@ -30,7 +30,9 @@
using namespace OpenSim;
using namespace std;

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

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

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

//_____________________________________________________________________________
/**
4 changes: 3 additions & 1 deletion OpenSim/Moco/RegisterTypes_osimMoco.cpp
Original file line number Diff line number Diff line change
@@ -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 {
5 changes: 4 additions & 1 deletion OpenSim/OpenSim.h
Original file line number Diff line number Diff line change
@@ -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
@@ -146,7 +146,9 @@
using namespace std;
using namespace OpenSim;

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

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

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

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