1 # This file contains various macros useful for building Quassel.
3 # (C) 2014 by the Quassel Project <devel@quassel-irc.org>
5 # The qt5_use_modules function was taken from Qt 5.10.1 (and modified):
6 # (C) 2005-2011 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 # Qt 5.11 removed the qt5_use_modules function, so we need to provide it until we can switch to a modern CMake version.
16 # If present, the Qt-provided version will be used automatically instead.
17 function(qt5_use_modules _target _link_type)
18 if (NOT TARGET ${_target})
19 message(FATAL_ERROR "The first argument to qt5_use_modules must be an existing target.")
21 if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE" )
22 set(_qt5_modules ${ARGN})
23 set(_qt5_link_type ${_link_type})
25 set(_qt5_modules ${_link_type} ${ARGN})
28 if ("${_qt5_modules}" STREQUAL "")
29 message(FATAL_ERROR "qt5_use_modules requires at least one Qt module to use.")
31 foreach(_module ${_qt5_modules})
32 if (NOT Qt5${_module}_FOUND)
33 find_package(Qt5${_module} PATHS "${_Qt5_COMPONENT_PATH}" NO_DEFAULT_PATH)
34 if (NOT Qt5${_module}_FOUND)
35 message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
38 target_link_libraries(${_target} ${_qt5_link_type} ${Qt5${_module}_LIBRARIES})
39 set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Qt5${_module}_INCLUDE_DIRS})
40 set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${Qt5${_module}_COMPILE_DEFINITIONS})
41 if (Qt5_POSITION_INDEPENDENT_CODE
42 AND (CMAKE_VERSION VERSION_LESS 2.8.12
43 AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
44 OR CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)))
45 set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
50 ######################################
51 # Macros for dealing with translations
52 ######################################
54 # This generates a .ts from a .po file
55 macro(generate_ts outvar basename)
56 set(input ${basename}.po)
57 set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts)
58 add_custom_command(OUTPUT ${output}
59 COMMAND ${QT_LCONVERT_EXECUTABLE}
63 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/po
64 # This is a workaround to add (duplicate) strings that lconvert missed to the .ts
65 COMMAND ${QT_LUPDATE_EXECUTABLE}
67 ${CMAKE_SOURCE_DIR}/src/
69 DEPENDS ${basename}.po)
70 set(${outvar} ${output})
71 endmacro(generate_ts outvar basename)
73 # This generates a .qm from a .ts file
74 macro(generate_qm outvar basename)
75 set(input ${CMAKE_BINARY_DIR}/po/${basename}.ts)
76 set(output ${CMAKE_BINARY_DIR}/po/${basename}.qm)
77 add_custom_command(OUTPUT ${output}
78 COMMAND ${QT_LRELEASE_EXECUTABLE}
81 DEPENDS ${basename}.ts)
82 set(${outvar} ${output})
83 endmacro(generate_qm outvar basename)