[client,sdl] fix resourcemanager
due to moving to a static class the C++ initializer did no longer work. add explicit calls for initializers to ensure the generated classes are referenced.
This commit is contained in:
parent
2efcf1c436
commit
06598da910
@ -49,7 +49,9 @@ class SdlWidget
|
||||
{
|
||||
public:
|
||||
SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, bool input);
|
||||
#if defined(WITH_SDL_IMAGE_DIALOGS)
|
||||
SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, SDL_RWops* ops);
|
||||
#endif
|
||||
SdlWidget(SdlWidget&& other) noexcept;
|
||||
virtual ~SdlWidget();
|
||||
|
||||
|
@ -19,6 +19,10 @@ add_executable(sdl-common-res2bin
|
||||
convert_res_to_c.cpp
|
||||
)
|
||||
|
||||
set(FACTORY_SRCS "")
|
||||
set(FACTORY_HDR "")
|
||||
set(FACTORY_CLASSES "")
|
||||
|
||||
macro(convert_to_bin FILE FILE_TYPE)
|
||||
get_filename_component(FILE_NAME ${FILE} NAME)
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" TARGET_NAME ${FILE_NAME})
|
||||
@ -26,9 +30,16 @@ macro(convert_to_bin FILE FILE_TYPE)
|
||||
set(FILE_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set(FILE_BYPRODUCTS ${FILE_BIN_DIR}/${TARGET_NAME}.hpp ${FILE_BIN_DIR}/${TARGET_NAME}.cpp)
|
||||
|
||||
list(APPEND FACTORY_SRCS
|
||||
${FILE_BYPRODUCTS}
|
||||
list(APPEND FACTORY_HDR
|
||||
${FILE_BIN_DIR}/${TARGET_NAME}.hpp
|
||||
)
|
||||
list(APPEND FACTORY_SRCS
|
||||
${FILE_BIN_DIR}/${TARGET_NAME}.cpp
|
||||
)
|
||||
|
||||
list(APPEND FACTORY_CLASSES
|
||||
${TARGET_NAME}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${FILE_BYPRODUCTS}
|
||||
@ -76,6 +87,20 @@ if (SDL_USE_COMPILED_RESOURCES)
|
||||
convert_to_bin("${FILE}" "fonts")
|
||||
endforeach()
|
||||
add_definitions(-DSDL_USE_COMPILED_RESOURCES)
|
||||
|
||||
set(FINIT ${CMAKE_CURRENT_BINARY_DIR}/resource-init.cpp)
|
||||
list(APPEND FACTORY_SRCS ${FINIT})
|
||||
|
||||
write_file(${FINIT} "#include <sdl_resource_manager.hpp>")
|
||||
foreach(HDR ${FACTORY_HDR})
|
||||
write_file(${FINIT} "#include <${HDR}>" APPEND)
|
||||
endforeach()
|
||||
|
||||
write_file(${FINIT} "void SDLResourceManager::init() {" APPEND)
|
||||
foreach(CLASS ${FACTORY_CLASSES})
|
||||
write_file(${FINIT} "\t${CLASS}::init();" APPEND)
|
||||
endforeach()
|
||||
write_file(${FINIT} "}" APPEND)
|
||||
else()
|
||||
set(SDL_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR}/FreeRDP)
|
||||
if (WITH_BINARY_VERSIONING)
|
||||
@ -97,9 +122,10 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(sdl-common-client-res OBJECT
|
||||
add_library(sdl-common-client-res STATIC
|
||||
${RES_FILES}
|
||||
${SRCS}
|
||||
${FACTORY_HDR}
|
||||
${FACTORY_SRCS}
|
||||
)
|
||||
set_property(TARGET sdl-common-client-res PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
@ -128,13 +128,14 @@ static int write_hpp_header(const fs::path& prg, const fs::path& file, const std
|
||||
<< "#include \"sdl_resource_file.hpp\"" << std::endl
|
||||
<< std::endl
|
||||
<< "class " << name << " {" << std::endl
|
||||
<< "friend class SDLResourceManager;" << std::endl
|
||||
<< "public:" << std::endl
|
||||
<< name << "() = delete;" << std::endl
|
||||
<< std::endl
|
||||
<< "static std::string name();" << std::endl
|
||||
<< "static std::string type();" << std::endl
|
||||
<< std::endl
|
||||
<< "private:" << std::endl
|
||||
<< "protected:" << std::endl
|
||||
<< "static std::vector<unsigned char> init();" << std::endl
|
||||
<< "static const SDLResourceFile _initializer;" << std::endl
|
||||
<< std::endl
|
||||
|
@ -93,5 +93,7 @@ std::map<std::string, std::vector<unsigned char>>& SDLResourceManager::resources
|
||||
{
|
||||
|
||||
static std::map<std::string, std::vector<unsigned char>> resources = {};
|
||||
if (resources.empty())
|
||||
init();
|
||||
return resources;
|
||||
}
|
||||
|
@ -47,4 +47,5 @@ class SDLResourceManager
|
||||
|
||||
private:
|
||||
static std::map<std::string, std::vector<unsigned char>>& resources();
|
||||
static void init(); // implemented in generated file
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user