Skip to content

Commit 814f963

Browse files
committed
Add InstallGTest and improve FindRapidJSON.
1 parent 7388c5a commit 814f963

File tree

2 files changed

+102
-5
lines changed

2 files changed

+102
-5
lines changed

FindRapidJSON.cmake

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#
32
# CMake Find RapidJSON by Parra Studios
43
# CMake script to find RapidJSON library.
@@ -23,18 +22,29 @@
2322
# RAPIDJSON_CXX_FLAGS - Custom RapidJSON compilation flags.
2423
# RAPIDJSON_INCLUDE_DIRS - A list of directories where the RapidJSON headers are located.
2524

26-
foreach(opt RAPIDJSON_INCLUDEDIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
25+
# Prevent vervosity if already included
26+
if(RAPIDJSON_FOUND)
27+
set(RAPIDJSON_FIND_QUIETLY TRUE)
28+
endif()
29+
30+
foreach(opt RAPIDJSON_INCLUDE_DIR RAPIDJSON_USE_SSE2 RAPIDJSON_USE_SSE42)
2731
if(${opt} AND DEFINED ENV{${opt}} AND NOT ${opt} STREQUAL "$ENV{${opt}}")
2832
message(WARNING "Conflicting ${opt} values: ignoring environment variable and using CMake cache entry")
2933
elseif(DEFINED ENV{${opt}} AND NOT ${opt})
3034
set(${opt} "$ENV{${opt}}")
3135
endif()
3236
endforeach()
3337

38+
# Default RapidJSON include paths
39+
set(RAPIDJSON_INCLUDE_DIR
40+
"${RAPIDJSON_INCLUDE_DIR}"
41+
"/usr/local/include/"
42+
)
43+
3444
find_path(
3545
RAPIDJSON_INCLUDE_DIRS
3646
NAMES rapidjson/rapidjson.h
37-
PATHS ${RAPIDJSON_INCLUDEDIR}
47+
PATHS ${RAPIDJSON_INCLUDE_DIR}
3848
DOC "Include directory for the RapidJSON library"
3949
)
4050

@@ -67,12 +77,12 @@ endif()
6777
mark_as_advanced(RAPIDJSON_CXX_FLAGS)
6878

6979
if(RAPIDJSON_FOUND)
70-
if(NOT RapidJSON_FIND_QUIETLY)
80+
if(NOT RAPIDJSON_FIND_QUIETLY)
7181
message(STATUS "Found RapidJSON header files in ${RAPIDJSON_INCLUDE_DIRS}")
7282
if(DEFINED RAPIDJSON_CXX_FLAGS)
7383
message(STATUS "Found RapidJSON C++ extra compilation flags: ${RAPIDJSON_CXX_FLAGS}")
7484
endif()
7585
endif()
76-
elseif(RapidJSON_FIND_REQUIRED)
86+
elseif(RAPIDJSON_FIND_REQUIRED)
7787
message(FATAL_ERROR "Could not find RapidJSON")
7888
endif()

InstallGTest.cmake

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# CMake Install Google Test by Parra Studios
3+
# CMake script to install Google Test library.
4+
#
5+
# Copyright (C) 2016 - 2019 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
# The following variables are set:
21+
#
22+
# GTEST_INCLUDE_DIRS - A list of directories where the Google Test headers are located.
23+
# GTEST_LIBRARIES - A list of directories where the Google Test libraries are located.
24+
25+
if(NOT GTEST_FOUND OR USE_BUNDLED_GTEST)
26+
if(NOT GTEST_VERSION OR USE_BUNDLED_GTEST)
27+
set(GTEST_VERSION 1.8.1)
28+
endif()
29+
30+
find_package(Threads REQUIRED)
31+
32+
if(MINGW)
33+
set(GTEST_DISABLE_PTHREADS ON)
34+
else()
35+
set(GTEST_DISABLE_PTHREADS OFF)
36+
endif()
37+
38+
# Import Google Test Framework
39+
ExternalProject_Add(GoogleTest
40+
GIT_REPOSITORY https://github.com/google/googletest.git
41+
GIT_TAG release-${GTEST_VERSION}
42+
CMAKE_ARGS -Dgmock_build_tests=OFF
43+
-Dgtest_build_samples=OFF
44+
-Dgtest_build_tests=OFF
45+
-Dgtest_disable_pthreads=${GTEST_DISABLE_PTHREADS}
46+
-Dgtest_force_shared_crt=ON
47+
-Dgtest_hide_internal_symbols=OFF
48+
-DINSTALL_GTEST=OFF
49+
-DBUILD_GMOCK=ON
50+
PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
51+
UPDATE_COMMAND ""
52+
INSTALL_COMMAND ""
53+
TEST_COMMAND ""
54+
)
55+
56+
# Google Test include and binary directories
57+
ExternalProject_Get_Property(GoogleTest source_dir binary_dir)
58+
59+
set(GTEST_INCLUDE_DIR "${source_dir}/googletest/include")
60+
set(GMOCK_INCLUDE_DIR "${source_dir}/googlemock/include")
61+
set(GTEST_LIBS_DIR "${binary_dir}/googlemock/gtest")
62+
set(GMOCK_LIBS_DIR "${binary_dir}/googlemock")
63+
64+
if(MSVC)
65+
set(GTEST_LIB_SUFFIX "lib")
66+
else()
67+
set(GTEST_LIB_SUFFIX "a")
68+
endif()
69+
70+
# Define Paths
71+
set(GTEST_INCLUDE_DIRS
72+
"${GTEST_INCLUDE_DIR}"
73+
"${GMOCK_INCLUDE_DIR}"
74+
)
75+
76+
set(GTEST_LIBRARIES
77+
"${GTEST_LIBS_DIR}/libgtest.${GTEST_LIB_SUFFIX}"
78+
"${GMOCK_LIBS_DIR}/libgmock.${GTEST_LIB_SUFFIX}"
79+
"${CMAKE_THREAD_LIBS_INIT}"
80+
)
81+
82+
set(GTEST_FOUND TRUE)
83+
84+
mark_as_advanced(GTEST_INCLUDE_DIRS GTEST_LIBRARIES)
85+
86+
message(STATUS "Install Google Test v${GTEST_VERSION}")
87+
endif ()

0 commit comments

Comments
 (0)