|
| 1 | +cmake_minimum_required(VERSION 2.8) |
| 2 | + |
| 3 | +# User settings for Firebase samples. |
| 4 | +# Path to Firebase SDK. |
| 5 | +# Try to read the path to the Firebase C++ SDK from an environment variable. |
| 6 | +if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 7 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}") |
| 8 | +else() |
| 9 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk") |
| 10 | +endif() |
| 11 | +if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 12 | + set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR}) |
| 13 | +endif() |
| 14 | +if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR}) |
| 15 | + message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information") |
| 16 | +endif() |
| 17 | + |
| 18 | +# Windows runtime mode, either MD or MT depending on whether you are using |
| 19 | +# /MD or /MT. For more information see: |
| 20 | +# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 21 | +set(MSVC_RUNTIME_MODE MD) |
| 22 | + |
| 23 | +project(firebase_testapp) |
| 24 | + |
| 25 | +# Sample source files. |
| 26 | +set(FIREBASE_SAMPLE_COMMON_SRCS |
| 27 | + src/main.h |
| 28 | + src/common_main.cc |
| 29 | +) |
| 30 | + |
| 31 | +# The include directory for the testapp. |
| 32 | +include_directories(src) |
| 33 | + |
| 34 | +# Sample uses some features that require C++ 11, such as lambdas. |
| 35 | +set (CMAKE_CXX_STANDARD 11) |
| 36 | + |
| 37 | +if(ANDROID) |
| 38 | + # Build an Android application. |
| 39 | + |
| 40 | + # Source files used for the Android build. |
| 41 | + set(FIREBASE_SAMPLE_ANDROID_SRCS |
| 42 | + src/android/android_main.cc |
| 43 | + ) |
| 44 | + |
| 45 | + # Build native_app_glue as a static lib |
| 46 | + add_library(native_app_glue STATIC |
| 47 | + ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) |
| 48 | + |
| 49 | + # Export ANativeActivity_onCreate(), |
| 50 | + # Refer to: https://github.com/android-ndk/ndk/issues/381. |
| 51 | + # This also does a workaround that prevents numerous errors that occur when |
| 52 | + # building using Android Studio. The errors look like: |
| 53 | + # libfirebase_auth.a(auth.o): relocation R_386_GOTOFF against preemptible |
| 54 | + # symbol <long_mangled_name> cannot be used when making a shared object. |
| 55 | + # Taken from: |
| 56 | + # https://github.com/opencv/opencv/issues/10229#issuecomment-359202825 |
| 57 | + set(CMAKE_SHARED_LINKER_FLAGS |
| 58 | + "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate \ |
| 59 | + -Wl,--exclude-libs,libfirebase_firestore.a \ |
| 60 | + -Wl,--exclude-libs,libfirebase_auth.a \ |
| 61 | + -Wl,--exclude-libs,libfirebase_app.a" |
| 62 | + ) |
| 63 | + |
| 64 | + # Define the target as a shared library, as that is what gradle expects. |
| 65 | + set(target_name "android_main") |
| 66 | + add_library(${target_name} SHARED |
| 67 | + ${FIREBASE_SAMPLE_ANDROID_SRCS} |
| 68 | + ${FIREBASE_SAMPLE_COMMON_SRCS} |
| 69 | + ) |
| 70 | + |
| 71 | + target_link_libraries(${target_name} |
| 72 | + log android atomic native_app_glue |
| 73 | + ) |
| 74 | + |
| 75 | + target_include_directories(${target_name} PRIVATE |
| 76 | + ${ANDROID_NDK}/sources/android/native_app_glue) |
| 77 | + |
| 78 | + set(ADDITIONAL_LIBS) |
| 79 | +else() |
| 80 | + # Build a desktop application. |
| 81 | + |
| 82 | + # Windows runtime mode, either MD or MT depending on whether you are using |
| 83 | + # /MD or /MT. For more information see: |
| 84 | + # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 85 | + set(MSVC_RUNTIME_MODE MD) |
| 86 | + |
| 87 | + # Platform abstraction layer for the desktop sample. |
| 88 | + set(FIREBASE_SAMPLE_DESKTOP_SRCS |
| 89 | + src/desktop/desktop_main.cc |
| 90 | + ) |
| 91 | + |
| 92 | + set(target_name "desktop_testapp") |
| 93 | + add_executable(${target_name} |
| 94 | + ${FIREBASE_SAMPLE_DESKTOP_SRCS} |
| 95 | + ${FIREBASE_SAMPLE_COMMON_SRCS} |
| 96 | + ) |
| 97 | + |
| 98 | + if(APPLE) |
| 99 | + set(ADDITIONAL_LIBS |
| 100 | + gssapi_krb5 |
| 101 | + pthread |
| 102 | + "-framework CoreFoundation" |
| 103 | + "-framework Foundation" |
| 104 | + "-framework GSS" |
| 105 | + "-framework Security" |
| 106 | + "-framework SystemConfiguration" |
| 107 | + ) |
| 108 | + elseif(MSVC) |
| 109 | + set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv) |
| 110 | + else() |
| 111 | + set(ADDITIONAL_LIBS pthread) |
| 112 | + endif() |
| 113 | + |
| 114 | + # If a config file is present, copy it into the binary location so that it's |
| 115 | + # possible to create the default Firebase app. |
| 116 | + set(FOUND_JSON_FILE FALSE) |
| 117 | + foreach(config "google-services-desktop.json" "google-services.json") |
| 118 | + if (EXISTS ${config}) |
| 119 | + add_custom_command( |
| 120 | + TARGET ${target_name} POST_BUILD |
| 121 | + COMMAND ${CMAKE_COMMAND} -E copy |
| 122 | + ${config} $<TARGET_FILE_DIR:${target_name}>) |
| 123 | + set(FOUND_JSON_FILE TRUE) |
| 124 | + break() |
| 125 | + endif() |
| 126 | + endforeach() |
| 127 | + if(NOT FOUND_JSON_FILE) |
| 128 | + message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.") |
| 129 | + endif() |
| 130 | +endif() |
| 131 | + |
| 132 | +# Add the Firebase libraries to the target using the function from the SDK. |
| 133 | +add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) |
| 134 | +# Note that firebase_app needs to be last in the list. |
| 135 | +set(firebase_libs firebase_firestore firebase_auth firebase_app) |
| 136 | +target_link_libraries(${target_name} "${firebase_libs}" ${ADDITIONAL_LIBS}) |
0 commit comments