summaryrefslogtreecommitdiffstats
path: root/client/SDL/dialogs/res/CMakeLists.txt
blob: 5591e4af6664d567853fca9ffb7bb4032e38d140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
add_executable(freerdp-res2bin
       convert_res_to_c.cpp
)

set(SRCS
    sdl_resource_manager.cpp
    sdl_resource_manager.hpp
)

set(RES_SVG_FILES
    ${CMAKE_SOURCE_DIR}/resources/FreeRDP_Icon.svg
    ${CMAKE_SOURCE_DIR}/resources/icon_info.svg
    ${CMAKE_SOURCE_DIR}/resources/icon_warning.svg
    ${CMAKE_SOURCE_DIR}/resources/icon_error.svg
)

set(RES_FONT_FILES
    ${CMAKE_SOURCE_DIR}/client/SDL/dialogs/font/OpenSans-VariableFont_wdth,wght.ttf
)

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})

    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}
    )

    add_custom_command(
        OUTPUT ${FILE_BYPRODUCTS}
        COMMAND ${CMAKE_COMMAND} -E make_directory ${FILE_BIN_DIR}
        COMMAND $<TARGET_FILE:freerdp-res2bin> ${FILE} ${FILE_TYPE} ${TARGET_NAME} ${FILE_BIN_DIR}
        COMMENT "create image resources"
        DEPENDS freerdp-res2bin
        DEPENDS ${FILE}
    )
endmacro()

option(SDL_USE_COMPILED_RESOURCES "Compile in images/fonts" ON)

if (SDL_USE_COMPILED_RESOURCES)
    list(APPEND SRCS
        sdl_resource_file.cpp
        sdl_resource_file.hpp
    )

    include_directories(${CMAKE_CURRENT_SOURCE_DIR})

    if (WITH_SDL_IMAGE_DIALOGS)
        foreach(FILE ${RES_SVG_FILES})
            convert_to_bin("${FILE}" "images")
        endforeach()
    endif()

    foreach(FILE ${RES_FONT_FILES})
        convert_to_bin("${FILE}" "fonts")
    endforeach()
    add_definitions(-DSDL_USE_COMPILED_RESOURCES)
else()
    set(SDL_RESOURCE_ROOT ${CMAKE_INSTALL_FULL_DATAROOTDIR}/FreeRDP)
    if (WITH_BINARY_VERSIONING)
        string(APPEND SDL_RESOURCE_ROOT "${PROJECT_VERSION_MAJOR}")
    endif()

    add_definitions(-DSDL_RESOURCE_ROOT="${SDL_RESOURCE_ROOT}")

    if (WITH_SDL_IMAGE_DIALOGS)
        install(
            FILES ${RES_SVG_FILES}
            DESTINATION ${SDL_RESOURCE_ROOT}/images
        )
    endif()

    install(
        FILES ${RES_FONT_FILES}
        DESTINATION ${SDL_RESOURCE_ROOT}/fonts
    )
endif()

add_library(sdl_client_res OBJECT
    ${RES_FILES}
    ${SRCS}
    ${FACTORY_SRCS}
)
set_property(TARGET sdl_client_res PROPERTY POSITION_INDEPENDENT_CODE ON)