Set link directories properly
[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 link_directories(${LXQT_LIBRARY_DIRS})
42
43 #cmake_policy(SET CMP0005 NEW)
44 add_definitions(-DLXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\")
45 add_definitions(-DLXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\")
46 add_definitions(-DLXQT_VERSION=\"${LXQT_VERSION}\")
47
48 # for backward compatability ----->
49 add_definitions(-DLXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\")
50 add_definitions(-DLXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\")
51 add_definitions(-DLXQT_VERSION=\"${LXQT_VERSION}\")
52 # for backward compatability <-----
53
54 find_package(Qt4 REQUIRED QUIET)
55 include(${QT_USE_FILE})
56
57 #**********************************************************
58 # DESKTOP files
59 #**********************************************************
60
61 function(lxqt_translate_desktop _RESULT)
62     set(_translationDir "translations")
63
64     # Parse arguments ***************************************
65     set(_state "")
66     foreach (_arg ${ARGN})
67         if (
68             ("${_arg}_I_HATE_CMAKE" STREQUAL "SOURCES_I_HATE_CMAKE") OR
69             ("${_arg}_I_HATE_CMAKE" STREQUAL "TRANSLATION_DIR_I_HATE_CMAKE")
70            )
71
72             set(_state ${_arg})
73
74         else()
75             if("${_state}" STREQUAL "SOURCES")
76                 get_filename_component (__file ${_arg} ABSOLUTE)
77                 set(_sources  ${_sources} ${__file})
78                 #set(_sources  ${_sources} ${_arg})
79
80             elseif("${_state}" STREQUAL "TRANSLATION_DIR")
81                 set(_translationDir ${_arg})
82                 set(_state "")
83
84             else()
85                 MESSAGE(FATAL_ERROR
86                   "Unknown argument '${_arg}'.\n"
87                   "See ${CMAKE_CURRENT_LIST_FILE} for more information.\n"
88                 )
89             endif()
90         endif()
91     endforeach(_arg)
92
93     get_filename_component (_translationDir ${_translationDir} ABSOLUTE)
94
95     foreach (_inFile ${_sources})
96         get_filename_component(_inFile   ${_inFile} ABSOLUTE)
97         get_filename_component(_fileName ${_inFile} NAME_WE)
98         #Extract the real extension ............
99         get_filename_component(_fileExt  ${_inFile} EXT)
100         string(REPLACE ".in" "" _fileExt ${_fileExt})
101         #.......................................
102         set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}${_fileExt}")
103
104         file(GLOB _translations
105             ${_translationDir}/${_fileName}_*${_fileExt}
106             ${_translationDir}/local/${_fileName}_*${_fileExt}
107         )
108
109         set(_pattern "'\\[.*]\\s*='")
110         if (_translations)
111             add_custom_command(OUTPUT ${_outFile}
112                 COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
113                 COMMAND grep --no-filename ${_pattern} ${_translations} >> ${_outFile}
114                 COMMENT "Generating ${_fileName}${_fileExt}"
115             )
116         else()
117             add_custom_command(OUTPUT ${_outFile}
118                 COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile}
119                 COMMENT "Generating ${_fileName}${_fileExt}"
120             )
121         endif()
122
123         set(__result ${__result} ${_outFile})
124     endforeach()
125
126     set(${_RESULT} ${__result} PARENT_SCOPE)
127 endfunction()
128
129
130 macro(lxqt_set_default_value VAR_NAME VAR_VALUE)
131     if (NOT DEFINED ${VAR_NAME})
132         set (${VAR_NAME} ${VAR_VALUE})
133     endif ()
134 endmacro()