Debian Codegraph @

cmake/FindGroongaRapidJSON.cmake

raw
1 # Copyright(C) 2023 Sutou Kouhei <[email protected]>
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 if(GroongaRapidJSON_FOUND)
18 return()
19 endif()
20
21 set(find_package_args "")
22 set(pkg_check_modules_version "")
23 if(GroongaRapidJSON_FIND_VERSION)
24 list(APPEND find_package_args ${GroongaRapidJSON_FIND_VERSION})
25 set(pkg_check_modules_version ">=${GroongaRapidJSON_FIND_VERSION}")
26 endif()
27 if(GroongaRapidJSON_FIND_QUIETLY)
28 list(APPEND find_package_args QUIET)
29 endif()
30 find_package(RapidJSON ${find_package_args})
31 set(GroongaRapidJSON_FOUND ${RapidJSON_FOUND})
32 if(GroongaRapidJSON_FOUND)
33 add_library(Groonga::RapidJSON INTERFACE IMPORTED)
34 target_include_directories(Groonga::RapidJSON
35 INTERFACE "${RAPIDJSON_INCLUDE_DIRS}")
36 endif()
37
38 if(NOT GroongaRapidJSON_FOUND)
39 find_package(PkgConfig)
40 if(PkgConfig_FOUND)
41 if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.18")
42 pkg_check_modules(GroongaRapidJSON_pkg_RapidJSON IMPORTED_TARGET
43 "RapidJSON${pkg_check_modules_version}")
44 else()
45 pkg_check_modules(GroongaRapidJSON_pkg_RapidJSON IMPORTED_TARGET GLOBAL
46 "RapidJSON${pkg_check_modules_version}")
47 endif()
48 set(GroongaRapidJSON_FOUND ${GroongaRapidJSON_pkg_RapidJSON_FOUND})
49 if(GroongaRapidJSON_FOUND)
50 add_library(Groonga::RapidJSON ALIAS
51 PkgConfig::GroongaRapidJSON_pkg_RapidJSON)
52 endif()
53 endif()
54 endif()
55
56 if(NOT GroongaRapidJSON_FOUND)
57 find_file(GroongaRapidJSON_rapidjson_h rapidjson/rapidjson.h)
58 if(GroongaRapidJSON_rapidjson_h)
59 add_library(Groonga::RapidJSON INTERFACE IMPORTED)
60 get_filename_component(GroongaRapidJSON_INCLUDE_DIR
61 "${GroongaRapidJSON_rapidjson_h}" DIRECTORY)
62 get_filename_component(GroongaRapidJSON_INCLUDE_DIR
63 "${GroongaRapidJSON_INCLUDE_DIR}" DIRECTORY)
64 target_include_directories(Groonga::RapidJSON
65 INTERFACE "${GroongaRapidJSON_INCLUDE_DIR}")
66 set(GroongaRapidJSON_FOUND TRUE)
67 endif()
68 endif()
69
70 include(FindPackageHandleStandardArgs)
71 find_package_handle_standard_args(GroongaRapidJSON
72 REQUIRED_VARS GroongaRapidJSON_FOUND)