aboutsummaryrefslogtreecommitdiff
path: root/tests/ECMAddAppIconTest/CMakeLists.txt
blob: a8a9d1b18ee716746f7c62552914d6fe621eaf96 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
project(ECMAddAppIconTest)
cmake_minimum_required(VERSION 3.5)

set(CMAKE_MODULE_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/../../modules
    ${CMAKE_CURRENT_SOURCE_DIR}/../../find-modules
)

include(ECMAddAppIcon)

if(WIN32)
    set(icon_extension_to_test "rc")
elseif(APPLE)
    set(icon_extension_to_test "icns")
endif()

#### Test 1: ecm_add_app_icon with only regular icons and no OUTFILE_BASENAME, for sources var ####
set(ICONS_1 16-category-name.png 128-category-name.png)
ecm_add_app_icon(OUT_1 ICONS ${ICONS_1})

list(LENGTH OUT_1 out_count)

if(WIN32 OR APPLE)
    if(out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() hasn't produced anything")
    endif()

    if(NOT OUT_1 MATCHES "OUT_1.${icon_extension_to_test}")
        message(FATAL_ERROR "ecm_add_app_icon() did not fall back to target name for icon name: ${OUT_1}")
    endif()
else()
    if(NOT out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() produced something unexpectedly.")
    endif()
endif()

add_custom_target(t_1 ALL DEPENDS ${OUT_1})
list(APPEND OUT "${OUT_1}")

#### Test 2: ecm_add_app_icon with regular and sidebar icons and OUTFILE_BASENAME set, for sources var ####
set(ICONS_2 16-category-name.png 128-category-name.png)
set(SIDEBAR_ICONS_2 16-category-name-sidebar.png 128-category-name-sidebar.png)

ecm_add_app_icon(OUT_2 ICONS ${ICONS_2} SIDEBAR_ICONS ${SIDEBAR_ICONS_2} OUTFILE_BASENAME "SuperBasename")

list(LENGTH OUT_2 out_count)

if(WIN32 OR APPLE)
    if(out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() hasn't produced anything")
    endif()

    if(NOT OUT_2 MATCHES "SuperBasename.${icon_extension_to_test}")
        message(FATAL_ERROR "ecm_add_app_icon() did not respect OUTFILE_BASENAME: ${OUT_2}")
    endif()
else()
    if(NOT out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() produced something unexpectedly.")
    endif()
endif()

if(APPLE)
    list(APPEND expected_icons "icon_16x16.png" "icon_128x128.png" "sidebar_16x16.png" "sidebar_32x32.png")
    foreach(expected_icon ${expected_icons})
        list(APPEND OUT_2 "${CMAKE_CURRENT_BINARY_DIR}/SuperBasename.iconset/${expected_icon}")
    endforeach()
endif()

add_custom_target(t_2 ALL DEPENDS ${OUT_2})
list(APPEND OUT "${OUT_2}")

#### Test 3: ecm_add_app_icon with only regular icons and no OUTFILE_BASENAME, for target  ####
set(ICONS_3 16-category-name.png 128-category-name.png)

add_executable(app_3)
target_sources(app_3 PRIVATE main.cpp)

ecm_add_app_icon(app_3 ICONS ${ICONS_1})

get_target_property(OUT_3 app_3 SOURCES)
list(REMOVE_ITEM OUT_3 main.cpp)
list(LENGTH OUT_3 out_count)

if(WIN32 OR APPLE)
    if(out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() hasn't produced anything")
    endif()

    if(NOT OUT_3 MATCHES "app_3.${icon_extension_to_test}")
        message(FATAL_ERROR "ecm_add_app_icon() did not fall back to target name for icon name: ${OUT_1}")
    endif()
else()
    if(NOT out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() produced something unexpectedly.")
    endif()
endif()

list(APPEND OUT "${OUT_3}")

#### Test 4: ecm_add_app_icon with regular and sidebar icons and OUTFILE_BASENAME set, for target ####
set(ICONS_4 16-category-name.png 128-category-name.png)
set(SIDEBAR_ICONS_4 16-category-name-sidebar.png 128-category-name-sidebar.png)

add_executable(app_4)
target_sources(app_4 PRIVATE main.cpp)

ecm_add_app_icon(app_4 ICONS ${ICONS_4} SIDEBAR_ICONS ${SIDEBAR_ICONS_4} OUTFILE_BASENAME "SuperBasename4")

get_target_property(OUT_4 app_4 SOURCES)
list(REMOVE_ITEM OUT_4 main.cpp)
list(LENGTH OUT_4 out_count)

if(WIN32 OR APPLE)
    if(out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() hasn't produced anything")
    endif()

    if(NOT OUT_4 MATCHES "SuperBasename4.${icon_extension_to_test}")
        message(FATAL_ERROR "ecm_add_app_icon() did not respect OUTFILE_BASENAME: ${OUT_4}")
    endif()
else()
    if(NOT out_count EQUAL 0)
        message(FATAL_ERROR "ecm_add_app_icon() produced something unexpectedly.")
    endif()
endif()

if(APPLE)
    list(APPEND expected_icons "icon_16x16.png" "icon_128x128.png" "sidebar_16x16.png" "sidebar_32x32.png")
    foreach(expected_icon ${expected_icons})
        list(APPEND OUT_4 "${CMAKE_CURRENT_BINARY_DIR}/SuperBasename4.iconset/${expected_icon}")
    endforeach()
endif()

list(APPEND OUT "${OUT_4}")

#### this will be run by CTest ####
configure_file(check_files.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/check_files.cmake" @ONLY)