From 393f39de2e344dac0bd7d6e316965454fdafa42c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 31 Jul 2016 19:25:15 +0200 Subject: [PATCH] Let the module registration script return a lambda that will contain all modules, thus removing the static initialization order problem --- src/engine/moduleengine.cpp | 2 +- support/cmake/module_registration.template | 6 ++++-- support/cmake/support_macros.cmake | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index 76611a92cc..7cc15c84d5 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -40,7 +40,7 @@ namespace { namespace openspace { void ModuleEngine::initialize() { - for (OpenSpaceModule* m : AllModules) + for (OpenSpaceModule* m : AllModules()) registerModule(std::unique_ptr(m)); } diff --git a/support/cmake/module_registration.template b/support/cmake/module_registration.template index 5349553d0b..e9f2a382a9 100644 --- a/support/cmake/module_registration.template +++ b/support/cmake/module_registration.template @@ -8,8 +8,10 @@ @MODULE_HEADERS@ namespace openspace { -std::vector AllModules = { -@MODULE_CLASSES@}; +auto AllModules = []() -> std::vector { + return { +@MODULE_CLASSES@ }; +}; } // namespace openspace diff --git a/support/cmake/support_macros.cmake b/support/cmake/support_macros.cmake index 8d05a9628f..5ecebf7b91 100644 --- a/support/cmake/support_macros.cmake +++ b/support/cmake/support_macros.cmake @@ -430,7 +430,7 @@ function (handle_internal_modules) #"#endif\n\n" ) - list(APPEND MODULE_CLASSES " new ${MODULE_NAME},\n") + list(APPEND MODULE_CLASSES " new ${MODULE_NAME},\n") endif () endforeach ()