-
Notifications
You must be signed in to change notification settings - Fork 51
/
build-gtest.sh
executable file
·72 lines (68 loc) · 2.13 KB
/
build-gtest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
ARCH="x86_64"
if [ "$1" == "ios" ]; then
IOS_BUILD="YES"
# Skip building tests on iOS as there is no way to run them
BUILD_TESTS="OFF"
else
IOS_BUILD="NO"
if [ "$1" == "arm64" ]; then
ARCH="arm64"
BUILD_TESTS="OFF"
else
BUILD_TESTS="ON"
fi
fi
cd `dirname $0`
GTEST_PATH=third_party/googletest
if [ ! "$(ls -A $GTEST_PATH/CMakeLists.txt)" ]; then
echo Clone googletest from google/googletest:master ...
rm -rf ${GTEST_PATH} #delete just if empty directory exists
git clone --depth 1 --branch release-1.12.1 https://github.com/google/googletest $GTEST_PATH
else
echo "Using existing googletest from thirdparty/"
fi
echo "Add ios and arm64 build steps for googletest"
cat > $GTEST_PATH/CMakeLists_temp.txt << EOF
# If building for iOS, set all the iOS options
if(BUILD_IOS)
set(TARGET_ARCH "APPLE")
set(IOS True)
set(APPLE True)
set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -miphoneos-version-min=10.0")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -miphoneos-version-min=10.0 -std=c++11")
set(IOS_PLATFORM "iphonesimulator")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
execute_process(COMMAND xcodebuild -version -sdk \${IOS_PLATFORM} Path
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
message("-- CMAKE_OSX_SYSROOT \${CMAKE_OSX_SYSROOT}")
elseif(\${ARCH} STREQUAL "arm64")
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -arch arm64")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -arch arm64")
set(CMAKE_SYSTEM_PROCESSOR arm64)
set(APPLE True)
endif()
EOF
sed -i -e "/^cmake_minimum_required/r $GTEST_PATH/CMakeLists_temp.txt" $GTEST_PATH/CMakeLists.txt
rm $GTEST_PATH/CMakeLists_temp.txt
pushd $GTEST_PATH
set -evx
env | sort
rm -rf build
mkdir -p build || true
cd build
cmake -Dgtest_build_samples=OFF \
-Dgmock_build_samples=OFF \
-Dgtest_build_tests=OFF \
-Dgmock_build_tests=OFF \
-DCMAKE_CXX_FLAGS="-fPIC $CXX_FLAGS" \
-DBUILD_IOS=$IOS_BUILD \
-DARCH=$ARCH \
..
make
popd
# CTEST_OUTPUT_ON_FAILURE=1 make test
# make install