]> git.lyx.org Git - lyx.git/blob - development/cmake/scripts/LyXCreateImagesResource.cmake
Customization: correct some color names.
[lyx.git] / development / cmake / scripts / LyXCreateImagesResource.cmake
1 #  Copyright (c) 2006-2011 Peter Kümmel, <syntheticpp@gmx.net>
2 #                2012, Kornel Benko, <kornel@lyx.org>
3 #
4 #  Redistribution and use in source and binary forms, with or without
5 #  modification, are permitted provided that the following conditions
6 #  are met:
7 #
8 #  1. Redistributions of source code must retain the copyright
9 #         notice, this list of conditions and the following disclaimer.
10 #  2. Redistributions in binary form must reproduce the copyright
11 #         notice, this list of conditions and the following disclaimer in the
12 #         documentation and/or other materials provided with the distribution.
13 #  3. The name of the author may not be used to endorse or promote products
14 #         derived from this software without specific prior written permission.
15 #
16 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 #  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 #  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 #  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 #  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 #  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 #  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # To call this script, one has to provide following parameters
28 # IMAGES_DIR                # root for the directory-tree for .png, .svgz and .git image files 
29 # RESOURCE_NAME             # full path of the resulting resource-file
30 # MAPPED_DIR                # Path-prefix to be removed from the file name entries
31
32 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
33
34 if(NOT RESOURCE_NAME)
35   message(FATAL_ERROR "RESOURCE_NAME not given")
36 endif()
37
38 message(STATUS "Generating ${RESOURCE_NAME}")
39
40 if(NOT IS_DIRECTORY ${IMAGES_DIR})
41   message(FATAL_ERROR "Directory ${IMAGES_DIR} does not exist")
42 endif()
43
44 if(NOT EXISTS ${MAPPED_DIR})
45   message(FATAL_ERROR "Directory ${MAPPED_DIR} does not exist")
46 endif()
47
48 file(GLOB_RECURSE images_png      ${IMAGES_DIR}/*.png)
49 file(GLOB_RECURSE images_gif      ${IMAGES_DIR}/*.gif)
50 file(GLOB_RECURSE images_svgz      ${IMAGES_DIR}/*.svgz)
51
52 set(images ${images_png} ${images_gif} ${images_svgz})
53
54 file(REMOVE ${RESOURCE_NAME})
55 if(EXISTS ${RESOURCE_NAME})
56   message(FATAL_ERROR "Cannot remove file ${RESOURCE_NAME}")
57 endif()
58
59 file(WRITE ${RESOURCE_NAME} "<!DOCTYPE RCC><RCC version=\"1.0\">\n")
60 file(APPEND ${RESOURCE_NAME} "<qresource>\n")
61
62 foreach (_current_FILE ${images})
63   get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
64   string(REGEX REPLACE "${MAPPED_DIR}" "" _file_name ${_abs_FILE})
65   file(APPEND ${RESOURCE_NAME} "         <file alias=\"${_file_name}\">${_abs_FILE}</file>\n")
66 endforeach (_current_FILE)
67
68 # copy lyx.svg too (and use versioning)
69 get_filename_component(_abs_FILE "${IMAGES_DIR}/lyx.svg" ABSOLUTE)
70 string(REGEX REPLACE "${MAPPED_DIR}" "" _file_name ${_abs_FILE})
71 file(APPEND ${RESOURCE_NAME} "         <file alias=\"lyx${SUFFIX}\">${_abs_FILE}</file>\n")
72
73 file(APPEND ${RESOURCE_NAME} "</qresource>\n")
74 file(APPEND ${RESOURCE_NAME} "</RCC>\n")
75
76 if(NOT EXISTS ${RESOURCE_NAME})
77   message(FATAL_ERROR "File ${RESOURCE_NAME} could not be created")
78 endif()