|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Cmake file for a single C++ integration test build. |
| 16 | + |
| 17 | +cmake_minimum_required(VERSION 2.8) |
| 18 | + |
| 19 | +# User settings for Firebase integration tests. |
| 20 | +# Path to Firebase SDK. |
| 21 | +# Try to read the path to the Firebase C++ SDK from an environment variable. |
| 22 | +if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 23 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}") |
| 24 | +else() |
| 25 | + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../cpp_sdk_version.json") |
| 26 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "${CMAKE_CURRENT_LIST_DIR}/../..") |
| 27 | + else() |
| 28 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk") |
| 29 | + endif() |
| 30 | +endif() |
| 31 | +if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 32 | + set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR}) |
| 33 | +endif() |
| 34 | +if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR}) |
| 35 | + message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information") |
| 36 | +endif() |
| 37 | + |
| 38 | +# Copy all prerequisite files for integration tests to run. |
| 39 | +if(NOT ANDROID) |
| 40 | + if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py) |
| 41 | + # If this is running from inside the SDK directory, run the setup script. |
| 42 | + execute_process(COMMAND "python" "${CMAKE_CURRENT_LIST_DIR}/../../setup_integration_tests.py" "${CMAKE_CURRENT_LIST_DIR}") |
| 43 | + endif() |
| 44 | +endif() |
| 45 | + |
| 46 | +# Windows runtime mode, either MD or MT depending on whether you are using |
| 47 | +# /MD or /MT. For more information see: |
| 48 | +# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 49 | +set(MSVC_RUNTIME_MODE MD) |
| 50 | + |
| 51 | +project(firebase_testapp) |
| 52 | + |
| 53 | +# Integration test source files. |
| 54 | +set(FIREBASE_APP_FRAMEWORK_SRCS |
| 55 | + src/app_framework.cc |
| 56 | + src/app_framework.h |
| 57 | +) |
| 58 | + |
| 59 | +set(FIREBASE_TEST_FRAMEWORK_SRCS |
| 60 | + src/firebase_test_framework.h |
| 61 | + src/firebase_test_framework.cc |
| 62 | +) |
| 63 | + |
| 64 | +set(FIREBASE_INTEGRATION_TEST_SRCS |
| 65 | + src/integration_test.cc |
| 66 | +) |
| 67 | + |
| 68 | +# The include directory for the testapp. |
| 69 | +include_directories(src) |
| 70 | + |
| 71 | +# Integration test uses some features that require C++ 11, such as lambdas. |
| 72 | +set (CMAKE_CXX_STANDARD 11) |
| 73 | + |
| 74 | +# Download and unpack googletest (and googlemock) at configure time |
| 75 | +set(GOOGLETEST_ROOT ${CMAKE_CURRENT_LIST_DIR}/external/googletest) |
| 76 | +# Note: Once googletest is downloaded once, it won't be updated or |
| 77 | +# downloaded again unless you delete the "external/googletest" |
| 78 | +# directory. |
| 79 | +if (NOT EXISTS ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc) |
| 80 | + configure_file(googletest.cmake |
| 81 | + ${CMAKE_CURRENT_LIST_DIR}/external/googletest/CMakeLists.txt COPYONLY) |
| 82 | + execute_process(COMMAND ${CMAKE_COMMAND} . |
| 83 | + RESULT_VARIABLE result |
| 84 | + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest ) |
| 85 | + if(result) |
| 86 | + message(FATAL_ERROR "CMake step for googletest failed: ${result}") |
| 87 | + endif() |
| 88 | + execute_process(COMMAND ${CMAKE_COMMAND} --build . |
| 89 | + RESULT_VARIABLE result |
| 90 | + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external/googletest ) |
| 91 | + if(result) |
| 92 | + message(FATAL_ERROR "Build step for googletest failed: ${result}") |
| 93 | + endif() |
| 94 | +endif() |
| 95 | + |
| 96 | +if(ANDROID) |
| 97 | + # Build an Android application. |
| 98 | + |
| 99 | + # Source files used for the Android build. |
| 100 | + set(FIREBASE_APP_FRAMEWORK_ANDROID_SRCS |
| 101 | + src/android/android_app_framework.cc |
| 102 | + ) |
| 103 | + |
| 104 | + # Source files used for the Android build. |
| 105 | + set(FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS |
| 106 | + src/android/android_firebase_test_framework.cc |
| 107 | + ) |
| 108 | + |
| 109 | +# Build native_app_glue as a static lib |
| 110 | + add_library(native_app_glue STATIC |
| 111 | + ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) |
| 112 | + |
| 113 | + # Export ANativeActivity_onCreate(), |
| 114 | + # Refer to: https://github.com/android-ndk/ndk/issues/381. |
| 115 | + set(CMAKE_SHARED_LINKER_FLAGS |
| 116 | + "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") |
| 117 | + |
| 118 | + add_library(gtest STATIC |
| 119 | + ${GOOGLETEST_ROOT}/src/googletest/src/gtest-all.cc) |
| 120 | + target_include_directories(gtest |
| 121 | + PRIVATE ${GOOGLETEST_ROOT}/src/googletest |
| 122 | + PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include) |
| 123 | + add_library(gmock STATIC |
| 124 | + ${GOOGLETEST_ROOT}/src/googlemock/src/gmock-all.cc) |
| 125 | + target_include_directories(gmock |
| 126 | + PRIVATE ${GOOGLETEST_ROOT}/src/googletest |
| 127 | + PRIVATE ${GOOGLETEST_ROOT}/src/googlemock |
| 128 | + PUBLIC ${GOOGLETEST_ROOT}/src/googletest/include |
| 129 | + PUBLIC ${GOOGLETEST_ROOT}/src/googlemock/include) |
| 130 | + |
| 131 | + # Define the target as a shared library, as that is what gradle expects. |
| 132 | + set(integration_test_target_name "android_integration_test_main") |
| 133 | + add_library(${integration_test_target_name} SHARED |
| 134 | + ${FIREBASE_APP_FRAMEWORK_SRCS} |
| 135 | + ${FIREBASE_APP_FRAMEWORK_ANDROID_SRCS} |
| 136 | + ${FIREBASE_INTEGRATION_TEST_SRCS} |
| 137 | + ${FIREBASE_TEST_FRAMEWORK_SRCS} |
| 138 | + ${FIREBASE_TEST_FRAMEWORK_ANDROID_SRCS} |
| 139 | + ) |
| 140 | + |
| 141 | + target_include_directories(${integration_test_target_name} PRIVATE |
| 142 | + ${ANDROID_NDK}/sources/android/native_app_glue) |
| 143 | + |
| 144 | + set(ADDITIONAL_LIBS log android atomic native_app_glue) |
| 145 | +else() |
| 146 | + # Build a desktop application. |
| 147 | + add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) |
| 148 | + |
| 149 | + # Prevent overriding the parent project's compiler/linker |
| 150 | + # settings on Windows |
| 151 | + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 152 | + |
| 153 | + # Add googletest directly to our build. This defines |
| 154 | + # the gtest and gtest_main targets. |
| 155 | + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/external/googletest/src |
| 156 | + ${CMAKE_CURRENT_LIST_DIR}/external/googletest/build |
| 157 | + EXCLUDE_FROM_ALL) |
| 158 | + |
| 159 | + # The gtest/gtest_main targets carry header search path |
| 160 | + # dependencies automatically when using CMake 2.8.11 or |
| 161 | + # later. Otherwise we have to add them here ourselves. |
| 162 | + if (CMAKE_VERSION VERSION_LESS 2.8.11) |
| 163 | + include_directories("${gtest_SOURCE_DIR}/include") |
| 164 | + include_directories("${gmock_SOURCE_DIR}/include") |
| 165 | + endif() |
| 166 | + |
| 167 | + # Windows runtime mode, either MD or MT depending on whether you are using |
| 168 | + # /MD or /MT. For more information see: |
| 169 | + # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 170 | + set(MSVC_RUNTIME_MODE MD) |
| 171 | + |
| 172 | + # Platform abstraction layer for the desktop integration test. |
| 173 | + set(FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS |
| 174 | + src/desktop/desktop_app_framework.cc |
| 175 | + ) |
| 176 | + |
| 177 | + set(integration_test_target_name "integration_test") |
| 178 | + add_executable(${integration_test_target_name} |
| 179 | + ${FIREBASE_APP_FRAMEWORK_SRCS} |
| 180 | + ${FIREBASE_APP_FRAMEWORK_DESKTOP_SRCS} |
| 181 | + ${FIREBASE_TEST_FRAMEWORK_SRCS} |
| 182 | + ${FIREBASE_INTEGRATION_TEST_SRCS} |
| 183 | + ) |
| 184 | + |
| 185 | + if(APPLE) |
| 186 | + set(ADDITIONAL_LIBS |
| 187 | + gssapi_krb5 |
| 188 | + pthread |
| 189 | + "-framework CoreFoundation" |
| 190 | + "-framework Foundation" |
| 191 | + "-framework GSS" |
| 192 | + "-framework Security" |
| 193 | + ) |
| 194 | + elseif(MSVC) |
| 195 | + set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32) |
| 196 | + else() |
| 197 | + set(ADDITIONAL_LIBS pthread) |
| 198 | + endif() |
| 199 | + |
| 200 | + # If a config file is present, copy it into the binary location so that it's |
| 201 | + # possible to create the default Firebase app. |
| 202 | + set(FOUND_JSON_FILE FALSE) |
| 203 | + foreach(config "google-services-desktop.json" "google-services.json") |
| 204 | + if (EXISTS ${config}) |
| 205 | + add_custom_command( |
| 206 | + TARGET ${integration_test_target_name} POST_BUILD |
| 207 | + COMMAND ${CMAKE_COMMAND} -E copy |
| 208 | + ${config} $<TARGET_FILE_DIR:${integration_test_target_name}>) |
| 209 | + set(FOUND_JSON_FILE TRUE) |
| 210 | + break() |
| 211 | + endif() |
| 212 | + endforeach() |
| 213 | + if(NOT FOUND_JSON_FILE) |
| 214 | + message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.") |
| 215 | + endif() |
| 216 | +endif() |
| 217 | + |
| 218 | +# Add the Firebase libraries to the target using the function from the SDK. |
| 219 | +add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) |
| 220 | +# Note that firebase_app needs to be last in the list. |
| 221 | +set(firebase_libs firebase_installations firebase_app) |
| 222 | +set(gtest_libs gtest gmock) |
| 223 | +target_link_libraries(${integration_test_target_name} ${firebase_libs} |
| 224 | + ${gtest_libs} ${ADDITIONAL_LIBS}) |
0 commit comments