File: FindASPELL.cmake

package info (click to toggle)
cmake 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 147,284 kB
  • sloc: ansic: 403,915; cpp: 290,772; sh: 4,102; python: 3,357; yacc: 3,106; lex: 1,189; f90: 532; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 230; perl: 217; objc: 215; xml: 198; makefile: 97; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (302 lines) | stat: -rw-r--r-- 8,256 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindASPELL
----------

Finds the GNU Aspell spell checker library.

Components
^^^^^^^^^^

This module supports the following components:

``ASPELL``
  .. versionadded:: 4.1

  Finds the Aspell library and its include paths.

``Executable``
  .. versionadded:: 4.1

  Finds the Aspell command-line interactive spell checker executable.

Components can be specified using the standard CMake syntax:

.. code-block:: cmake

  find_package(ASPELL [COMPONENTS <components>...])

If no ``COMPONENTS`` are specified, the module searches for both the ``ASPELL``
and ``Executable`` components by default.

Imported Targets
^^^^^^^^^^^^^^^^

This module provides the following :ref:`Imported Targets` when
:prop_gbl:`CMAKE_ROLE` is ``PROJECT``:

``ASPELL::ASPELL``
  .. versionadded:: 4.1

  Target encapsulating the Aspell library usage requirements.  It is available
  only when the ``ASPELL`` component is found.

``ASPELL::Executable``
  .. versionadded:: 4.1

  Target encapsulating the Aspell command-line spell checker executable.  It is
  available only when the ``Executable`` component is found.

Result Variables
^^^^^^^^^^^^^^^^

This module defines the following variables:

``ASPELL_FOUND``
  Boolean indicating whether the requested Aspell components have been found.

``ASPELL_VERSION``
  .. versionadded:: 4.1

  Version string of the found Aspell if any.  It may be only determined if the
  ``Executable`` component is found.  If version isn't determined, version value
  is not set.

``ASPELL_INCLUDE_DIRS``
  .. versionadded:: 4.1

  Include directories needed to use Aspell.  They are available when the
  ``ASPELL`` component is found.

  The Aspell library may also provide a backward-compatible interface for Pspell
  via the ``pspell.h`` header file.  If such an interface is found, it is also
  added to the list of include directories.

``ASPELL_LIBRARIES``
  Libraries needed to link to Aspell.  They are available when the ``ASPELL``
  component is found.

  .. versionchanged:: 4.1
    This variable is now set as a regular result variable instead of being a
    cache variable.

Cache Variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``ASPELL_INCLUDE_DIR``
  The directory containing the ``aspell.h`` header file when using the
  ``Executable`` component.

``ASPELL_LIBRARY``
  .. versionadded:: 4.1

  The path to the Aspell library when using the ``ASPELL`` component.

``ASPELL_EXECUTABLE``
  The path to the ``aspell`` command-line spell checker program when using the
  ``Executable`` component.

Examples
^^^^^^^^

Finding the Aspell library with CMake 4.1 or later and linking it to a project
target:

.. code-block:: cmake

  find_package(ASPELL COMPONENTS ASPELL)
  target_link_libraries(project_target PRIVATE ASPELL::ASPELL)

When writing backward-compatible code that supports CMake 4.0 and earlier, a
local imported target can be defined directly in the project:

.. code-block:: cmake

  find_package(ASPELL COMPONENTS ASPELL)
  if(ASPELL_FOUND AND NOT TARGET ASPELL::ASPELL)
    add_library(ASPELL::ASPELL INTERFACE IMPORTED)
    set_target_properties(
      ASPELL::ASPELL
      PROPERTIES
        INTERFACE_LINK_LIBRARIES "${ASPELL_LIBRARIES}"
        INTERFACE_INCLUDE_DIRECTORIES "${ASPELL_INCLUDE_DIR}"
    )
  endif()
  target_link_libraries(project_target PRIVATE ASPELL::ASPELL)

Example, how to execute the ``aspell`` command-line spell checker in a project:

.. code-block:: cmake

  find_package(ASPELL COMPONENTS Executable)
  execute_process(COMMAND ${ASPELL_EXECUTABLE} --help)
#]=======================================================================]

set(_ASPELL_REASON_FAILURE_MESSAGE "")
set(_ASPELL_REQUIRED_VARS "")

# Set default components, when 'COMPONENTS <components>...' are not specified in
# the 'find_package(ASPELL ...)' call.
if(NOT ASPELL_FIND_COMPONENTS)
  set(ASPELL_FIND_COMPONENTS "ASPELL" "Executable")
  set(ASPELL_FIND_REQUIRED_ASPELL TRUE)
  set(ASPELL_FIND_REQUIRED_Executable TRUE)
endif()

if("ASPELL" IN_LIST ASPELL_FIND_COMPONENTS)
  find_path(
    ASPELL_INCLUDE_DIR
    NAMES aspell.h
    DOC "The directory containing <aspell.h>."
  )
  mark_as_advanced(ASPELL_INCLUDE_DIR)

  if(NOT ASPELL_INCLUDE_DIR)
    string(APPEND _ASPELL_REASON_FAILURE_MESSAGE "aspell.h could not be found. ")
  endif()

  # Find backward-compatibility interface for Pspell.
  find_path(
    ASPELL_PSPELL_INCLUDE_DIR
    NAMES pspell.h
    PATH_SUFFIXES pspell
    DOC "Directory containing <pspell.h> BC interface header"
  )
  mark_as_advanced(ASPELL_PSPELL_INCLUDE_DIR)

  # For backward compatibility in projects supporting CMake 4.0 or earlier.
  # Previously the ASPELL_LIBRARIES was a cache variable storing the
  # find_library result.
  if(DEFINED ASPELL_LIBRARIES AND NOT DEFINED ASPELL_LIBRARY)
    set(ASPELL_LIBRARY ${ASPELL_LIBRARIES})
  endif()

  find_library(
    ASPELL_LIBRARY
    NAMES aspell aspell-15 libaspell-15 libaspell
    DOC "The path to the Aspell library."
  )
  mark_as_advanced(ASPELL_LIBRARY)

  if(NOT ASPELL_LIBRARY)
    string(APPEND _ASPELL_REASON_FAILURE_MESSAGE "Aspell library not found. ")
  endif()

  if(ASPELL_INCLUDE_DIR AND ASPELL_LIBRARY)
    set(ASPELL_ASPELL_FOUND TRUE)
  else()
    set(ASPELL_ASPELL_FOUND FALSE)
  endif()

  if(ASPELL_FIND_REQUIRED_ASPELL)
    list(APPEND _ASPELL_REQUIRED_VARS ASPELL_LIBRARY ASPELL_INCLUDE_DIR)
  endif()
endif()

if("Executable" IN_LIST ASPELL_FIND_COMPONENTS)
  find_program(
    ASPELL_EXECUTABLE
    NAMES aspell
    DOC "The path to the aspell command-line utility program."
  )
  mark_as_advanced(ASPELL_EXECUTABLE)

  if(NOT ASPELL_EXECUTABLE)
    string(
      APPEND
      _ASPELL_REASON_FAILURE_MESSAGE
      "Aspell command-line executable not found. "
    )
    set(ASPELL_Executable_FOUND FALSE)
  else()
    set(ASPELL_Executable_FOUND TRUE)

    block(PROPAGATE ASPELL_VERSION)
      execute_process(
        COMMAND ${ASPELL_EXECUTABLE} --version
        OUTPUT_VARIABLE output
        RESULT_VARIABLE result
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
      )
      if(result EQUAL 0 AND output MATCHES "([0-9.]+)[)]?$")
        set(ASPELL_VERSION ${CMAKE_MATCH_1})
      endif()
    endblock()
  endif()

  if(ASPELL_FIND_REQUIRED_Executable)
    list(APPEND _ASPELL_REQUIRED_VARS ASPELL_EXECUTABLE)
  endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  ASPELL
  REQUIRED_VARS ${_ASPELL_REQUIRED_VARS}
  HANDLE_COMPONENTS
  VERSION_VAR ASPELL_VERSION
  REASON_FAILURE_MESSAGE "${_ASPELL_REASON_FAILURE_MESSAGE}"
)

unset(_ASPELL_REASON_FAILURE_MESSAGE)
unset(_ASPELL_REQUIRED_VARS)

if(NOT ASPELL_FOUND)
  return()
endif()

get_property(_ASPELL_ROLE GLOBAL PROPERTY CMAKE_ROLE)

if("ASPELL" IN_LIST ASPELL_FIND_COMPONENTS AND ASPELL_ASPELL_FOUND)
  set(ASPELL_INCLUDE_DIRS ${ASPELL_INCLUDE_DIR})
  if(ASPELL_PSPELL_INCLUDE_DIR)
    list(APPEND ASPELL_INCLUDE_DIRS ${ASPELL_PSPELL_INCLUDE_DIR})
    list(REMOVE_DUPLICATES ASPELL_INCLUDE_DIRS)
  endif()
  set(ASPELL_LIBRARIES ${ASPELL_LIBRARY})

  if(_ASPELL_ROLE STREQUAL "PROJECT" AND NOT TARGET ASPELL::ASPELL)
    if(IS_ABSOLUTE "${ASPELL_LIBRARY}")
      add_library(ASPELL::ASPELL UNKNOWN IMPORTED)
      set_target_properties(
        ASPELL::ASPELL
        PROPERTIES
          IMPORTED_LOCATION "${ASPELL_LIBRARY}"
      )
    else()
      add_library(ASPELL::ASPELL INTERFACE IMPORTED)
      set_target_properties(
        ASPELL::ASPELL
        PROPERTIES
          IMPORTED_LIBNAME "${ASPELL_LIBRARY}"
      )
    endif()

    set_target_properties(
      ASPELL::ASPELL
      PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${ASPELL_INCLUDE_DIRS}"
    )
  endif()
endif()

if(
  _ASPELL_ROLE STREQUAL "PROJECT"
  AND "Executable" IN_LIST ASPELL_FIND_COMPONENTS
  AND ASPELL_Executable_FOUND
  AND NOT TARGET ASPELL::Executable
)
  add_executable(ASPELL::Executable IMPORTED)
  set_target_properties(
    ASPELL::Executable
    PROPERTIES
      IMPORTED_LOCATION "${ASPELL_EXECUTABLE}"
  )
endif()

unset(_ASPELL_ROLE)