CocosUseLibs.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. macro(cocos2d_depend_libs)
  2. # confim the libs, prepare to link
  3. set(PLATFORM_SPECIFIC_LIBS)
  4. # confim the prebuilt libs, prepare to use
  5. set(PREBUILT_SPECIFIC_LIBS)
  6. if(WINDOWS)
  7. foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL SQLITE3)
  8. list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
  9. endforeach()
  10. list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm Version Iphlpapi)
  11. if(MINGW)
  12. list(APPEND PLATFORM_SPECIFIC_LIBS shlwapi version)
  13. endif()
  14. elseif(LINUX)
  15. # need review those libs: X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m
  16. list(APPEND PLATFORM_SPECIFIC_LIBS dl X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m)
  17. foreach(_pkg OPENGL GLEW GLFW3 FMOD FONTCONFIG THREADS GTK3 SQLITE3)
  18. list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
  19. endforeach()
  20. elseif(ANDROID)
  21. list(APPEND PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
  22. list(APPEND PREBUILT_SPECIFIC_LIBS TREMOLO PVMP3DEC CPUFEATURES)
  23. elseif(APPLE)
  24. include_directories(/System/Library/Frameworks)
  25. find_library(ICONV_LIBRARY iconv)
  26. find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
  27. find_library(FOUNDATION_LIBRARY Foundation)
  28. find_library(OPENAL_LIBRARY OpenAL)
  29. find_library(QUARTZCORE_LIBRARY QuartzCore)
  30. set(COCOS_APPLE_LIBS
  31. ${OPENAL_LIBRARY}
  32. ${AUDIOTOOLBOX_LIBRARY}
  33. ${QUARTZCORE_LIBRARY}
  34. ${FOUNDATION_LIBRARY}
  35. ${ICONV_LIBRARY}
  36. )
  37. if(MACOSX)
  38. list(APPEND PREBUILT_SPECIFIC_LIBS GLFW3)
  39. find_library(COCOA_LIBRARY Cocoa)
  40. find_library(OPENGL_LIBRARY OpenGL)
  41. find_library(APPLICATIONSERVICES_LIBRARY ApplicationServices)
  42. find_library(IOKIT_LIBRARY IOKit)
  43. list(APPEND PLATFORM_SPECIFIC_LIBS
  44. ${COCOA_LIBRARY}
  45. ${OPENGL_LIBRARY}
  46. ${APPLICATIONSERVICES_LIBRARY}
  47. ${IOKIT_LIBRARY}
  48. ${COCOS_APPLE_LIBS}
  49. )
  50. elseif(IOS)
  51. # Locate system libraries on iOS
  52. find_library(UIKIT_LIBRARY UIKit)
  53. find_library(OPENGLES_LIBRARY OpenGLES)
  54. find_library(CORE_MOTION_LIBRARY CoreMotion)
  55. find_library(MEDIA_PLAYER_LIBRARY MediaPlayer)
  56. find_library(CORE_TEXT_LIBRARY CoreText)
  57. find_library(SECURITY_LIBRARY Security)
  58. find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
  59. find_library(AV_FOUNDATION_LIBRARY AVFoundation)
  60. find_library(Z_LIBRARY z)
  61. list(APPEND PLATFORM_SPECIFIC_LIBS
  62. ${UIKIT_LIBRARY}
  63. ${OPENGLES_LIBRARY}
  64. ${CORE_MOTION_LIBRARY}
  65. ${MEDIA_PLAYER_LIBRARY}
  66. ${CORE_TEXT_LIBRARY}
  67. ${SECURITY_LIBRARY}
  68. ${CORE_GRAPHICS_LIBRARY}
  69. ${AV_FOUNDATION_LIBRARY}
  70. ${Z_LIBRARY}
  71. ${COCOS_APPLE_LIBS}
  72. )
  73. endif()
  74. endif()
  75. foreach(_pkg ZLIB MINIZIP TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
  76. list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
  77. endforeach()
  78. if(NOT EMSCRIPTEN)
  79. list(APPEND PREBUILT_SPECIFIC_LIBS OPENSSL)
  80. endif()
  81. if(USE_JPEG)
  82. add_definitions(-DCC_USE_JPEG=1)
  83. list(APPEND PREBUILT_SPECIFIC_LIBS JPEG)
  84. else()
  85. add_definitions(-DCC_USE_JPEG=0)
  86. endif()
  87. if(USE_WEBP)
  88. cocos_find_package(WebP WEBP REQUIRED)
  89. add_definitions(-DCC_USE_WEBP=1)
  90. list(APPEND PREBUILT_SPECIFIC_LIBS WEBP)
  91. else()
  92. add_definitions(-DCC_USE_WEBP=0)
  93. endif()
  94. if(USE_TIFF)
  95. add_definitions(-DCC_USE_TIFF=1)
  96. list(APPEND PREBUILT_SPECIFIC_LIBS TIFF)
  97. else()
  98. add_definitions(-DCC_USE_TIFF=0)
  99. endif()
  100. if(USE_PNG)
  101. add_definitions(-DCC_USE_PNG=1)
  102. list(APPEND PREBUILT_SPECIFIC_LIBS PNG)
  103. else()
  104. add_definitions(-DCC_USE_PNG=0)
  105. endif()
  106. if(USE_CHIPMUNK)
  107. cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
  108. add_definitions(-DCC_USE_PHYSICS=1)
  109. add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
  110. list(APPEND PREBUILT_SPECIFIC_LIBS CHIPMUNK)
  111. else()
  112. add_definitions(-DCC_USE_PHYSICS=0)
  113. add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=0)
  114. endif()
  115. if(USE_BOX2D)
  116. cocos_find_package(box2d Box2D REQUIRED)
  117. add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
  118. list(APPEND PREBUILT_SPECIFIC_LIBS Box2D)
  119. else()
  120. add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
  121. endif(USE_BOX2D)
  122. if(USE_BULLET)
  123. cocos_find_package(bullet BULLET REQUIRED)
  124. add_definitions(-DCC_USE_3D_PHYSICS=1)
  125. add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
  126. list(APPEND PREBUILT_SPECIFIC_LIBS BULLET)
  127. else(USE_BULLET)
  128. add_definitions(-DCC_USE_3D_PHYSICS=0)
  129. add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
  130. endif(USE_BULLET)
  131. if(USE_RECAST)
  132. list(APPEND PREBUILT_SPECIFIC_LIBS RECAST)
  133. endif()
  134. endmacro()
  135. macro(target_use_cocos2d_depend_libs target)
  136. cocos2d_depend_libs()
  137. message(STATUS "${target} prepare to use cpp needed libs: ${PREBUILT_SPECIFIC_LIBS}")
  138. foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
  139. cocos_use_pkg(${target} ${prebuilt_lib})
  140. endforeach()
  141. foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
  142. target_link_libraries(${target} ${platform_lib})
  143. endforeach()
  144. endmacro()
  145. macro(jscocos2d_depend_libs)
  146. set(PLATFORM_SPECIFIC_LIBS)
  147. set(PREBUILT_SPECIFIC_LIBS)
  148. list(APPEND PREBUILT_SPECIFIC_LIBS SPIDERMONKEY)
  149. if(APPLE)
  150. find_library(GAME_CONTROLLER GameController)
  151. list(APPEND PLATFORM_SPECIFIC_LIBS ${GAME_CONTROLLER})
  152. list(APPEND PREBUILT_SPECIFIC_LIBS SQLITE3)
  153. endif()
  154. endmacro()
  155. macro(target_use_jscocos2d_depend_libs target)
  156. jscocos2d_depend_libs()
  157. message(STATUS "${target} prepare to use js needed libs: ${PREBUILT_SPECIFIC_LIBS}")
  158. foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
  159. cocos_use_pkg(${target} ${prebuilt_lib})
  160. endforeach()
  161. foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
  162. target_link_libraries(${target} ${platform_lib})
  163. endforeach()
  164. endmacro()
  165. macro(luacocos2d_depend_libs)
  166. set(PLATFORM_SPECIFIC_LIBS)
  167. set(PREBUILT_SPECIFIC_LIBS)
  168. list(APPEND PREBUILT_SPECIFIC_LIBS LUAJIT)
  169. endmacro()
  170. macro(target_use_luacocos2d_depend_libs target)
  171. luacocos2d_depend_libs()
  172. message(STATUS "${target} prepare to use lua needed libs: ${PREBUILT_SPECIFIC_LIBS}")
  173. foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
  174. cocos_use_pkg(${target} ${prebuilt_lib})
  175. endforeach()
  176. foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
  177. target_link_libraries(${target} ${platform_lib})
  178. endforeach()
  179. endmacro()
  180. macro(simulator_depend_libs)
  181. set(PLATFORM_SPECIFIC_LIBS)
  182. set(PREBUILT_SPECIFIC_LIBS)
  183. if(MACOSX)
  184. include_directories(/System/Library/Frameworks)
  185. find_library(APPKIT_LIBRARY AppKit)
  186. list(APPEND PLATFORM_SPECIFIC_LIBS ${APPKIT_LIBRARY})
  187. elseif(WINDOWS)
  188. list(APPEND PREBUILT_SPECIFIC_LIBS TinyXML2 CURL)
  189. endif()
  190. endmacro()
  191. macro(target_use_simulator_depend_libs target)
  192. simulator_depend_libs()
  193. if(WINDOWS)
  194. message(STATUS "${target} prepare to use simulator needed libs: ${PREBUILT_SPECIFIC_LIBS}")
  195. endif()
  196. foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
  197. cocos_use_pkg(${target} ${prebuilt_lib})
  198. endforeach()
  199. foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
  200. target_link_libraries(${target} ${platform_lib})
  201. endforeach()
  202. endmacro()