comparison cmake/function/MalikaniaBuildAssets.cmake @ 49:2804ae55c70f

CMake: big cleanup, closes #598
author David Demelier <markand@malikania.fr>
date Fri, 09 Dec 2016 13:28:45 +0100
parents
children 858621081b95
comparison
equal deleted inserted replaced
48:3be179ba3226 49:2804ae55c70f
1 #
2 # MalikaniaBuildAssets.cmake -- CMake build system for malikania
3 #
4 # Copyright (c) 2013-2016 Malikania Authors
5 #
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #
18
19 #
20 # malikania_build_assets
21 # ----------------------
22 #
23 # malikania_build_assets(inputs outputs)
24 #
25 # Create binary data as C++ arrays for inclusion in source code. Static assets
26 # increases the executable size so use this when really needed.
27 #
28 # The macro iterates over the input data which can be any files and generates
29 # outputs file in the form CMAKE_CURRENT_BINARY_DIR/assets/basename.cpp.
30 #
31 # The macro removes the extension from the filename and create a static array
32 # with that name, thus you need to specify a filename that is compatible with
33 # C++ identifiers!
34 #
35 # Correct:
36 # - myfile.png
37 # - startup_logo.png
38 #
39 # Incorrect:
40 # - useful-code.ogg
41 # - archive.tar.xz
42 #
43 # Note: this macro requires the target mlk-bcc (tools/bcc directory).
44 #
45
46 macro(malikania_build_assets inputs outputs)
47 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets)
48
49 foreach (in ${inputs})
50 get_filename_component(basename ${in} NAME_WE)
51 set(out ${CMAKE_CURRENT_BINARY_DIR}/assets/${basename}.cpp)
52 add_custom_command(
53 OUTPUT ${out}
54 COMMENT "Generating binary data from ${in}"
55 DEPENDS ${in}
56 COMMAND
57 $<TARGET_FILE:mlk-bcc> ${basename} ${in} ${out}
58 )
59 list(APPEND ${outputs} ${out})
60 endforeach ()
61 endmacro()