1 # This file contains various functions and macros useful for building Quassel.
3 # (C) 2014-2018 by the Quassel Project <devel@quassel-irc.org>
5 # Redistribution and use is allowed according to the terms of the BSD license.
6 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
7 ###################################################################################################
9 ###################################################################################################
10 # Adds a library target for a Quassel module.
12 # It expects the (CamelCased) module name as a parameter, and derives various
13 # strings from it. For example, quassel_add_module(Client) produces
14 # - a library target named quassel_client with output name (lib)quassel-client(.so)
15 # - an alias target named Quassel::Client in global scope
17 # The function exports the TARGET variable which can be used in the current scope
18 # for setting source files, properties, link dependencies and so on.
19 # To refer to the target outside of the current scope, e.g. for linking, use
22 function(quassel_add_module _module)
23 # Derive target, alias target, output name from the given module name
24 set(alias "Quassel::${_module}")
26 string(TOLOWER ${target} target)
27 string(REPLACE "::" "_" target ${target})
28 string(REPLACE "_" "-" output_name ${target})
30 add_library(${target} STATIC "")
31 add_library(${alias} ALIAS ${target})
33 set_target_properties(${target} PROPERTIES
34 OUTPUT_NAME ${output_name}
37 target_include_directories(${target}
38 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
39 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # for generated files
42 # Export the target name for further use
43 set(TARGET ${target} PARENT_SCOPE)
46 ######################################
47 # Macros for dealing with translations
48 ######################################
50 # This generates a .ts from a .po file
51 macro(generate_ts outvar basename)
52 set(input ${basename}.po)
53 set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts)
54 add_custom_command(OUTPUT ${output}
55 COMMAND ${QT_LCONVERT_EXECUTABLE}
59 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/po
60 # This is a workaround to add (duplicate) strings that lconvert missed to the .ts
61 COMMAND ${QT_LUPDATE_EXECUTABLE}
63 ${CMAKE_SOURCE_DIR}/src/
65 DEPENDS ${basename}.po)
66 set(${outvar} ${output})
67 endmacro(generate_ts outvar basename)
69 # This generates a .qm from a .ts file
70 macro(generate_qm outvar basename)
71 set(input ${CMAKE_BINARY_DIR}/po/${basename}.ts)
72 set(output ${CMAKE_BINARY_DIR}/po/${basename}.qm)
73 add_custom_command(OUTPUT ${output}
74 COMMAND ${QT_LRELEASE_EXECUTABLE}
77 DEPENDS ${basename}.ts)
78 set(${outvar} ${output})
79 endmacro(generate_qm outvar basename)