cmake: Modernize use of Qt Linguist Tools
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 2 Aug 2018 23:11:08 +0000 (01:11 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
All Qt versions we support provide an alias target for the linguist
tools. Thus, remove the fallback for older Qt versions.

Use the LOCATION property of the tools' target instead of relying
on the corresponding QT_L*_EXECUTABLE variables.

CMakeLists.txt
cmake/QuasselMacros.cmake
po/CMakeLists.txt

index c162ec4..d9dc2a8 100644 (file)
@@ -333,25 +333,6 @@ set_package_properties(Qt5LinguistTools PROPERTIES TYPE RECOMMENDED
     PURPOSE "Required for having translations"
 )
 
     PURPOSE "Required for having translations"
 )
 
-# Some Qt5 versions do not define a target for lconvert, so we need to find it ourselves
-if (Qt5LinguistTools_FOUND)
-    if (NOT TARGET Qt5::lconvert AND TARGET Qt5::lrelease)
-        get_target_property(_lrelease_location Qt5::lrelease LOCATION)
-        get_filename_component(_lrelease_path ${_lrelease_location} PATH)
-        find_program(QT_LCONVERT_EXECUTABLE NAMES lconvert-qt5 lconvert PATHS ${_lrelease_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
-    elseif(TARGET Qt5::lconvert AND NOT Qt5_LCONVERT_EXECUTABLE)
-        # Newer Qt5 versions define the target, but not the Qt5_LCONVERT_EXECUTABLE variable for some reason
-        get_target_property(QT_LCONVERT_EXECUTABLE Qt5::lconvert LOCATION)
-    endif()
-
-    # Compatibility with the Qt4 variables
-    set(QT_LRELEASE_EXECUTABLE ${Qt5_LRELEASE_EXECUTABLE})
-    set(QT_LUPDATE_EXECUTABLE ${Qt5_LUPDATE_EXECUTABLE})
-    if (Qt5_LCONVERT_EXECUTABLE)
-        set(QT_LCONVERT_EXECUTABLE ${Qt5_LCONVERT_EXECUTABLE})
-    endif()
-endif()
-
 # Non-Qt-based packages
 
 find_package(ZLIB REQUIRED)
 # Non-Qt-based packages
 
 find_package(ZLIB REQUIRED)
@@ -461,8 +442,6 @@ if (NOT WIN32)
     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
 endif()
 
     add_feature_info("syslog.h" HAVE_SYSLOG "Provide support for logging to the syslog")
 endif()
 
-add_feature_info("Qt Linguist Tools" QT_LCONVERT_EXECUTABLE "Translation support for Quassel")
-
 if (EMBED_DATA)
     message(STATUS "Embedding data files into the binary")
 else()
 if (EMBED_DATA)
     message(STATUS "Embedding data files into the binary")
 else()
index 8512866..08eaaa8 100644 (file)
@@ -52,13 +52,13 @@ macro(generate_ts outvar basename)
   set(input ${basename}.po)
   set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts)
   add_custom_command(OUTPUT ${output}
   set(input ${basename}.po)
   set(output ${CMAKE_BINARY_DIR}/po/${basename}.ts)
   add_custom_command(OUTPUT ${output}
-          COMMAND ${QT_LCONVERT_EXECUTABLE}
+          COMMAND $<TARGET_PROPERTY:Qt5::lconvert,LOCATION>
           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
           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 $<TARGET_PROPERTY:Qt5::lupdate,LOCATION>
           ARGS -silent
                ${CMAKE_SOURCE_DIR}/src/
                -ts ${output}
           ARGS -silent
                ${CMAKE_SOURCE_DIR}/src/
                -ts ${output}
@@ -71,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}
   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 $<TARGET_PROPERTY:Qt5::lrelease,LOCATION>
           ARGS -silent
                ${input}
           DEPENDS ${basename}.ts)
           ARGS -silent
                ${input}
           DEPENDS ${basename}.ts)
index cac949c..1d95aa6 100644 (file)
@@ -1,7 +1,7 @@
 # Generate and add translations
 # The LINGUAS variable can be used to limit that set
 
 # Generate and add translations
 # The LINGUAS variable can be used to limit that set
 
-if(QT_LCONVERT_EXECUTABLE)
+if (TARGET Qt5::lconvert)
   # get environment variable for translations
   set(LINGUAS "$ENV{LINGUAS}")
   string(REGEX REPLACE "[ \t]+" \; output "${LINGUAS}")
   # get environment variable for translations
   set(LINGUAS "$ENV{LINGUAS}")
   string(REGEX REPLACE "[ \t]+" \; output "${LINGUAS}")