Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit b0e1aaed authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Fixed converter registration in statically linked builds:

Statically linked builds strip all unused objects from their sources. This would be the case for the converters since they are nowhere called explicitly. In order to fix that, we use the same pattern as with the pipeline registration: The CMake build scripts parse all headers for an explicit template instantiation of a ConversionFunctionRegistrar. All these headers are included from the generated gen_converterregistration.h file, which is itself included from imagerepresentationconverter.cpp and thus gets compiled into the final executable also on static linking.

refs #474
refs #553
parent dbe4f8e5
MACRO(WRITE_CONVERTER_REGISTRATION FileName)
MESSAGE(STATUS "* Generating converter registration header: ${FileName}")
SET(ConverterRegistrationSource "// WARNING: This file is automatically generated by CMake, do not modify!\n\n" )
LIST(APPEND ConverterRegistrationSource "// Include Converter Headers:\n" )
FOREACH(IncludeFile ${ConverterRegistrationIncludeFiles})
LIST(APPEND ConverterRegistrationSource "#include \"${IncludeFile}\"\n" )
ENDFOREACH()
FILE(WRITE ${FileName} ${ConverterRegistrationSource})
ENDMACRO(WRITE_CONVERTER_REGISTRATION)
MACRO(PARSE_HEADER_FOR_CONVERTER FileName)
FILE(READ ${FileName} content)
# Find all class definitions inheriting from a Pipeline
STRING(REGEX MATCHALL "template class ConversionFunctionRegistrar<" matches ${content})
LIST(LENGTH matches NumMatches)
IF(${NumMatches} GREATER 0)
MESSAGE(STATUS "Found ${NumMatches} converters in ${FileName}")
LIST(APPEND ConverterRegistrationIncludeFiles ${FileName})
ENDIF()
ENDMACRO(PARSE_HEADER_FOR_CONVERTER)
MACRO(ADD_PIPELINE_REGISTRATION IncludeFile ClassName)
LIST(APPEND PipelineRegistrationIncludeFiles ${IncludeFile})
LIST(APPEND PipelineRegistrationClassNames ${ClassName})
......
......@@ -4,7 +4,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
MESSAGE(STATUS "Configuring CAMPVis Core")
# glob sources from core directories
FILE(GLOB CampvisCoreSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
classification/*.cpp
......@@ -44,6 +43,11 @@ FOREACH(CampvisModulesCoreHeader ${CampvisModulesCoreHeaders})
LIST(APPEND CampvisCoreHeaders ${ModHeaderFile})
ENDFOREACH()
FOREACH(HeaderFile ${CampvisCoreHeaders})
PARSE_HEADER_FOR_CONVERTER(${HeaderFile})
ENDFOREACH()
WRITE_CONVERTER_REGISTRATION("gen_converterregistration.h")
ADD_LIBRARY(campvis-core
${CampvisCoreSources} ${CampvisCoreHeaders}
)
......
......@@ -26,6 +26,7 @@
#define IMAGEREPRESENTATIONCONVERSIONCORE_H__
#include "core/coreapi.h"
#include "core/tools/opengljobprocessor.h"
#include "core/datastructures/imagerepresentationconverter.h"
#include "core/datastructures/imagerepresentationdisk.h"
......
......@@ -27,6 +27,7 @@
#include <functional>
#include "core/properties/abstractproperty.h"
#include "core/gen_converterregistration.h"
namespace campvis {
......
......@@ -118,13 +118,13 @@ namespace campvis {
private:
/// static helper field to ensure registration at static initialization time.
static const size_t _factoryId;
static size_t _factoryId;
};
// The meat of the static factory registration, call the registerConversionFunction() method and use the
// returned size_t to store it in the static member and thus ensure calling during static initialization.
template<typename ConversionTarget, typename ConverterClass>
const size_t ConversionFunctionRegistrar<ConversionTarget, ConverterClass>::_factoryId
size_t ConversionFunctionRegistrar<ConversionTarget, ConverterClass>::_factoryId
= ImageRepresentationConverter::getRef().registerConversionFunction(
typeid(ConversionTarget),
&ConversionFunctionRegistrar<ConversionTarget, ConverterClass>::tryConvertFrom
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment