64bf5e5bc9f3ea8b61b68791eee3c8b8c97234d7
[lxde/liblxqt.git] / cmake / lxqt_use.cmake
1 # - Find the LXQt include and library dirs and define a some macros
2 #
3 # The module defines the following functions
4 #
5 # lxqt_translate_desktop(desktop_files
6 #                         SOURCES sources ...
7 #                         [TRANSLATION_DIR] translation_directory
8 #                        )
9 #     out: desktop_files
10 #     generates commands to create .desktop files from sources.
11 #     The generated filenames can be found in desktop_files.
12 #
13 #     in: sources
14 #     List of the desktop.in files
15 #
16 #     in: translation_directory
17 #     A relative path to the directory with translations files, it is
18 #     relative to the CMakeList.txt. By default is "translations"
19 #
20 #
21 # lxqt_set_default_value(VAR_NAME VAR_VALUE)
22 #
23 #
24 #
25 # The module defines the following definitions
26 #
27 #  -DLXQT_SHARE_DIR      - This allows to install and read the configs from non-standard locations
28 #
29 #  -DLXQT_ETC_XDG_DIR    - XDG standards expects system-wide configuration files in the
30 #                          /etc/xdg/lxqt location. Unfortunately QSettings we are using internally
31 #                          can be overriden in the Qt compilation time to use different path for
32 #                          system-wide configs. (for example configure ... -sysconfdir /etc/settings ...)
33 #                          This path can be found calling Qt4's qmake:
34 #                             qmake -query QT_INSTALL_CONFIGURATION
35 #
36 #
37 #
38
39 include_directories(${LXQT_INCLUDE_DIRS})
40
41 #cmake_policy(SET CMP0005 NEW)
42 add_definitions(-DLXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\")
43 add_definitions(-DLXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\")
44 add_definitions(-DLXQT_VERSION=\"${LXQT_VERSION}\")
45
46 # for backward compatability ----->
47 add_definitions(-DLXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\")
48 add_definitions(-DLXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\")
49 add_definitions(-DLXQT_VERSION=\"${LXQT_VERSION}\")
50 # for backward compatability <-----
51
52 find_package(Qt4 REQUIRED QUIET)
53 include(${QT_USE_FILE})
54
55 #**********************************************************
56 # DESKTOP files
57 #**********************************************************
58
59 function(lxqt_translate_desktop _RESULT)
60     set(_translationDir "translations")
61
62     # Parse arguments ***************************************
63     set(_state "")
64     foreach (_arg ${ARGN})
65         if (
66             ("${_arg}_I_HATE_CMAKE" STREQUAL "SOURCES_I_HATE_CMAKE") OR
67             ("${_arg}_I_HATE_CMAKE" STREQUAL "TRANSLATION_DIR_I_HATE_CMAKE")
68            )
69
70             set(_state ${_arg})
71
72         else()
73             if("${_state}" STREQUAL "SOURCES")
74                 get_filename_component (__file ${_arg} ABSOLUTE)
75                 set(_sources  ${_sources} ${__file})
76                 #set(_sources  ${_sources} ${_arg})
77
78             elseif("${_state}" STREQUAL "TRANSLATION_DIR")
79                 set(_translationDir ${_arg})
80                 set(_state "")
81
82             else()
83                 MESSAGE(FATAL_ERROR
84                   "Unknown argument '${_arg}'.\n"
85                   "See ${CMAKE_CURRENT_LIST_FILE} for more information.\n"
86                 )
87             endif()
88         endif()
89     endforeach(_arg)
90
91     get_filename_component (_translationDir ${_translationDir} ABSOLUTE)
92
93     foreach (_inFile ${_sources})
94         get_filename_component(_inFile   ${_inFile} ABSOLUTE)
95         get_filename_component(_fileName ${_inFile} NAME_WE)
96         #Extract the real extension ............
97         get_filename_component(_fileExt  ${_inFile} EXT)
98         string(REPLACE ".in" "" _fileExt ${_fileExt})
99         #.......................................
100         set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}${_fileExt}")
101
102         file(GLOB _translations
103             ${_translationDir}/${_fileName}_*${_fileExt}
104             ${_translationDir}/local/${_fileName}_*${_fileExt}
105         )
106
107         set(_pattern "'\\[.*]\\s*='")
108         if (_translations)
109             add_custom_command(OUTPUT ${_outFile}
110                 COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
111                 COMMAND grep --no-filename ${_pattern} ${_translations} >> ${_outFile}
112                 COMMENT "Generating ${_fileName}${_fileExt}"
113             )
114         else()
115             add_custom_command(OUTPUT ${_outFile}
116                 COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
117                 COMMENT "Generating ${_fileName}${_fileExt}"
118             )
119         endif()
120
121         set(__result ${__result} ${_outFile})
122     endforeach()
123
124     set(${_RESULT} ${__result} PARENT_SCOPE)
125 endfunction()
126
127
128 macro(lxqt_set_default_value VAR_NAME VAR_VALUE)
129     if (NOT DEFINED ${VAR_NAME})
130         set (${VAR_NAME} ${VAR_VALUE})
131     endif ()
132 endmacro()