1 # This file contains various macros useful for building Quassel.
3 # (C) 2014 by the Quassel Project <devel@quassel-irc.org>
5 # The qt4_use_modules function was taken from CMake's Qt4Macros.cmake:
6 # (C) 2005-2009 Kitware, Inc.
8 # Redistribution and use is allowed according to the terms of the BSD license.
9 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
11 ############################
12 # Macros for dealing with Qt
13 ############################
15 # CMake gained this function in 2.8.10. To be able to use older versions, we've copied
16 # this here. If present, the function from CMake will take precedence and our copy will be ignored.
17 function(qt4_use_modules _target _link_type)
18 if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
20 set(link_type ${_link_type})
22 set(modules ${_link_type} ${ARGN})
24 foreach(_module ${modules})
25 string(TOUPPER ${_module} _ucmodule)
26 set(_targetPrefix QT_QT${_ucmodule})
27 if (_ucmodule STREQUAL QAXCONTAINER OR _ucmodule STREQUAL QAXSERVER)
28 if (NOT QT_Q${_ucmodule}_FOUND)
29 message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
31 set(_targetPrefix QT_Q${_ucmodule})
33 if (NOT QT_QT${_ucmodule}_FOUND)
34 message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
36 if ("${_ucmodule}" STREQUAL "MAIN")
37 message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
40 target_link_libraries(${_target} ${link_type} ${${_targetPrefix}_LIBRARIES})
41 set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${${_targetPrefix}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
42 set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${${_targetPrefix}_COMPILE_DEFINITIONS})
46 # Some wrappers for simplifying dual-Qt support
48 function(qt_use_modules)
50 qt5_use_modules(${ARGN})
52 qt4_use_modules(${ARGN})
56 function(qt_wrap_ui _var)
58 qt5_wrap_ui(var ${ARGN})
60 qt4_wrap_ui(var ${ARGN})
62 set(${_var} ${${_var}} ${var} PARENT_SCOPE)
65 function(qt_add_resources _var)
67 qt5_add_resources(var ${ARGN})
69 qt4_add_resources(var ${ARGN})
71 set(${_var} ${${_var}} ${var} PARENT_SCOPE)
74 function(qt_add_dbus_interface _var)
76 qt5_add_dbus_interface(var ${ARGN})
78 qt4_add_dbus_interface(var ${ARGN})
80 set(${_var} ${${_var}} ${var} PARENT_SCOPE)
83 function(qt_add_dbus_adaptor _var)
85 qt5_add_dbus_adaptor(var ${ARGN})
87 qt4_add_dbus_adaptor(var ${ARGN})
89 set(${_var} ${${_var}} ${var} PARENT_SCOPE)
92 ######################################
93 # Macros for dealing with translations
94 ######################################
96 # This generates a .ts from a .po file
97 macro(generate_ts outvar basename)
98 set(input ${basename}.po)
99 set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts)
100 add_custom_command(OUTPUT ${output}
101 COMMAND ${QT_LCONVERT_EXECUTABLE}
105 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/po
106 # This is a workaround to add (duplicate) strings that lconvert missed to the .ts
107 COMMAND ${QT_LUPDATE_EXECUTABLE}
109 ${CMAKE_SOURCE_DIR}/src/
111 DEPENDS ${basename}.po)
112 set(${outvar} ${output})
113 endmacro(generate_ts outvar basename)
115 # This generates a .qm from a .ts file
116 macro(generate_qm outvar basename)
117 set(input ${CMAKE_BINARY_DIR}/po/${basename}.ts)
118 set(output ${CMAKE_BINARY_DIR}/po/${basename}.qm)
119 add_custom_command(OUTPUT ${output}
120 COMMAND ${QT_LRELEASE_EXECUTABLE}
123 DEPENDS ${basename}.ts)
124 set(${outvar} ${output})
125 endmacro(generate_qm outvar basename)