Warning, /network/konqueror/cmake/modules/FindHunspell.cmake is written in an unsupported language. File is not indexed.

0001 # This file is part of the KDE project.
0002 #
0003 # SPDX-FileCopyrightText: 2021 Stefano Crocco <posta@stefanocrocco.it>
0004 #
0005 # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 #[=======================================================================[.rst:
0007 FindHunspell
0008 -------
0009 
0010 Finds the Hunspell program and its availlable dictionaries
0011 
0012 Result Variables
0013 ^^^^^^^^^^^^^^^^
0014 
0015 This will define the following variables:
0016 
0017 ``Hunspell_FOUND``
0018   True if the system has the hunspell executable.
0019 ``Hunspell_EXECUTABLE``
0020   The path to the hunspell executable
0021 ``Hunspell_DICTIONARIES``
0022   A list of all dictionaries availlable to hunspell, as reported by hunspell -D
0023 ``Hunspell_UNIQUE_DICTIONARIES``
0024   A list of dictionaries availlable to hunspell without dictionaries with the same name. If more than one dictionary with the same name exists, the first one reported by hunspell -D will be included
0025 #]=======================================================================]
0026 
0027 find_program(Hunspell_EXECUTABLE hunspell)
0028 include(FindPackageHandleStandardArgs)
0029 find_package_handle_standard_args(Hunspell
0030   FOUND_VAR Hunspell_FOUND
0031   REQUIRED_VARS Hunspell_EXECUTABLE
0032 )
0033 
0034 if (Hunspell_FOUND)
0035   #Call hunspell -D to find list of available dictionaries
0036   execute_process(COMMAND ${Hunspell_EXECUTABLE} "-D" OUTPUT_VARIABLE Hunspell_OUTPUT ERROR_VARIABLE Hunspell_OUTPUT)
0037   #Convert output to a list of lines
0038   string(REPLACE "\n" ";" OUTPUT_AS_LIST ${Hunspell_OUTPUT})
0039   #NOTE: don't rely on the exact text of the first lines, as it can be translated
0040   #Remove the first 3 lines, as they aren't part of the dictionary list
0041   list(SUBLIST OUTPUT_AS_LIST 3 -1 OUTPUT_AS_LIST)
0042 
0043   set(Hunspell_DICTIONARIES "")
0044   set(Hunspell_UNIQUE_DICTIONARIES "")
0045   set(Hunspell_unique_dict_names "")
0046 
0047   #There may be more than one dictionary with the same name. We need a list
0048   #of unique dictionaries (as QtWebEngine only takes into account their name
0049   #and not their path)
0050   foreach(D ${OUTPUT_AS_LIST})
0051   #The content of Hunspell_DICTIONARIES isn't just the list of dictionaries:
0052   #the last entries are the line LOADED DICTIONARIES followed by a list of loaded
0053   #dictionary files which we aren't interested in. As soon as we find a line
0054   #not containing the path separator (/) we know that we have reached the LOADED DICTIONARIES
0055   #line and we can exit the loop
0056     string(FIND ${D} "/" separator_idx)
0057     #This means that / wasn't in the string
0058     if (separator_idx EQUAL -1)
0059       break()
0060     endif()
0061     list(APPEND Hunspell_DICTIONARIES ${D})
0062     get_filename_component(base ${D} NAME)
0063     list(FIND Hunspell_unique_dict_names ${base} dict_found)
0064     if (${dict_found} EQUAL -1)
0065       list(APPEND Hunspell_unique_dict_names ${base})
0066       list(APPEND Hunspell_UNIQUE_DICTIONARIES ${D})
0067     endif()
0068   endforeach()
0069 endif()
0070 list(JOIN Hunspell_unique_dict_names ", " detected_dictionaries)
0071 add_feature_info(Hunspell Hunspell_FOUND "with dictionaries ${detected_dictionaries}")