1# Copyright 2022 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15cmake_minimum_required(VERSION 3.13..3.26) 16 17project(sapi_hunspell CXX) 18include(CTest) 19include(GoogleTest) 20 21set(CMAKE_CXX_STANDARD 17) 22set(CMAKE_CXX_STANDARD_REQUIRED True) 23 24if(NOT TARGET sapi::sapi) 25 set(SAPI_ROOT "../.." CACHE PATH "Path to the Sandboxed API source tree") 26 add_subdirectory("${SAPI_ROOT}" 27 "${CMAKE_BINARY_DIR}/sandboxed-api-build" 28 EXCLUDE_FROM_ALL) 29endif() 30 31FetchContent_Declare(libhunspell 32 GIT_REPOSITORY https://github.com/hunspell/hunspell.git 33 GIT_TAG 31e6d6323026a3bef12c5912ce032d88bfef2091 # 2021-10-15 34) 35 36FetchContent_GetProperties(libhunspell) 37if(NOT libhunspell_POPULATED) 38 FetchContent_Populate(libhunspell) 39 set(libhunspell_STATUS_FILE "${libhunspell_SOURCE_DIR}/config.status") 40 if(EXISTS "${libhunspell_STATUS_FILE}") 41 file(SHA256 "${libhunspell_STATUS_FILE}" _sapi_CONFIG_STATUS) 42 endif() 43 if(NOT _sapi_CONFIG_STATUS STREQUAL "${libhunspell_CONFIG_STATUS}") 44 message("-- Configuring libhunspell...") 45 execute_process( 46 COMMAND autoreconf -i 47 WORKING_DIRECTORY "${libhunspell_SOURCE_DIR}" 48 RESULT_VARIABLE _sapi_libhunspell_autoreconf_result 49 ) 50 if(NOT _sapi_libhunspell_autoreconf_result EQUAL "0") 51 message(FATAL_ERROR "Configuration for libhunspell failed: " 52 "${_sapi_libhunspell_autoreconf_result}") 53 endif() 54 execute_process( 55 COMMAND ./configure --disable-dependency-tracking 56 --quiet 57 WORKING_DIRECTORY "${libhunspell_SOURCE_DIR}" 58 RESULT_VARIABLE _sapi_libhunspell_config_result 59 ) 60 if(NOT _sapi_libhunspell_config_result EQUAL "0") 61 message(FATAL_ERROR "Configuration for libhunspell failed: " 62 "${_sapi_libhunspell_config_result}") 63 endif() 64 file(SHA256 "${libhunspell_SOURCE_DIR}/config.status" _sapi_CONFIG_STATUS) 65 set(libhunspell_CONFIG_STATUS "${_sapi_CONFIG_STATUS}" CACHE INTERNAL "") 66 endif() 67endif() 68 69add_library(hunspell STATIC 70 "${libhunspell_SOURCE_DIR}/src/hunspell/affentry.cxx" 71 "${libhunspell_SOURCE_DIR}/src/hunspell/affentry.hxx" 72 "${libhunspell_SOURCE_DIR}/src/hunspell/affixmgr.cxx" 73 "${libhunspell_SOURCE_DIR}/src/hunspell/affixmgr.hxx" 74 "${libhunspell_SOURCE_DIR}/src/hunspell/atypes.hxx" 75 "${libhunspell_SOURCE_DIR}/src/hunspell/baseaffix.hxx" 76 "${libhunspell_SOURCE_DIR}/src/hunspell/csutil.cxx" 77 "${libhunspell_SOURCE_DIR}/src/hunspell/csutil.hxx" 78 "${libhunspell_SOURCE_DIR}/src/hunspell/filemgr.cxx" 79 "${libhunspell_SOURCE_DIR}/src/hunspell/filemgr.hxx" 80 "${libhunspell_SOURCE_DIR}/src/hunspell/hashmgr.cxx" 81 "${libhunspell_SOURCE_DIR}/src/hunspell/hashmgr.hxx" 82 "${libhunspell_SOURCE_DIR}/src/hunspell/htypes.hxx" 83 "${libhunspell_SOURCE_DIR}/src/hunspell/hunspell.cxx" 84 "${libhunspell_SOURCE_DIR}/src/hunspell/hunspell.h" 85 "${libhunspell_SOURCE_DIR}/src/hunspell/hunspell.hxx" 86 "${libhunspell_SOURCE_DIR}/src/hunspell/hunzip.cxx" 87 "${libhunspell_SOURCE_DIR}/src/hunspell/hunzip.hxx" 88 "${libhunspell_SOURCE_DIR}/src/hunspell/langnum.hxx" 89 "${libhunspell_SOURCE_DIR}/src/hunspell/phonet.cxx" 90 "${libhunspell_SOURCE_DIR}/src/hunspell/phonet.hxx" 91 "${libhunspell_SOURCE_DIR}/src/hunspell/replist.cxx" 92 "${libhunspell_SOURCE_DIR}/src/hunspell/replist.hxx" 93 "${libhunspell_SOURCE_DIR}/src/hunspell/suggestmgr.cxx" 94 "${libhunspell_SOURCE_DIR}/src/hunspell/suggestmgr.hxx" 95 "${libhunspell_SOURCE_DIR}/src/hunspell/utf_info.hxx" 96 "${libhunspell_SOURCE_DIR}/src/hunspell/w_char.hxx" 97) 98 99target_include_directories(hunspell PUBLIC 100 "${libhunspell_SOURCE_DIR}/src/hunspell" 101) 102 103set(libhunspell_INCLUDE_DIR "${libhunspell_SOURCE_DIR}/src/hunspell") 104 105add_sapi_library(sapi_hunspell 106 FUNCTIONS Hunspell_create 107 Hunspell_create_key 108 Hunspell_destroy 109 110 Hunspell_spell 111 Hunspell_get_dic_encoding 112 113 Hunspell_suggest 114 Hunspell_analyze 115 116 Hunspell_add 117 Hunspell_remove 118 119 Hunspell_free_list 120 121 INPUTS "${libhunspell_INCLUDE_DIR}/hunspell.h" 122 123 LIBRARY hunspell 124 LIBRARY_NAME Hunspell 125 NAMESPACE "" 126) 127add_library(sapi_contrib::hunspell ALIAS sapi_hunspell) 128target_include_directories(sapi_hunspell INTERFACE 129 "${PROJECT_BINARY_DIR}" 130) 131 132if(SAPI_BUILD_EXAMPLES) 133 add_subdirectory(example) 134endif() 135 136if(BUILD_TESTING AND SAPI_BUILD_TESTING) 137 add_subdirectory(test) 138endif() 139