vanlannan

Untitled

Jun 20th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.63 KB | None | 0 0
  1. cmake_minimum_required(VERSION 2.8)
  2. project(mcpelauncher)
  3.  
  4. enable_language(C ASM)
  5.  
  6. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
  7.  
  8. set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
  9. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  10. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  11. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  12.  
  13. if(APPLE)
  14. set(CMAKE_LIBRARY_ARCHITECTURE "i386-apple-darwin")
  15. else()
  16. set(CMAKE_LIBRARY_ARCHITECTURE "i386-linux-gnu")
  17. endif(APPLE)
  18.  
  19. find_package(Threads REQUIRED)
  20. find_package(ZLIB REQUIRED)
  21. find_package(PNG)
  22. find_package(CURL)
  23. find_package(OpenSSL)
  24.  
  25. if(APPLE)
  26. find_package(OpenGL REQUIRED)
  27. find_package(Cocoa REQUIRED)
  28. find_package(CoreVideo REQUIRED)
  29. find_package(IOKit REQUIRED)
  30. else()
  31. find_package(X11)
  32. endif(APPLE)
  33.  
  34. include(ExternalProject)
  35.  
  36. set(BUILD_CLIENT true)
  37. set(BUILD_SERVER true)
  38. set(GLFW_ENABLED false)
  39. set(CEF_ENABLED true)
  40. set(PLAYAPI_ENABLED true)
  41. set(LIBZIP_FROM_SOURCES false)
  42. set(GAMEPAD_SUPPORT_ENABLED true)
  43. set(USE_ZENITY true)
  44.  
  45. if(APPLE)
  46. set(GLFW_ENABLED true)
  47. set(CEF_ENABLED false)
  48. set(PLAYAPI_ENABLED false)
  49. set(LIBZIP_FROM_SOURCES true)
  50. set(GAMEPAD_SUPPORT_ENABLED false)
  51. endif(APPLE)
  52.  
  53. if (NOT CURL_FOUND OR ((NOT PNG_FOUND OR NOT OPENSSL_FOUND OR NOT X11_FOUND) AND NOT APPLE))
  54. message(WARNING "One of the required dependencies for building the client were not found.\nOnly the server will be built as a result. To build the client please install the missing dependencies, and run cmake again.")
  55. set(BUILD_CLIENT false)
  56. set(CEF_ENABLED false)
  57. set(PLAYAPI_ENABLED false)
  58. endif()
  59.  
  60. if (GLFW_ENABLED)
  61. ExternalProject_Add(
  62. glfw
  63. URL "https://github.com/glfw/glfw/archive/3.2.1.tar.gz"
  64. URL_HASH SHA1=bee9cd9a8b4925184070ade5bc287c5635830eb0
  65. INSTALL_DIR ${CMAKE_BINARY_DIR}/ext/glfw
  66. CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/ext/glfw" "-DBUILD_SHARED_LIBS=OFF" "-DCMAKE_C_FLAGS=-m32" "-DCMAKE_LINK_FLAGS=-m32" "-DCMAKE_LIBRARY_ARCHITECTURE=${CMAKE_LIBRARY_ARCHITECTURE}"
  67. )
  68. set(GLFW_LIBRARIES ${CMAKE_BINARY_DIR}/ext/glfw/lib/libglfw3.a)
  69. set(GLFW_INCLUDE_DIR ${CMAKE_BINARY_DIR}/ext/glfw/include/)
  70. endif()
  71. set(LIBZIP_LIBRARIES zip)
  72. set(LIBZIP_INCLUDE_DIR )
  73. if (LIBZIP_FROM_SOURCES)
  74. ExternalProject_Add(
  75. libzip
  76. URL "https://github.com/nih-at/libzip/archive/rel-1-4-0.tar.gz"
  77. URL_HASH SHA1=7b38ace94d806f200bd34d67e40c9924291b6745
  78. INSTALL_DIR ${CMAKE_BINARY_DIR}/ext/libzip
  79. CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/ext/libzip" "-DBUILD_SHARED_LIBS=OFF" "CMAKE_CXX_FLAGS=-m32" "-DCMAKE_C_FLAGS=-m32" "-DCMAKE_LINK_FLAGS=-m32" "-DCMAKE_LIBRARY_ARCHITECTURE=${CMAKE_LIBRARY_ARCHITECTURE}"
  80. )
  81. set(LIBZIP_LIBRARIES ${CMAKE_BINARY_DIR}/ext/libzip/lib/libzip.a)
  82. set(LIBZIP_INCLUDE_DIR ${CMAKE_BINARY_DIR}/ext/libzip/include/)
  83.  
  84. find_package(BZip2)
  85. if (BZIP2_FOUND)
  86. set(LIBZIP_LIBRARIES ${LIBZIP_LIBRARIES} ${BZIP2_LIBRARY})
  87. endif()
  88. endif()
  89.  
  90. if (NOT EXISTS ${CMAKE_SOURCE_DIR}/libs/cef)
  91. if(NOT APPLE)
  92. message(WARNING "CEF not found. Xbox Live login and APK download features will be disabled.\nTo set up CEF please run setup_cef.sh in the source directory.")
  93. endif(NOT APPLE)
  94. set(CEF_ENABLED false)
  95. set(PLAYAPI_ENABLED false)
  96. endif()
  97. if (PLAYAPI_ENABLED)
  98. find_package(Protobuf)
  99. if (NOT Protobuf_FOUND)
  100. message(WARNING "Protobuf not found. Downloading the apk with a Google account will not be possible.")
  101. set(PLAYAPI_ENABLED false)
  102. endif()
  103. endif()
  104.  
  105. if (PLAYAPI_ENABLED)
  106. add_subdirectory(gplay_api)
  107. set_target_properties(gplaydl PROPERTIES EXCLUDE_FROM_ALL TRUE)
  108. endif()
  109.  
  110. if(APPLE)
  111. add_subdirectory(libs/epoll)
  112. include_directories(${Cocoa_INCLUDE_DIRS} ${CoreVideo_INCLUDE_DIRS} ${IOKit_INCLUDE_DIRS})
  113. include_directories(libs/elf)
  114. endif()
  115.  
  116. include_directories(${ZLIB_INCLUDE_DIRS} ${LIBZIP_INCLUDE_DIR})
  117. include_directories(libs/rapidxml)
  118. include_directories(libs/hybris/include)
  119.  
  120. set(HYBRIS_SOURCES libs/hybris/src/cache.c libs/hybris/src/dlfcn.c libs/hybris/src/hooks.c libs/hybris/src/hooks_shm.c libs/hybris/src/logging.c libs/hybris/src/properties.c libs/hybris/src/ctype.c libs/hybris/src/sysconf.c libs/hybris/src/jb/dlfcn.c libs/hybris/src/jb/linker.c libs/hybris/src/jb/linker_environ.c libs/hybris/src/jb/linker_format.c libs/hybris/src/jb/rt.c libs/hybris/src/hooks_pthread.c libs/hybris/src/hooks_dirent.c libs/hybris/src/hooks_io.c libs/hybris/src/hooks_net.c)
  121. if(APPLE)
  122. set(HYBRIS_SOURCES ${HYBRIS_SOURCES} libs/hybris/src/hooks_net_darwin.c libs/hybris/src/hooks_darwin_pthread_once.cpp)
  123. else()
  124. set(HYBRIS_SOURCES ${HYBRIS_SOURCES} libs/hybris/src/strlcpy.c)
  125. endif(APPLE)
  126.  
  127. set(EGLUT_SOURCES libs/eglut/eglut.c libs/eglut/eglut_x11.c)
  128.  
  129. set(COMMON_SOURCE_FILES src/common/common.cpp src/common/hook.cpp src/client/appplatform.cpp src/minecraft/ImagePickingCallback.h src/minecraft/FilePickerSettings.h src/minecraft/Common.h src/minecraft/Xbox.h src/minecraft/std/string.h src/common/base64.cpp src/common/base64.h src/common/async_result_util.h src/common/extract.cpp src/common/extract.h src/common/path_helper.cpp src/common/path_helper.h src/common/log.cpp src/common/log.h src/minecraft/symbols.cpp src/minecraft/symbols.h src/minecraft/std/function.h src/common/modloader.cpp src/common/modloader.h)
  130. set(CLIENT_SOURCE_FILES src/client/main.cpp src/client/appplatform.cpp src/client/fake_jni.cpp src/client/fake_jni.h src/msa/msa.cpp src/msa/msa.h src/msa/msa_token.h src/msa/msa_network.cpp src/msa/msa_network.h src/client/xboxlive.h src/client/xboxlive.cpp src/common/cll.cpp src/common/cll.h)
  131. set(CLIENT_SOURCE_FILES_GAMEPAD src/client/gamepad.cpp src/client/gamepad.h)
  132. set(CLIENT_SOURCE_FILES_CEF src/ui/browser/browser.cpp src/ui/browser/browser.h src/ui/browser/xbox_login_browser.h src/ui/browser/xbox_login_browser.cpp src/ui/browser/initial_setup_browser.cpp src/ui/browser/initial_setup_browser.h)
  133. set(CLIENT_SOURCE_FILES_CEF_GAMEPAD src/ui/browser/gamepad_mapper_browser.cpp src/ui/browser/gamepad_mapper_browser.h)
  134. set(CLIENT_SOURCE_FILES_PLAYAPI gplay_api/src/config.h gplay_api/src/config.cpp src/ui/browser/google_login_browser.h src/ui/browser/google_login_browser.cpp src/ui/browser/google_play_helper.cpp src/ui/browser/google_play_helper.h)
  135. set(CLIENT_SOURCE_FILES_CORE_UI src/ui/game_window/window.h src/ui/file_picker/file_picker.h src/ui/file_picker/file_picker_factory.cpp src/ui/file_picker/file_picker_factory.h)
  136. set(CLIENT_SOURCE_FILES_EGLUT src/ui/game_window/window_eglut.cpp src/ui/game_window/window_eglut.h)
  137. set(CLIENT_SOURCE_FILES_GLFW src/ui/game_window/window_glfw.cpp src/ui/game_window/window_glfw.h)
  138. set(CLIENT_SOURCE_FILES_ZENITY src/ui/file_picker/file_picker_zenity.cpp src/ui/file_picker/file_picker_zenity.h)
  139. set(SERVER_SOURCE_FILES src/server/server.cpp src/server/server_minecraft_app.h src/server/server_properties.cpp src/server/server_properties.h src/server/stub_key_provider.h)
  140.  
  141. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_CORE_UI})
  142.  
  143. if(APPLE)
  144. set(COMMON_SOURCE_FILES ${COMMON_SOURCE_FILES} src/minecraft/std/string_darwin.cpp)
  145. else()
  146. set(COMMON_SOURCE_FILES ${COMMON_SOURCE_FILES} src/minecraft/std/string_linux.cpp)
  147. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} src/client/amdfix.s src/common/openssl_multithread.cpp src/common/openssl_multithread.h)
  148. endif(APPLE)
  149.  
  150. if (USE_ZENITY)
  151. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_ZENITY})
  152. endif()
  153.  
  154.  
  155. set(HYBRIS_DEFINES PRIVATE ANDROID_X86_LINKER _GNU_SOURCE LINKER_TEXT_BASE=0xB0000100 LINKER_AREA_SIZE=0x01000000 LINKER_DEBUG=1)
  156.  
  157. if (CEF_ENABLED)
  158. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_CEF})
  159. link_directories(${CMAKE_SOURCE_DIR}/libs/cef/lib/)
  160. endif()
  161. if (PLAYAPI_ENABLED)
  162. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_PLAYAPI})
  163. endif()
  164. if (GLFW_ENABLED)
  165. include_directories(${GLFW_INCLUDE_DIR})
  166. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_GLFW})
  167. else()
  168. include_directories(libs/eglut)
  169. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_EGLUT} ${EGLUT_SOURCES})
  170. endif()
  171. if (GAMEPAD_SUPPORT_ENABLED)
  172. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_GAMEPAD})
  173. if (CEF_ENABLED)
  174. set(CLIENT_SOURCE_FILES ${CLIENT_SOURCE_FILES} ${CLIENT_SOURCE_FILES_CEF_GAMEPAD})
  175. endif()
  176. endif()
  177.  
  178. if (BUILD_CLIENT)
  179. include_directories(${CURL_INCLUDE_DIRS})
  180. if (NOT APPLE)
  181. include_directories(${PNG_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR})
  182. endif()
  183. add_executable(mcpelauncher ${HYBRIS_SOURCES} ${COMMON_SOURCE_FILES} ${CLIENT_SOURCE_FILES})
  184.  
  185. if (CEF_ENABLED)
  186. include_directories(libs/cef)
  187. target_link_libraries(mcpelauncher libcef.so libcef_dll_wrapper.a)
  188. else()
  189. target_compile_definitions(mcpelauncher PRIVATE DISABLE_CEF)
  190. endif()
  191. if (PLAYAPI_ENABLED)
  192. target_link_libraries(mcpelauncher gplayapi)
  193. else()
  194. target_compile_definitions(mcpelauncher PRIVATE DISABLE_PLAYAPI)
  195. endif()
  196. if (GLFW_ENABLED)
  197. add_dependencies(mcpelauncher glfw)
  198. target_link_libraries(mcpelauncher ${GLFW_LIBRARIES} ${X11_Xcursor_LIB} ${X11_Xrandr_LIB} ${X11_Xxf86vm_LIB} ${X11_Xinerama_LIB})
  199. target_compile_definitions(mcpelauncher PRIVATE USE_GLFW)
  200. else()
  201. target_compile_definitions(mcpelauncher PRIVATE USE_EGLUT)
  202. endif()
  203. if (GAMEPAD_SUPPORT_ENABLED)
  204. target_link_libraries(mcpelauncher evdev udev)
  205. target_compile_definitions(mcpelauncher PRIVATE GAMEPAD_SUPPORT)
  206. endif()
  207. if (LIBZIP_FROM_SOURCES)
  208. add_dependencies(mcpelauncher libzip)
  209. endif()
  210. if (USE_ZENITY)
  211. target_compile_definitions(mcpelauncher PRIVATE USE_ZENITY)
  212. endif()
  213.  
  214. target_link_libraries(mcpelauncher ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${LIBZIP_LIBRARIES} ${CURL_LIBRARIES})
  215.  
  216. if(APPLE)
  217. add_dependencies(mcpelauncher epoll)
  218. target_link_libraries(mcpelauncher ${Cocoa_LIBRARIES} ${CoreVideo_LIBRARIES} ${IOKit_LIBRARIES} ${OPENGL_LIBRARIES} epoll)
  219. else()
  220. target_link_libraries(mcpelauncher ${X11_X11_LIB} ${PNG_LIBRARIES} ${OPENSSL_LIBRARIES} rt EGL GLESv2)
  221. endif(APPLE)
  222.  
  223. target_compile_definitions(mcpelauncher ${HYBRIS_DEFINES})
  224. endif()
  225.  
  226. if (BUILD_SERVER)
  227. add_executable(server ${HYBRIS_SOURCES} ${COMMON_SOURCE_FILES} ${SERVER_SOURCE_FILES})
  228.  
  229. if(LIBZIP_FROM_SOURCES)
  230. add_dependencies(server libzip)
  231. endif()
  232.  
  233. target_link_libraries(server ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES} ${LIBZIP_LIBRARIES})
  234.  
  235. if(APPLE)
  236. add_dependencies(server epoll)
  237. target_link_libraries(server epoll)
  238. else()
  239. target_link_libraries(server rt)
  240. endif(APPLE)
  241.  
  242.  
  243. target_compile_definitions(server ${HYBRIS_DEFINES} SERVER)
  244. endif()
  245.  
  246. function (add_non_source_dir_custom_command command...)
  247. add_custom_command(TARGET mcpelauncher POST_BUILD
  248. COMMAND $<$<NOT:$<STREQUAL:$<TARGET_FILE_DIR:mcpelauncher>,${CMAKE_SOURCE_DIR}>>:${command}>)
  249. endfunction()
  250.  
  251. if (BUILD_CLIENT)
  252. add_custom_command(TARGET mcpelauncher POST_BUILD
  253. COMMAND ${CMAKE_COMMAND} -E make_directory
  254. $<TARGET_FILE_DIR:mcpelauncher>/src)
  255. add_custom_command(TARGET mcpelauncher POST_BUILD
  256. COMMAND ${CMAKE_COMMAND} -E create_symlink
  257. ${CMAKE_SOURCE_DIR}/libs/cef/lib/libcef.so $<TARGET_FILE_DIR:mcpelauncher>/libcef.so)
  258. add_custom_command(TARGET mcpelauncher POST_BUILD
  259. COMMAND ${CMAKE_COMMAND} -E create_symlink
  260. ${CMAKE_SOURCE_DIR}/libs/cef/bin/icudtl.dat $<TARGET_FILE_DIR:mcpelauncher>/icudtl.dat)
  261. add_custom_command(TARGET mcpelauncher POST_BUILD
  262. COMMAND ${CMAKE_COMMAND} -E create_symlink
  263. ${CMAKE_SOURCE_DIR}/libs/cef/bin/snapshot_blob.bin $<TARGET_FILE_DIR:mcpelauncher>/snapshot_blob.bin)
  264. add_custom_command(TARGET mcpelauncher POST_BUILD
  265. COMMAND ${CMAKE_COMMAND} -E create_symlink
  266. ${CMAKE_SOURCE_DIR}/libs/cef/bin/natives_blob.bin $<TARGET_FILE_DIR:mcpelauncher>/natives_blob.bin)
  267. add_custom_command(TARGET mcpelauncher POST_BUILD
  268. COMMAND ${CMAKE_COMMAND} -E create_symlink
  269. ${CMAKE_SOURCE_DIR}/libs/cef/bin/icudtl.dat $<TARGET_FILE_DIR:mcpelauncher>/icudtl.dat)
  270. add_non_source_dir_custom_command(${CMAKE_COMMAND} -E create_symlink
  271. ${CMAKE_SOURCE_DIR}/src/ui/browser/resources $<TARGET_FILE_DIR:mcpelauncher>/src/ui/browser/resources)
  272. add_non_source_dir_custom_command(${CMAKE_COMMAND} -E create_symlink
  273. ${CMAKE_SOURCE_DIR}/libs $<TARGET_FILE_DIR:mcpelauncher>/libs)
  274. add_non_source_dir_custom_command(${CMAKE_COMMAND} -E create_symlink
  275. ${CMAKE_SOURCE_DIR}/mcpelauncher-icon.png $<TARGET_FILE_DIR:mcpelauncher>/mcpelauncher-icon.png)
  276.  
  277. install(TARGETS mcpelauncher
  278. RUNTIME DESTINATION share/mcpelauncher/bin/)
  279. install(FILES libs/cef/lib/libcef.so libs/cef/bin/snapshot_blob.bin libs/cef/bin/natives_blob.bin libs/cef/bin/icudtl.dat start_mcpelauncher.sh
  280. DESTINATION share/mcpelauncher/bin
  281. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
  282. install(FILES mcpelauncher-icon.png
  283. DESTINATION share/mcpelauncher
  284. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
  285. install(DIRECTORY libs/cef/res
  286. DESTINATION share/mcpelauncher/libs/cef
  287. PATTERN "*"
  288. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
  289. install(DIRECTORY src/ui/browser/resources
  290. DESTINATION share/mcpelauncher/src/ui/browser
  291. PATTERN "*"
  292. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
  293. install(DIRECTORY libs/native
  294. DESTINATION share/mcpelauncher/libs
  295. PATTERN "*"
  296. PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
  297. install(DIRECTORY DESTINATION bin/)
  298. install(CODE "
  299. execute_process(
  300. COMMAND ${CMAKE_COMMAND} -E create_symlink
  301. ${CMAKE_INSTALL_PREFIX}/share/mcpelauncher/bin/start_mcpelauncher.sh ${CMAKE_INSTALL_PREFIX}/bin/mcpelauncher
  302. )")
  303. install(FILES mcpelauncher.desktop DESTINATION share/applications/)
  304. install(FILES mcpelauncher-icon.png DESTINATION share/pixmaps/)
  305. endif()
Add Comment
Please, Sign In to add comment