|
| 1 | +#/**************************************************************************** |
| 2 | + # Copyright (c) 2013-2014 cocos2d-x.org |
| 3 | + # Copyright (c) 2015-2017 Chukong Technologies Inc. |
| 4 | + # |
| 5 | + # http://www.cocos2d-x.org |
| 6 | + # |
| 7 | + # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + # of this software and associated documentation files (the "Software"), to deal |
| 9 | + # in the Software without restriction, including without limitation the rights |
| 10 | + # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + # copies of the Software, and to permit persons to whom the Software is |
| 12 | + # furnished to do so, subject to the following conditions: |
| 13 | + |
| 14 | + # The above copyright notice and this permission notice shall be included in |
| 15 | + # all copies or substantial portions of the Software. |
| 16 | + |
| 17 | + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + # THE SOFTWARE. |
| 24 | +# ****************************************************************************/ |
| 25 | + |
| 26 | +cmake_minimum_required(VERSION 3.6) |
| 27 | + |
| 28 | +set(APP_NAME tictactoe_demo) |
| 29 | + |
| 30 | +project(${APP_NAME}) |
| 31 | + |
| 32 | +# User settings for Firebase samples. |
| 33 | +# Path to Firebase SDK. |
| 34 | +# Try to read the path to the Firebase C++ SDK from an environment variable. |
| 35 | +if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 36 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}") |
| 37 | +else() |
| 38 | + set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk") |
| 39 | +endif() |
| 40 | +if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "") |
| 41 | + set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR}) |
| 42 | +endif() |
| 43 | +if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR}) |
| 44 | + message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information") |
| 45 | +endif() |
| 46 | + |
| 47 | +# Build a desktop application. |
| 48 | +# Windows runtime mode, either MD or MT depending on whether you are using |
| 49 | +# /MD or /MT. For more information see: |
| 50 | +# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 51 | +set(MSVC_RUNTIME_MODE MD) |
| 52 | + |
| 53 | +if(APPLE) |
| 54 | + set(ADDITIONAL_LIBS gssapi_krb5 pthread "-framework CoreFoundation" "-framework Foundation" "-framework GSS" "-framework Security") |
| 55 | +elseif(MSVC) |
| 56 | + set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv) |
| 57 | +else() |
| 58 | + set(ADDITIONAL_LIBS pthread) |
| 59 | +endif() |
| 60 | + |
| 61 | +# If a config file is present, copy it into the binary location so that it's |
| 62 | +# possible to create the default Firebase app. |
| 63 | +set(FOUND_JSON_FILE FALSE) |
| 64 | +foreach(config "google-services-desktop.json" "google-services.json") |
| 65 | + if (EXISTS ${config}) |
| 66 | + add_custom_command( |
| 67 | + TARGET ${APP_NAME} POST_BUILD |
| 68 | + COMMAND ${CMAKE_COMMAND} -E copy |
| 69 | + ${config} $<TARGET_FILE_DIR:${APP_NAME}>) |
| 70 | + set(FOUND_JSON_FILE TRUE) |
| 71 | + break() |
| 72 | + endif() |
| 73 | +endforeach() |
| 74 | +if(NOT FOUND_JSON_FILE) |
| 75 | + message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.") |
| 76 | +endif() |
| 77 | +#Target name change to cocos |
| 78 | +# Add the Firebase libraries to the target using the function from the SDK. |
| 79 | +add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL) |
| 80 | + |
| 81 | +# # Note that firebase_app needs to be last in the list. |
| 82 | +set(firebase_libs firebase_database firebase_auth firebase_app) |
| 83 | + |
| 84 | +if(XCODE) |
| 85 | + if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET) |
| 86 | + SET (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 8.0) |
| 87 | + endif() |
| 88 | +endif() |
| 89 | + |
| 90 | +if(NOT DEFINED BUILD_ENGINE_DONE) # to test install_test into root project |
| 91 | + set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d) |
| 92 | + set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/) |
| 93 | + |
| 94 | + include(CocosBuildSet) |
| 95 | + add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core) |
| 96 | +endif() |
| 97 | + |
| 98 | +# record sources, headers, resources... |
| 99 | +set(GAME_HEADER) |
| 100 | + |
| 101 | +set(GAME_RES_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/Resources") |
| 102 | + |
| 103 | +if(APPLE OR WINDOWS) |
| 104 | + cocos_mark_multi_resources(common_res_files RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER}) |
| 105 | +endif() |
| 106 | + |
| 107 | +# add cross-platforms source files and header files |
| 108 | +list(APPEND GAME_SOURCE Classes/AppDelegate.cpp Classes/TicTacToeScene.cpp) |
| 109 | +list(APPEND GAME_HEADER Classes/AppDelegate.h Classes/TicTacToeScene.h) |
| 110 | + |
| 111 | +if(ANDROID) |
| 112 | + # change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml |
| 113 | + set(APP_NAME MyGame) |
| 114 | + list(APPEND GAME_SOURCE proj.android/app/jni/hellocpp/main.cpp) |
| 115 | +elseif(LINUX) |
| 116 | + list(APPEND GAME_SOURCE proj.linux/main.cpp) |
| 117 | +elseif(WINDOWS) |
| 118 | + list(APPEND GAME_HEADER proj.win32/main.h proj.win32/resource.h) |
| 119 | + list(APPEND GAME_SOURCE proj.win32/main.cpp proj.win32/game.rc ${common_res_files}) |
| 120 | +elseif(APPLE) |
| 121 | + if(IOS) |
| 122 | + list(APPEND GAME_HEADER proj.ios_mac/ios/AppController.h |
| 123 | + proj.ios_mac/ios/RootViewController.h) |
| 124 | + set(APP_UI_RES proj.ios_mac/ios/LaunchScreen.storyboard |
| 125 | + proj.ios_mac/ios/LaunchScreenBackground.png |
| 126 | + proj.ios_mac/ios/Images.xcassets) |
| 127 | + list(APPEND GAME_SOURCE proj.ios_mac/ios/main.m proj.ios_mac/ios/AppController.mm |
| 128 | + proj.ios_mac/ios/RootViewController.mm proj.ios_mac/ios/Prefix.pch ${APP_UI_RES}) |
| 129 | + elseif(MACOSX) |
| 130 | + set(APP_UI_RES proj.ios_mac/mac/Icon.icns proj.ios_mac/mac/Info.plist) |
| 131 | + list(APPEND GAME_SOURCE proj.ios_mac/mac/main.cpp |
| 132 | + proj.ios_mac/mac/Prefix.pch ${APP_UI_RES}) |
| 133 | + endif() |
| 134 | + list(APPEND GAME_SOURCE ${common_res_files}) |
| 135 | +endif() |
| 136 | + |
| 137 | +# mark app complie info and libs info |
| 138 | +set(all_code_files ${GAME_HEADER} ${GAME_SOURCE}) |
| 139 | +if(NOT ANDROID) |
| 140 | + add_executable(${APP_NAME} ${all_code_files}) |
| 141 | +else() |
| 142 | + add_library(${APP_NAME} SHARED ${all_code_files}) |
| 143 | + add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/platform/android |
| 144 | + ${ENGINE_BINARY_PATH}/cocos/platform) |
| 145 | + target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec |
| 146 | + -Wl,--no-whole-archive) |
| 147 | +endif() |
| 148 | + |
| 149 | +target_link_libraries(${APP_NAME} cocos2d "${firebase_libs}" ${ADDITIONAL_LIBS}) |
| 150 | +target_include_directories(${APP_NAME} PRIVATE Classes |
| 151 | + PRIVATE ${COCOS2DX_ROOT_PATH}/cocos/audio/include/) |
| 152 | + |
| 153 | +# mark app resources |
| 154 | +setup_cocos_app_config(${APP_NAME}) |
| 155 | +if(APPLE) |
| 156 | + set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}") |
| 157 | + if(MACOSX) |
| 158 | + set_xcode_property(${APP_NAME} INFOPLIST_FILE |
| 159 | + "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist") |
| 160 | + elseif(IOS) |
| 161 | + set_xcode_property(${APP_NAME} INFOPLIST_FILE |
| 162 | + "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/Info.plist") |
| 163 | + set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon") |
| 164 | + endif() |
| 165 | + |
| 166 | +# For code-signing, set the DEVELOPMENT_TEAM: |
| 167 | +#set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "GRLXXXX2K9") |
| 168 | +elseif(WINDOWS) |
| 169 | + cocos_copy_target_dll(${APP_NAME}) |
| 170 | +endif() |
| 171 | + |
| 172 | +if(LINUX OR WINDOWS) |
| 173 | + cocos_get_resource_path(APP_RES_DIR ${APP_NAME}) |
| 174 | + cocos_copy_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} |
| 175 | + FOLDERS ${GAME_RES_FOLDER}) |
| 176 | +endif() |
| 177 | + |
0 commit comments