cmake: Use official CMake config for QCA
[quassel.git] / cmake / QuasselMacros.cmake
1 # This file contains various macros useful for building Quassel.
2 #
3 # (C) 2014 by the Quassel Project <devel@quassel-irc.org>
4 #
5 # The qt5_use_modules function was taken from Qt 5.10.1 (and modified):
6 # (C) 2005-2011 Kitware, Inc.
7 #
8 # Redistribution and use is allowed according to the terms of the BSD license.
9 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
10
11 ############################
12 # Macros for dealing with Qt
13 ############################
14
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.")
20     endif()
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})
24     else()
25         set(_qt5_modules ${_link_type} ${ARGN})
26     endif()
27
28     if ("${_qt5_modules}" STREQUAL "")
29         message(FATAL_ERROR "qt5_use_modules requires at least one Qt module to use.")
30     endif()
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.")
36             endif()
37         endif()
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})
46         endif()
47     endforeach()
48 endfunction()
49
50 ######################################
51 # Macros for dealing with translations
52 ######################################
53
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}
60           ARGS -i ${input}
61                -of ts
62                -o ${output}
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}
66           ARGS -silent
67                ${CMAKE_SOURCE_DIR}/src/
68                -ts ${output}
69           DEPENDS ${basename}.po)
70   set(${outvar} ${output})
71 endmacro(generate_ts outvar basename)
72
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}
79           ARGS -silent
80                ${input}
81           DEPENDS ${basename}.ts)
82   set(${outvar} ${output})
83 endmacro(generate_qm outvar basename)