1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
18 set(find_package_args)
19 if(RapidJSONAlt_FIND_VERSION)
20 list(APPEND find_package_args ${RapidJSONAlt_FIND_VERSION})
22 if(RapidJSONAlt_FIND_QUIETLY)
23 list(APPEND find_package_args QUIET)
25 find_package(RapidJSON ${find_package_args})
27 set(RapidJSONAlt_FOUND TRUE)
28 set(RAPIDJSON_INCLUDE_DIR ${RAPIDJSON_INCLUDE_DIRS})
33 find_path(RAPIDJSON_INCLUDE_DIR
34 NAMES rapidjson/rapidjson.h
35 PATHS ${RapidJSON_ROOT}
37 PATH_SUFFIXES "include")
39 find_path(RAPIDJSON_INCLUDE_DIR
40 NAMES rapidjson/rapidjson.h
41 PATH_SUFFIXES "include")
44 if(RAPIDJSON_INCLUDE_DIR)
45 file(READ "${RAPIDJSON_INCLUDE_DIR}/rapidjson/rapidjson.h" RAPIDJSON_H_CONTENT)
46 string(REGEX MATCH "#define RAPIDJSON_MAJOR_VERSION ([0-9]+)"
47 RAPIDJSON_MAJOR_VERSION_DEFINITION "${RAPIDJSON_H_CONTENT}")
48 string(REGEX REPLACE "^.+ ([0-9]+)$" "\\1" RAPIDJSON_MAJOR_VERSION
49 "${RAPIDJSON_MAJOR_VERSION_DEFINITION}")
50 string(REGEX MATCH "#define RAPIDJSON_MINOR_VERSION ([0-9]+)"
51 RAPIDJSON_MINOR_VERSION_DEFINITION "${RAPIDJSON_H_CONTENT}")
52 string(REGEX REPLACE "^.+ ([0-9]+)$" "\\1" RAPIDJSON_MINOR_VERSION
53 "${RAPIDJSON_MINOR_VERSION_DEFINITION}")
54 string(REGEX MATCH "#define RAPIDJSON_PATCH_VERSION ([0-9]+)"
55 RAPIDJSON_PATCH_VERSION_DEFINITION "${RAPIDJSON_H_CONTENT}")
56 string(REGEX REPLACE "^.+ ([0-9]+)$" "\\1" RAPIDJSON_PATCH_VERSION
57 "${RAPIDJSON_PATCH_VERSION_DEFINITION}")
58 if("${RAPIDJSON_MAJOR_VERSION}" STREQUAL ""
59 OR "${RAPIDJSON_MINOR_VERSION}" STREQUAL ""
60 OR "${RAPIDJSON_PATCH_VERSION}" STREQUAL "")
61 set(RAPIDJSON_VERSION "0.0.0")
64 "${RAPIDJSON_MAJOR_VERSION}.${RAPIDJSON_MINOR_VERSION}.${RAPIDJSON_PATCH_VERSION}"
69 find_package_handle_standard_args(
71 REQUIRED_VARS RAPIDJSON_INCLUDE_DIR
72 VERSION_VAR RAPIDJSON_VERSION)