Skip to content

Commit 7388c5a

Browse files
committed
Add script to find RapidJSON.
1 parent 9b4e4cb commit 7388c5a

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

FindRapidJSON.cmake

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
#
3+
# CMake Find RapidJSON by Parra Studios
4+
# CMake script to find RapidJSON library.
5+
#
6+
# Copyright (C) 2016 - 2019 Vicente Eduardo Ferrer Garcia <[email protected]>
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
# The following variables are set:
22+
#
23+
# RAPIDJSON_CXX_FLAGS - Custom RapidJSON compilation flags.
24+
# RAPIDJSON_INCLUDE_DIRS - A list of directories where the RapidJSON headers are located.
25+
26+
foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
27+
if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
28+
message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry")
29+
elseif(DEFINED ENV{${opt}} AND NOT ${opt})
30+
set(${opt} "$ENV{${opt}}")
31+
endif()
32+
endforeach()
33+
34+
find_path(
35+
RAPIDJSON_INCLUDE_DIRS
36+
NAMES rapidjson/rapidjson.h
37+
PATHS ${RAPIDJSON_INCLUDEDIR}
38+
DOC "Include directory for the RapidJSON library"
39+
)
40+
41+
mark_as_advanced(RAPIDJSON_INCLUDE_DIRS)
42+
43+
if(RAPIDJSON_INCLUDE_DIRS)
44+
set(RAPIDJSON_FOUND TRUE)
45+
endif()
46+
47+
mark_as_advanced(RAPIDJSON_FOUND)
48+
49+
if(RAPIDJSON_USE_SSE42)
50+
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE42")
51+
if(MSVC)
52+
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE4.2")
53+
else()
54+
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse4.2")
55+
endif()
56+
else()
57+
if(RAPIDJSON_USE_SSE2)
58+
set(RAPIDJSON_CXX_FLAGS "-DRAPIDJSON_SSE2")
59+
if(MSVC)
60+
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} /arch:SSE2")
61+
else()
62+
set(RAPIDJSON_CXX_FLAGS "${RAPIDJSON_CXX_FLAGS} -msse2")
63+
endif()
64+
endif()
65+
endif()
66+
67+
mark_as_advanced(RAPIDJSON_CXX_FLAGS)
68+
69+
if(RAPIDJSON_FOUND)
70+
if(NOT RapidJSON_FIND_QUIETLY)
71+
message(STATUS "Found RapidJSON header files in ${RAPIDJSON_INCLUDE_DIRS}")
72+
if(DEFINED RAPIDJSON_CXX_FLAGS)
73+
message(STATUS "Found RapidJSON C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
74+
endif()
75+
endif()
76+
elseif(RapidJSON_FIND_REQUIRED)
77+
message(FATAL_ERROR "Could not find RapidJSON")
78+
endif()

InstallRapidJSON.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#
32
# CMake Install RapidJSON by Parra Studios
43
# CMake script to install RapidJSON library.

0 commit comments

Comments
 (0)