X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=cmake%2FQuasselMacros.cmake;h=08eaaa8c43e9ceb4bbe6da80d607fd9d5f967333;hp=f0791ec6366eb6b233f04b85421ed3ba9232fcf6;hb=18746a803a6cf040c6525f8916bb721c1edbce1f;hpb=a2121709c6e39fe3640163e5a4b6b96b8b0f1ab8 diff --git a/cmake/QuasselMacros.cmake b/cmake/QuasselMacros.cmake index f0791ec6..08eaaa8c 100644 --- a/cmake/QuasselMacros.cmake +++ b/cmake/QuasselMacros.cmake @@ -1,56 +1,66 @@ -# This macro sets variables for the Qt modules we need. +# This file contains various functions and macros useful for building Quassel. +# +# (C) 2014-2018 by the Quassel Project +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +################################################################################################### -macro(setup_qt_variables) - set(QUASSEL_QT_LIBRARIES ) - set(QUASSEL_QT_INCLUDES ${QT_INCLUDE_DIR}) # Qt4 - set(QUASSEL_QT_DEFINITIONS ${QT_DEFINITIONS}) # Qt4 +################################################################################################### +# Adds a library target for a Quassel module. +# +# It expects the (CamelCased) module name as a parameter, and derives various +# strings from it. For example, quassel_add_module(Client) produces +# - a library target named quassel_client with output name (lib)quassel-client(.so) +# - an alias target named Quassel::Client in global scope +# +# The function exports the TARGET variable which can be used in the current scope +# for setting source files, properties, link dependencies and so on. +# To refer to the target outside of the current scope, e.g. for linking, use +# the alias name. +# +function(quassel_add_module _module) + # Derive target, alias target, output name from the given module name + set(alias "Quassel::${_module}") + set(target ${alias}) + string(TOLOWER ${target} target) + string(REPLACE "::" "_" target ${target}) + string(REPLACE "_" "-" output_name ${target}) - IF(WIN32) - set(MAIN Main) - ENDIF(WIN32) - foreach(qtmod Core ${ARGV} ${MAIN}) - if(WITH_QT5) - find_package(Qt5${qtmod} ${QT_MIN_VERSION} REQUIRED) - list(APPEND QUASSEL_QT_LIBRARIES ${Qt5${qtmod}_LIBRARIES}) - list(APPEND QUASSEL_QT_INCLUDES ${Qt5${qtmod}_INCLUDE_DIRS}) - list(APPEND QUASSEL_QT_DEFINITIONS ${Qt5${qtmod}_DEFINITIONS} ${Qt5${qtmod}_EXECUTABLE_COMPILE_FLAGS}) - else(WITH_QT5) - string(TOUPPER ${qtmod} QTMOD) - list(APPEND QUASSEL_QT_LIBRARIES ${QT_QT${QTMOD}_LIBRARY}) - if(STATIC) - list(APPEND QUASSEL_QT_LIBRARIES ${QT_QT${QTMOD}_LIB_DEPENDENCIES}) - endif(STATIC) - list(APPEND QUASSEL_QT_INCLUDES ${QT_QT${QTMOD}_INCLUDE_DIR}) - list(APPEND QUASSEL_QT_DEFINITIONS -DQT_QT${QTMOD}_LIB) - endif(WITH_QT5) - endforeach(qtmod) + add_library(${target} STATIC "") + add_library(${alias} ALIAS ${target}) - list(REMOVE_DUPLICATES QUASSEL_QT_LIBRARIES) - list(REMOVE_DUPLICATES QUASSEL_QT_INCLUDES) - list(REMOVE_DUPLICATES QUASSEL_QT_DEFINITIONS) + set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${output_name} + ) - # The COMPILE_FLAGS property expects a string, not a list... - set(QUASSEL_QT_COMPILEFLAGS ) - foreach(flag ${QUASSEL_QT_DEFINITIONS}) - set(QUASSEL_QT_COMPILEFLAGS "${QUASSEL_QT_COMPILEFLAGS} ${flag}") - endforeach(flag) + target_include_directories(${target} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # for generated files + ) -endmacro(setup_qt_variables) + # Export the target name for further use + set(TARGET ${target} PARENT_SCOPE) +endfunction() + +###################################### +# Macros for dealing with translations +###################################### # This generates a .ts from a .po file macro(generate_ts outvar basename) set(input ${basename}.po) set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts) add_custom_command(OUTPUT ${output} - COMMAND ${QT_LCONVERT_EXECUTABLE} + COMMAND $ ARGS -i ${input} -of ts -o ${output} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/po # This is a workaround to add (duplicate) strings that lconvert missed to the .ts - COMMAND ${QT_LUPDATE_EXECUTABLE} + COMMAND $ ARGS -silent - ${CMAKE_SOURCE_DIR}/src/ + ${CMAKE_SOURCE_DIR}/src/ -ts ${output} DEPENDS ${basename}.po) set(${outvar} ${output}) @@ -61,7 +71,7 @@ macro(generate_qm outvar basename) set(input ${CMAKE_BINARY_DIR}/po/${basename}.ts) set(output ${CMAKE_BINARY_DIR}/po/${basename}.qm) add_custom_command(OUTPUT ${output} - COMMAND ${QT_LRELEASE_EXECUTABLE} + COMMAND $ ARGS -silent ${input} DEPENDS ${basename}.ts)