├── tests
├── basic
│ ├── .gitignore
│ ├── assets
│ │ ├── resource1.txt
│ │ └── resource2.txt
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── extended
│ ├── .gitignore
│ ├── assets
│ │ ├── resource1.txt
│ │ ├── resource2.txt
│ │ ├── resource4.jpg
│ │ ├── resource5.jpg
│ │ └── resource3.xml
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── compress-all
│ ├── .gitignore
│ ├── assets
│ │ ├── resource1.txt
│ │ └── resource2.txt
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── create-c-code
│ ├── .gitignore
│ ├── assets
│ │ ├── resource1.txt
│ │ └── resource2.txt
│ ├── snapshots
│ │ ├── resources.gresource.xml
│ │ └── resources.c
│ └── CMakeLists.txt
├── custom-target
│ ├── .gitignore
│ ├── assets
│ │ └── resource.txt
│ ├── snapshots
│ │ ├── custom-resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── topixdata-all
│ ├── .gitignore
│ ├── assets
│ │ ├── resource1.jpg
│ │ └── resource2.jpg
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── source-dir-absolute
│ ├── .gitignore
│ ├── assets
│ │ └── resource.txt
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── source-dir-relative
│ ├── .gitignore
│ ├── assets
│ │ └── resource.txt
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ └── CMakeLists.txt
├── stripblanks-all
│ ├── .gitignore
│ ├── snapshots
│ │ ├── resources.gresource
│ │ └── resources.gresource.xml
│ ├── assets
│ │ ├── resource2.xml
│ │ └── resource1.xml
│ └── CMakeLists.txt
└── test.bats
├── macros
├── GlibCompileResourcesSupport.cmake
├── BuildTargetScript.cmake
├── GenerateGXML.cmake
└── CompileGResources.cmake
├── .github
└── workflows
│ └── test.yml
├── README.md
└── LICENSE
/tests/basic/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/extended/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/compress-all/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/create-c-code/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/custom-target/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/topixdata-all/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/source-dir-absolute/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/source-dir-relative/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/stripblanks-all/.gitignore:
--------------------------------------------------------------------------------
1 | /build/
2 |
--------------------------------------------------------------------------------
/tests/basic/assets/resource1.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/basic/assets/resource2.txt:
--------------------------------------------------------------------------------
1 | this is test resource #2
2 |
--------------------------------------------------------------------------------
/tests/extended/assets/resource1.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/compress-all/assets/resource1.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/compress-all/assets/resource2.txt:
--------------------------------------------------------------------------------
1 | this is test resource #2
2 |
--------------------------------------------------------------------------------
/tests/create-c-code/assets/resource1.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/custom-target/assets/resource.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/extended/assets/resource2.txt:
--------------------------------------------------------------------------------
1 | this is test resource #2
2 |
--------------------------------------------------------------------------------
/tests/create-c-code/assets/resource2.txt:
--------------------------------------------------------------------------------
1 | this is test resource #2
2 |
--------------------------------------------------------------------------------
/tests/source-dir-absolute/assets/resource.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/source-dir-relative/assets/resource.txt:
--------------------------------------------------------------------------------
1 | this is a test resource
2 |
--------------------------------------------------------------------------------
/tests/extended/assets/resource4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/extended/assets/resource4.jpg
--------------------------------------------------------------------------------
/tests/extended/assets/resource5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/extended/assets/resource5.jpg
--------------------------------------------------------------------------------
/tests/topixdata-all/assets/resource1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/topixdata-all/assets/resource1.jpg
--------------------------------------------------------------------------------
/tests/topixdata-all/assets/resource2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/topixdata-all/assets/resource2.jpg
--------------------------------------------------------------------------------
/tests/basic/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/basic/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/extended/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/extended/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/compress-all/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/compress-all/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/topixdata-all/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/topixdata-all/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/stripblanks-all/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/stripblanks-all/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/source-dir-absolute/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/source-dir-absolute/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/source-dir-relative/snapshots/resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/source-dir-relative/snapshots/resources.gresource
--------------------------------------------------------------------------------
/tests/custom-target/snapshots/custom-resources.gresource:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Makman2/GCR_CMake/HEAD/tests/custom-target/snapshots/custom-resources.gresource
--------------------------------------------------------------------------------
/tests/custom-target/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource.txt
--------------------------------------------------------------------------------
/tests/source-dir-absolute/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | resource.txt
--------------------------------------------------------------------------------
/tests/source-dir-relative/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | resource.txt
--------------------------------------------------------------------------------
/tests/basic/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.txtassets/resource2.txt
--------------------------------------------------------------------------------
/tests/create-c-code/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.txtassets/resource2.txt
--------------------------------------------------------------------------------
/tests/compress-all/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.txtassets/resource2.txt
--------------------------------------------------------------------------------
/tests/topixdata-all/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.jpgassets/resource2.jpg
--------------------------------------------------------------------------------
/tests/stripblanks-all/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.xmlassets/resource2.xml
--------------------------------------------------------------------------------
/tests/extended/assets/resource3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Tove
4 | Teststreet 12
5 |
6 |
7 | Jani
8 | Main Ave. 102
9 |
10 | Reminder
11 | Don't forget me this weekend!
12 |
13 |
--------------------------------------------------------------------------------
/tests/stripblanks-all/assets/resource2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Adam
4 | Teststreet 13
5 |
6 |
7 | Eva
8 | Main Ave. 104
9 |
10 | Note
11 | Don't forget me this week!
12 |
13 |
--------------------------------------------------------------------------------
/tests/stripblanks-all/assets/resource1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Tove
4 | Teststreet 12
5 |
6 |
7 | Jani
8 | Main Ave. 102
9 |
10 | Reminder
11 | Don't forget me this weekend!
12 |
13 |
--------------------------------------------------------------------------------
/tests/extended/snapshots/resources.gresource.xml:
--------------------------------------------------------------------------------
1 | assets/resource1.txtassets/resource2.txtassets/resource3.xmlassets/resource4.jpgassets/resource5.jpg
--------------------------------------------------------------------------------
/macros/GlibCompileResourcesSupport.cmake:
--------------------------------------------------------------------------------
1 | # Path to this file.
2 | set(GCR_CMAKE_MACRO_DIR ${CMAKE_CURRENT_LIST_DIR})
3 |
4 | # Finds the glib-compile-resources executable.
5 | find_program(GLIB_COMPILE_RESOURCES_EXECUTABLE glib-compile-resources)
6 | mark_as_advanced(GLIB_COMPILE_RESOURCES_EXECUTABLE)
7 |
8 | # Include the cmake files containing the functions.
9 | include(${GCR_CMAKE_MACRO_DIR}/CompileGResources.cmake)
10 | include(${GCR_CMAKE_MACRO_DIR}/GenerateGXML.cmake)
11 |
12 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: test
2 | on:
3 | push:
4 | branches:
5 | - master
6 | pull_request:
7 | jobs:
8 | test:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v2
12 | - uses: actions/setup-node@v2
13 | with:
14 | node-version: '14'
15 | - run: npm install -g bats
16 | - run: sudo apt-get install -y cmake libxml2-utils
17 | - name: Run Tests
18 | working-directory: tests
19 | run: ./test.bats
20 |
--------------------------------------------------------------------------------
/tests/basic/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource1.txt assets/resource2.txt)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE BUNDLE
16 | RESOURCES ${RESOURCES})
17 |
18 | add_custom_target(resources
19 | ALL
20 | DEPENDS ${RESOURCE_OUT})
21 |
--------------------------------------------------------------------------------
/tests/create-c-code/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource1.txt assets/resource2.txt)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE EMBED_C
16 | RESOURCES ${RESOURCES})
17 |
18 | add_custom_target(resources
19 | ALL
20 | DEPENDS ${RESOURCE_OUT})
21 |
--------------------------------------------------------------------------------
/tests/compress-all/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource1.txt assets/resource2.txt)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE BUNDLE
16 | RESOURCES ${RESOURCES}
17 | COMPRESS_ALL)
18 |
19 | add_custom_target(resources
20 | ALL
21 | DEPENDS ${RESOURCE_OUT})
22 |
--------------------------------------------------------------------------------
/tests/topixdata-all/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource1.jpg assets/resource2.jpg)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE BUNDLE
16 | RESOURCES ${RESOURCES}
17 | TOPIXDATA_ALL)
18 |
19 | add_custom_target(resources
20 | ALL
21 | DEPENDS ${RESOURCE_OUT})
22 |
--------------------------------------------------------------------------------
/tests/stripblanks-all/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource1.xml assets/resource2.xml)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE BUNDLE
16 | RESOURCES ${RESOURCES}
17 | STRIPBLANKS_ALL)
18 |
19 | add_custom_target(resources
20 | ALL
21 | DEPENDS ${RESOURCE_OUT})
22 |
--------------------------------------------------------------------------------
/tests/custom-target/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES assets/resource.txt)
12 |
13 | compile_gresources(RESOURCE_OUT
14 | XML_OUT
15 | TYPE BUNDLE
16 | TARGET ${CMAKE_BINARY_DIR}/custom-resources.gresource
17 | RESOURCES ${RESOURCES})
18 |
19 | add_custom_target(resources
20 | ALL
21 | DEPENDS ${RESOURCE_OUT})
22 |
--------------------------------------------------------------------------------
/tests/source-dir-relative/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | # We use SOURCE_DIR below relative to "assets", so the asset paths should work relative to this directory.
12 | list(APPEND RESOURCES resource.txt)
13 |
14 | compile_gresources(RESOURCE_OUT
15 | XML_OUT
16 | TYPE BUNDLE
17 | SOURCE_DIR assets
18 | RESOURCES ${RESOURCES})
19 |
20 | add_custom_target(resources
21 | ALL
22 | DEPENDS ${RESOURCE_OUT})
23 |
--------------------------------------------------------------------------------
/tests/extended/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | list(APPEND RESOURCES
12 | COMPRESS assets/resource1.txt
13 | assets/resource2.txt
14 | STRIPBLANKS assets/resource3.xml
15 | TOPIXDATA assets/resource4.jpg
16 | assets/resource5.jpg)
17 |
18 | compile_gresources(RESOURCE_OUT
19 | XML_OUT
20 | TYPE BUNDLE
21 | RESOURCES ${RESOURCES})
22 |
23 | add_custom_target(resources
24 | ALL
25 | DEPENDS ${RESOURCE_OUT})
26 |
--------------------------------------------------------------------------------
/tests/source-dir-absolute/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | get_filename_component(ProjectFolder ${CMAKE_CURRENT_LIST_DIR} NAME)
4 | string(REPLACE " " "_" ProjectFolder ${ProjectFolder})
5 | project("GCR_CMake-testcase-${ProjectFolder}")
6 |
7 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../macros)
8 |
9 | include(GlibCompileResourcesSupport)
10 |
11 | # We use SOURCE_DIR below relative to "assets", so the asset paths should work relative to this directory.
12 | list(APPEND RESOURCES resource.txt)
13 |
14 | compile_gresources(RESOURCE_OUT
15 | XML_OUT
16 | TYPE BUNDLE
17 | SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/assets
18 | RESOURCES ${RESOURCES})
19 |
20 | add_custom_target(resources
21 | ALL
22 | DEPENDS ${RESOURCE_OUT})
23 |
--------------------------------------------------------------------------------
/macros/BuildTargetScript.cmake:
--------------------------------------------------------------------------------
1 | # This file is used to be invoked at build time. It generates the needed
2 | # resource XML file.
3 |
4 | # Input variables that need to provided when invoking this script:
5 | # GXML_OUTPUT The output file path where to save the XML file.
6 | # GXML_COMPRESS_ALL Sets all COMPRESS flags in all resources in resource
7 | # list.
8 | # GXML_NO_COMPRESS_ALL Removes all COMPRESS flags in all resources in
9 | # resource list.
10 | # GXML_STRIPBLANKS_ALL Sets all STRIPBLANKS flags in all resources in
11 | # resource list.
12 | # GXML_NO_STRIPBLANKS_ALL Removes all STRIPBLANKS flags in all resources in
13 | # resource list.
14 | # GXML_TOPIXDATA_ALL Sets all TOPIXDATA flags i nall resources in resource
15 | # list.
16 | # GXML_NO_TOPIXDATA_ALL Removes all TOPIXDATA flags in all resources in
17 | # resource list.
18 | # GXML_PREFIX Overrides the resource prefix that is prepended to
19 | # each relative name in registered resources.
20 | # GXML_RESOURCES The list of resource files. Whether absolute or
21 | # relative path is equal.
22 |
23 | # Include the GENERATE_GXML() function.
24 | include(${CMAKE_CURRENT_LIST_DIR}/GenerateGXML.cmake)
25 |
26 | # Set flags to actual invocation flags.
27 | if(GXML_COMPRESS_ALL)
28 | set(GXML_COMPRESS_ALL COMPRESS_ALL)
29 | endif()
30 | if(GXML_NO_COMPRESS_ALL)
31 | set(GXML_NO_COMPRESS_ALL NO_COMPRESS_ALL)
32 | endif()
33 | if(GXML_STRIPBLANKS_ALL)
34 | set(GXML_STRIPBLANKS_ALL STRIPBLANKS_ALL)
35 | endif()
36 | if(GXML_NO_STRIPBLANKS_ALL)
37 | set(GXML_NO_STRIPBLANKS_ALL NO_STRIPBLANKS_ALL)
38 | endif()
39 | if(GXML_TOPIXDATA_ALL)
40 | set(GXML_TOPIXDATA_ALL TOPIXDATA_ALL)
41 | endif()
42 | if(GXML_NO_TOPIXDATA_ALL)
43 | set(GXML_NO_TOPIXDATA_ALL NO_TOPIXDATA_ALL)
44 | endif()
45 |
46 | # Replace " " with ";" to import the list over the command line. Otherwise
47 | # CMake would interprete the passed resources as a whole string.
48 | string(REPLACE " " ";" GXML_RESOURCES ${GXML_RESOURCES})
49 |
50 | # Invoke the gresource XML generation function.
51 | generate_gxml(${GXML_OUTPUT}
52 | ${GXML_COMPRESS_ALL} ${GXML_NO_COMPRESS_ALL}
53 | ${GXML_STRIPBLANKS_ALL} ${GXML_NO_STRIPBLANKS_ALL}
54 | ${GXML_TOPIXDATA_ALL} ${GXML_NO_TOPIXDATA_ALL}
55 | PREFIX ${GXML_PREFIX}
56 | RESOURCES ${GXML_RESOURCES})
57 |
58 |
--------------------------------------------------------------------------------
/tests/test.bats:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bats
2 |
3 | @test "basic test" {
4 | cd basic
5 |
6 | rm -rf build
7 | mkdir build
8 | cd build
9 | cmake ..
10 | make
11 | cd ..
12 |
13 | [ -f "build/resources.gresource.xml" ]
14 | [ -f "build/resources.gresource" ]
15 |
16 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
17 | diff "build/resources.gresource" "snapshots/resources.gresource"
18 | }
19 |
20 | @test "COMPRESS_ALL works" {
21 | cd compress-all
22 |
23 | rm -rf build
24 | mkdir build
25 | cd build
26 | cmake ..
27 | make
28 | cd ..
29 |
30 | [ -f "build/resources.gresource.xml" ]
31 | [ -f "build/resources.gresource" ]
32 |
33 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
34 | diff "build/resources.gresource" "snapshots/resources.gresource"
35 | }
36 |
37 | @test "EMBED_C type-option works" {
38 | cd create-c-code
39 |
40 | rm -rf build
41 | mkdir build
42 | cd build
43 | cmake ..
44 | make
45 | cd ..
46 |
47 | [ -f "build/resources.gresource.xml" ]
48 | [ -f "build/resources.c" ]
49 |
50 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
51 | diff "build/resources.c" "snapshots/resources.c"
52 | }
53 |
54 | @test "setting TARGET to a custom value works" {
55 | cd custom-target
56 |
57 | rm -rf build
58 | mkdir build
59 | cd build
60 | cmake ..
61 | make
62 | cd ..
63 |
64 | [ -f "build/resources.gresource.xml" ]
65 | [ -f "build/custom-resources.gresource" ]
66 |
67 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
68 | diff "build/custom-resources.gresource" "snapshots/custom-resources.gresource"
69 | }
70 |
71 | @test "extended test" {
72 | cd extended
73 |
74 | rm -rf build
75 | mkdir build
76 | cd build
77 | cmake ..
78 | make
79 | cd ..
80 |
81 | [ -f "build/resources.gresource.xml" ]
82 | [ -f "build/resources.gresource" ]
83 |
84 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
85 | diff "build/resources.gresource" "snapshots/resources.gresource"
86 | }
87 |
88 | @test "SOURCE_DIR argument works properly with relative paths" {
89 | cd source-dir-relative
90 |
91 | rm -rf build
92 | mkdir build
93 | cd build
94 | cmake ..
95 | make
96 | cd ..
97 |
98 | [ -f "build/resources.gresource.xml" ]
99 | [ -f "build/resources.gresource" ]
100 |
101 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
102 | diff "build/resources.gresource" "snapshots/resources.gresource"
103 | }
104 |
105 | @test "SOURCE_DIR argument works properly with absolute paths" {
106 | cd source-dir-absolute
107 |
108 | rm -rf build
109 | mkdir build
110 | cd build
111 | cmake ..
112 | make
113 | cd ..
114 |
115 | [ -f "build/resources.gresource.xml" ]
116 | [ -f "build/resources.gresource" ]
117 |
118 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
119 | diff "build/resources.gresource" "snapshots/resources.gresource"
120 | }
121 |
122 | @test "STRIPBLANKS_ALL works" {
123 | cd stripblanks-all
124 |
125 | rm -rf build
126 | mkdir build
127 | cd build
128 | cmake ..
129 | make
130 | cd ..
131 |
132 | [ -f "build/resources.gresource.xml" ]
133 | [ -f "build/resources.gresource" ]
134 |
135 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
136 | diff "build/resources.gresource" "snapshots/resources.gresource"
137 | }
138 |
139 | @test "TOPIXDATA_ALL works" {
140 | cd topixdata-all
141 |
142 | rm -rf build
143 | mkdir build
144 | cd build
145 | cmake ..
146 | make
147 | cd ..
148 |
149 | [ -f "build/resources.gresource.xml" ]
150 | [ -f "build/resources.gresource" ]
151 |
152 | diff "build/resources.gresource.xml" "snapshots/resources.gresource.xml"
153 | diff "build/resources.gresource" "snapshots/resources.gresource"
154 | }
155 |
--------------------------------------------------------------------------------
/macros/GenerateGXML.cmake:
--------------------------------------------------------------------------------
1 | include(CMakeParseArguments)
2 |
3 | # Generates the resource XML controlling file from resource list (and saves it
4 | # to xml_path). It's not recommended to use this function directly, since it
5 | # doesn't handle invalid arguments. It is used by the function
6 | # COMPILE_GRESOURCES() to create a custom command, so that this function is
7 | # invoked at build-time in script mode from CMake.
8 | function(GENERATE_GXML xml_path)
9 | # Available options:
10 | # COMPRESS_ALL, NO_COMPRESS_ALL Overrides the COMPRESS flag in all
11 | # registered resources.
12 | # STRIPBLANKS_ALL, NO_STRIPBLANKS_ALL Overrides the STRIPBLANKS flag in all
13 | # registered resources.
14 | # TOPIXDATA_ALL, NO_TOPIXDATA_ALL Overrides the TOPIXDATA flag in all
15 | # registered resources.
16 | set(GXML_OPTIONS COMPRESS_ALL NO_COMPRESS_ALL
17 | STRIPBLANKS_ALL NO_STRIPBLANKS_ALL
18 | TOPIXDATA_ALL NO_TOPIXDATA_ALL)
19 |
20 | # Available one value options:
21 | # PREFIX Overrides the resource prefix that is prepended to each
22 | # relative file name in registered resources.
23 | set(GXML_ONEVALUEARGS PREFIX)
24 |
25 | # Available multi-value options:
26 | # RESOURCES The list of resource files. Whether absolute or relative path is
27 | # equal, absolute paths are stripped down to relative ones. If the
28 | # absolute path is not inside the given base directory SOURCE_DIR
29 | # or CMAKE_CURRENT_SOURCE_DIR (if SOURCE_DIR is not overriden),
30 | # this function aborts.
31 | set(GXML_MULTIVALUEARGS RESOURCES)
32 |
33 | # Parse the arguments.
34 | cmake_parse_arguments(GXML_ARG
35 | "${GXML_OPTIONS}"
36 | "${GXML_ONEVALUEARGS}"
37 | "${GXML_MULTIVALUEARGS}"
38 | "${ARGN}")
39 |
40 | # Variable to store the double-quote (") string. Since escaping
41 | # double-quotes in strings is not possible we need a helper variable that
42 | # does this job for us.
43 | set(Q \")
44 |
45 | # Process resources and generate XML file.
46 | # Begin with the XML header and header nodes.
47 | set(GXML_XML_FILE "")
48 | set(GXML_XML_FILE "${GXML_XML_FILE}")
59 |
60 | # Process each resource.
61 | foreach(res ${GXML_ARG_RESOURCES})
62 | if ("${res}" STREQUAL "COMPRESS")
63 | set(GXML_COMPRESSION_FLAG ON)
64 | elseif ("${res}" STREQUAL "STRIPBLANKS")
65 | set(GXML_STRIPBLANKS_FLAG ON)
66 | elseif ("${res}" STREQUAL "TOPIXDATA")
67 | set(GXML_TOPIXDATA_FLAG ON)
68 | else()
69 | # The file name.
70 | set(GXML_RESOURCE_PATH "${res}")
71 |
72 | # Append to real resource file dependency list.
73 | list(APPEND GXML_RESOURCES_DEPENDENCIES ${GXML_RESOURCE_PATH})
74 |
75 | # Assemble node.
76 | set(GXML_RES_LINE "${GXML_RESOURCE_PATH}")
104 |
105 | # Append to file string.
106 | set(GXML_XML_FILE "${GXML_XML_FILE}${GXML_RES_LINE}")
107 |
108 | # Unset variables.
109 | unset(GXML_COMPRESSION_FLAG)
110 | unset(GXML_STRIPBLANKS_FLAG)
111 | unset(GXML_TOPIXDATA_FLAG)
112 | endif()
113 |
114 | endforeach()
115 |
116 | # Append closing nodes.
117 | set(GXML_XML_FILE "${GXML_XML_FILE}")
118 |
119 | # Use "file" function to generate XML controlling file.
120 | get_filename_component(xml_path_only_name "${xml_path}" NAME)
121 | file(WRITE ${xml_path} ${GXML_XML_FILE})
122 |
123 | endfunction()
124 |
125 |
--------------------------------------------------------------------------------
/tests/create-c-code/snapshots/resources.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #if defined (__ELF__) && ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 6))
4 | # define SECTION __attribute__ ((section (".gresource.resources"), aligned (8)))
5 | #else
6 | # define SECTION
7 | #endif
8 |
9 | #ifdef _MSC_VER
10 | static const SECTION union { const guint8 data[282]; const double alignment; void * const ptr;} resources_resource_data = { {
11 | 0107, 0126, 0141, 0162, 0151, 0141, 0156, 0164, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
12 | 0030, 0000, 0000, 0000, 0220, 0000, 0000, 0000, 0000, 0000, 0000, 0050, 0004, 0000, 0000, 0000,
13 | 0000, 0000, 0000, 0000, 0001, 0000, 0000, 0000, 0002, 0000, 0000, 0000, 0004, 0000, 0000, 0000,
14 | 0324, 0265, 0002, 0000, 0377, 0377, 0377, 0377, 0220, 0000, 0000, 0000, 0001, 0000, 0114, 0000,
15 | 0224, 0000, 0000, 0000, 0230, 0000, 0000, 0000, 0275, 0000, 0142, 0053, 0002, 0000, 0000, 0000,
16 | 0230, 0000, 0000, 0000, 0015, 0000, 0166, 0000, 0250, 0000, 0000, 0000, 0320, 0000, 0000, 0000,
17 | 0166, 0005, 0066, 0033, 0000, 0000, 0000, 0000, 0320, 0000, 0000, 0000, 0007, 0000, 0114, 0000,
18 | 0330, 0000, 0000, 0000, 0340, 0000, 0000, 0000, 0076, 0031, 0164, 0053, 0002, 0000, 0000, 0000,
19 | 0340, 0000, 0000, 0000, 0015, 0000, 0166, 0000, 0360, 0000, 0000, 0000, 0031, 0001, 0000, 0000,
20 | 0057, 0000, 0000, 0000, 0002, 0000, 0000, 0000, 0162, 0145, 0163, 0157, 0165, 0162, 0143, 0145,
21 | 0061, 0056, 0164, 0170, 0164, 0000, 0000, 0000, 0030, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
22 | 0164, 0150, 0151, 0163, 0040, 0151, 0163, 0040, 0141, 0040, 0164, 0145, 0163, 0164, 0040, 0162,
23 | 0145, 0163, 0157, 0165, 0162, 0143, 0145, 0012, 0000, 0000, 0050, 0165, 0165, 0141, 0171, 0051,
24 | 0141, 0163, 0163, 0145, 0164, 0163, 0057, 0000, 0001, 0000, 0000, 0000, 0003, 0000, 0000, 0000,
25 | 0162, 0145, 0163, 0157, 0165, 0162, 0143, 0145, 0062, 0056, 0164, 0170, 0164, 0000, 0000, 0000,
26 | 0031, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0164, 0150, 0151, 0163, 0040, 0151, 0163, 0040,
27 | 0164, 0145, 0163, 0164, 0040, 0162, 0145, 0163, 0157, 0165, 0162, 0143, 0145, 0040, 0043, 0062,
28 | 0012, 0000, 0000, 0050, 0165, 0165, 0141, 0171, 0051
29 | } };
30 | #else /* _MSC_VER */
31 | static const SECTION union { const guint8 data[282]; const double alignment; void * const ptr;} resources_resource_data = {
32 | "\107\126\141\162\151\141\156\164\000\000\000\000\000\000\000\000"
33 | "\030\000\000\000\220\000\000\000\000\000\000\050\004\000\000\000"
34 | "\000\000\000\000\001\000\000\000\002\000\000\000\004\000\000\000"
35 | "\324\265\002\000\377\377\377\377\220\000\000\000\001\000\114\000"
36 | "\224\000\000\000\230\000\000\000\275\000\142\053\002\000\000\000"
37 | "\230\000\000\000\015\000\166\000\250\000\000\000\320\000\000\000"
38 | "\166\005\066\033\000\000\000\000\320\000\000\000\007\000\114\000"
39 | "\330\000\000\000\340\000\000\000\076\031\164\053\002\000\000\000"
40 | "\340\000\000\000\015\000\166\000\360\000\000\000\031\001\000\000"
41 | "\057\000\000\000\002\000\000\000\162\145\163\157\165\162\143\145"
42 | "\061\056\164\170\164\000\000\000\030\000\000\000\000\000\000\000"
43 | "\164\150\151\163\040\151\163\040\141\040\164\145\163\164\040\162"
44 | "\145\163\157\165\162\143\145\012\000\000\050\165\165\141\171\051"
45 | "\141\163\163\145\164\163\057\000\001\000\000\000\003\000\000\000"
46 | "\162\145\163\157\165\162\143\145\062\056\164\170\164\000\000\000"
47 | "\031\000\000\000\000\000\000\000\164\150\151\163\040\151\163\040"
48 | "\164\145\163\164\040\162\145\163\157\165\162\143\145\040\043\062"
49 | "\012\000\000\050\165\165\141\171\051" };
50 | #endif /* !_MSC_VER */
51 |
52 | static GStaticResource static_resource = { resources_resource_data.data, sizeof (resources_resource_data.data) - 1 /* nul terminator */, NULL, NULL, NULL };
53 |
54 | G_MODULE_EXPORT
55 | GResource *resources_get_resource (void);
56 | GResource *resources_get_resource (void)
57 | {
58 | return g_static_resource_get_resource (&static_resource);
59 | }
60 | /*
61 | If G_HAS_CONSTRUCTORS is true then the compiler support *both* constructors and
62 | destructors, in a usable way, including e.g. on library unload. If not you're on
63 | your own.
64 |
65 | Some compilers need #pragma to handle this, which does not work with macros,
66 | so the way you need to use this is (for constructors):
67 |
68 | #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
69 | #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(my_constructor)
70 | #endif
71 | G_DEFINE_CONSTRUCTOR(my_constructor)
72 | static void my_constructor(void) {
73 | ...
74 | }
75 |
76 | */
77 |
78 | #ifndef __GTK_DOC_IGNORE__
79 |
80 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
81 |
82 | #define G_HAS_CONSTRUCTORS 1
83 |
84 | #define G_DEFINE_CONSTRUCTOR(_func) static void __attribute__((constructor)) _func (void);
85 | #define G_DEFINE_DESTRUCTOR(_func) static void __attribute__((destructor)) _func (void);
86 |
87 | #elif defined (_MSC_VER) && (_MSC_VER >= 1500)
88 | /* Visual studio 2008 and later has _Pragma */
89 |
90 | #include
91 |
92 | #define G_HAS_CONSTRUCTORS 1
93 |
94 | /* We do some weird things to avoid the constructors being optimized
95 | * away on VS2015 if WholeProgramOptimization is enabled. First we
96 | * make a reference to the array from the wrapper to make sure its
97 | * references. Then we use a pragma to make sure the wrapper function
98 | * symbol is always included at the link stage. Also, the symbols
99 | * need to be extern (but not dllexport), even though they are not
100 | * really used from another object file.
101 | */
102 |
103 | /* We need to account for differences between the mangling of symbols
104 | * for x86 and x64/ARM/ARM64 programs, as symbols on x86 are prefixed
105 | * with an underscore but symbols on x64/ARM/ARM64 are not.
106 | */
107 | #ifdef _M_IX86
108 | #define G_MSVC_SYMBOL_PREFIX "_"
109 | #else
110 | #define G_MSVC_SYMBOL_PREFIX ""
111 | #endif
112 |
113 | #define G_DEFINE_CONSTRUCTOR(_func) G_MSVC_CTOR (_func, G_MSVC_SYMBOL_PREFIX)
114 | #define G_DEFINE_DESTRUCTOR(_func) G_MSVC_DTOR (_func, G_MSVC_SYMBOL_PREFIX)
115 |
116 | #define G_MSVC_CTOR(_func,_sym_prefix) \
117 | static void _func(void); \
118 | extern int (* _array ## _func)(void); \
119 | int _func ## _wrapper(void) { _func(); g_slist_find (NULL, _array ## _func); return 0; } \
120 | __pragma(comment(linker,"/include:" _sym_prefix # _func "_wrapper")) \
121 | __pragma(section(".CRT$XCU",read)) \
122 | __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _wrapper;
123 |
124 | #define G_MSVC_DTOR(_func,_sym_prefix) \
125 | static void _func(void); \
126 | extern int (* _array ## _func)(void); \
127 | int _func ## _constructor(void) { atexit (_func); g_slist_find (NULL, _array ## _func); return 0; } \
128 | __pragma(comment(linker,"/include:" _sym_prefix # _func "_constructor")) \
129 | __pragma(section(".CRT$XCU",read)) \
130 | __declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _constructor;
131 |
132 | #elif defined (_MSC_VER)
133 |
134 | #define G_HAS_CONSTRUCTORS 1
135 |
136 | /* Pre Visual studio 2008 must use #pragma section */
137 | #define G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA 1
138 | #define G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA 1
139 |
140 | #define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(_func) \
141 | section(".CRT$XCU",read)
142 | #define G_DEFINE_CONSTRUCTOR(_func) \
143 | static void _func(void); \
144 | static int _func ## _wrapper(void) { _func(); return 0; } \
145 | __declspec(allocate(".CRT$XCU")) static int (*p)(void) = _func ## _wrapper;
146 |
147 | #define G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(_func) \
148 | section(".CRT$XCU",read)
149 | #define G_DEFINE_DESTRUCTOR(_func) \
150 | static void _func(void); \
151 | static int _func ## _constructor(void) { atexit (_func); return 0; } \
152 | __declspec(allocate(".CRT$XCU")) static int (* _array ## _func)(void) = _func ## _constructor;
153 |
154 | #elif defined(__SUNPRO_C)
155 |
156 | /* This is not tested, but i believe it should work, based on:
157 | * http://opensource.apple.com/source/OpenSSL098/OpenSSL098-35/src/fips/fips_premain.c
158 | */
159 |
160 | #define G_HAS_CONSTRUCTORS 1
161 |
162 | #define G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA 1
163 | #define G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA 1
164 |
165 | #define G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(_func) \
166 | init(_func)
167 | #define G_DEFINE_CONSTRUCTOR(_func) \
168 | static void _func(void);
169 |
170 | #define G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(_func) \
171 | fini(_func)
172 | #define G_DEFINE_DESTRUCTOR(_func) \
173 | static void _func(void);
174 |
175 | #else
176 |
177 | /* constructors not supported for this compiler */
178 |
179 | #endif
180 |
181 | #endif /* __GTK_DOC_IGNORE__ */
182 |
183 | #ifdef G_HAS_CONSTRUCTORS
184 |
185 | #ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
186 | #pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(resource_constructor)
187 | #endif
188 | G_DEFINE_CONSTRUCTOR(resource_constructor)
189 | #ifdef G_DEFINE_DESTRUCTOR_NEEDS_PRAGMA
190 | #pragma G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(resource_destructor)
191 | #endif
192 | G_DEFINE_DESTRUCTOR(resource_destructor)
193 |
194 | #else
195 | #warning "Constructor not supported on this compiler, linking in resources will not work"
196 | #endif
197 |
198 | static void resource_constructor (void)
199 | {
200 | g_static_resource_init (&static_resource);
201 | }
202 |
203 | static void resource_destructor (void)
204 | {
205 | g_static_resource_fini (&static_resource);
206 | }
207 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GCR_CMake
2 | A CMake extension supporting the **glib-compile-resources** tool.
3 |
4 | About
5 | -----
6 |
7 | Inspired from the macros for Vala that I used to build a GTK application, I came
8 | to the point where I needed resources for it. For that purpose the
9 | **glib-compile-resources** tool seemed to be the right choice, but the extra XML
10 | file you need to write bothered me. If I add a resource I don't want to mark it
11 | explicitly in CMake and in the XML file. So I came up with this macro that does
12 | everything for you. You just add your resource to a resource list (with
13 | eventually some attributes like compression) and invoke the resource compilation
14 | function. It generates the XML automatically for you. Quite simple, isn't it?
15 |
16 | Clone
17 | -----
18 |
19 | To clone this repository, just type
20 |
21 | ```shell
22 | git clone https://github.com/Makman2/GCR_CMake
23 | ```
24 |
25 | Usage
26 | -----
27 |
28 | Just add the macro directory to your `CMAKE_MODULE_PATH`, include the CMake
29 | file and you are ready to go.
30 |
31 | ```cmake
32 | list(APPEND CMAKE_MODULE_PATH
33 | ${PATH_TO_GCR_CMAKE_PARENT_DIR}/GCR_CMake/macros)
34 |
35 | include(GlibCompileResourcesSupport)
36 | ```
37 |
38 | Reference
39 | ---------
40 |
41 | The resource compiling macro is quite powerful and handles as much errors as
42 | possible to make error-finding easier. The function is defined as follows:
43 |
44 | ```
45 | compile_gresources(