1
0

CMakeLists.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. # THE SOFTWARE.
  22. # ****************************************************************************/
  23. cmake_policy(SET CMP0017 NEW)
  24. cmake_minimum_required(VERSION 3.1)
  25. set(APP_NAME MyGame)
  26. project (${APP_NAME})
  27. set(COCOS2D_ROOT ${CMAKE_SOURCE_DIR}/cocos2d)
  28. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${COCOS2D_ROOT}/cmake/Modules/")
  29. include(CocosBuildHelpers)
  30. # Some macro definitions
  31. if(WINDOWS)
  32. if(BUILD_SHARED_LIBS)
  33. ADD_DEFINITIONS (-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
  34. else()
  35. ADD_DEFINITIONS (-DCC_STATIC)
  36. endif()
  37. ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
  38. set(PLATFORM_FOLDER win32)
  39. elseif(MACOSX OR APPLE)
  40. ADD_DEFINITIONS (-DCC_TARGET_OS_MAC)
  41. ADD_DEFINITIONS (-DUSE_FILE32API)
  42. set(PLATFORM_FOLDER mac)
  43. elseif(LINUX)
  44. ADD_DEFINITIONS(-DLINUX)
  45. set(PLATFORM_FOLDER linux)
  46. elseif(ANDROID)
  47. ADD_DEFINITIONS (-DUSE_FILE32API)
  48. set(PLATFORM_FOLDER android)
  49. else()
  50. message( FATAL_ERROR "Unsupported platform, CMake will exit" )
  51. endif()
  52. # Compiler options
  53. if(MSVC)
  54. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  55. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrt /NODEFAULTLIB:libcmt")
  56. else()
  57. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt")
  58. endif()
  59. ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
  60. -wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
  61. -wd4514 -wd4056 -wd4996 -wd4099)
  62. else()
  63. if(CMAKE_BUILD_TYPE MATCHES Debug)
  64. ADD_DEFINITIONS(-DCOCOS2D_DEBUG=1)
  65. endif()
  66. set(CMAKE_C_FLAGS_DEBUG "-g -Wall")
  67. set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
  68. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  69. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
  70. if(CLANG)
  71. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  72. endif()
  73. endif(MSVC)
  74. set(PLATFORM_SPECIFIC_SRC)
  75. set(PLATFORM_SPECIFIC_HEADERS)
  76. if(MACOSX OR APPLE)
  77. set(PLATFORM_SPECIFIC_SRC
  78. proj.ios_mac/mac/main.cpp
  79. )
  80. elseif(LINUX)
  81. set(PLATFORM_SPECIFIC_SRC
  82. proj.linux/main.cpp
  83. )
  84. elseif ( WIN32 )
  85. set(PLATFORM_SPECIFIC_SRC
  86. proj.win32/main.cpp
  87. )
  88. set(PLATFORM_SPECIFIC_HEADERS
  89. proj.win32/main.h
  90. proj.win32/resource.h
  91. )
  92. elseif(ANDROID)
  93. set(PLATFORM_SPECIFIC_SRC
  94. proj.android-studio/app/jni/hellocpp/main.cpp
  95. )
  96. endif()
  97. include_directories(
  98. /usr/local/include/GLFW
  99. /usr/include/GLFW
  100. ${COCOS2D_ROOT}
  101. ${COCOS2D_ROOT}/cocos
  102. ${COCOS2D_ROOT}/external
  103. ${COCOS2D_ROOT}/cocos/platform
  104. ${COCOS2D_ROOT}/cocos/audio/include/
  105. Classes
  106. )
  107. if ( WIN32 )
  108. include_directories(
  109. ${COCOS2D_ROOT}/external/glfw3/include/win32
  110. ${COCOS2D_ROOT}/external/win32-specific/gles/include/OGLES
  111. )
  112. endif( WIN32 )
  113. set(GAME_SRC
  114. Classes/Ball.cpp
  115. Classes/AppDelegate.cpp
  116. Classes/BlocksLayer.cpp
  117. Classes/GameScene.cpp
  118. Classes/HelloWorldScene.cpp
  119. ${PLATFORM_SPECIFIC_SRC}
  120. )
  121. set(GAME_HEADERS
  122. Classes/Ball.h
  123. Classes/AppDelegate.h
  124. Classes/BlocksLayer.h
  125. Classes/GameScene.h
  126. Classes/HelloWorldScene.h
  127. Classes/params.h
  128. ${PLATFORM_SPECIFIC_HEADERS}
  129. )
  130. # Configure libcocos2d
  131. set(BUILD_CPP_EMPTY_TEST OFF CACHE BOOL "turn off build cpp-empty-test")
  132. set(BUILD_CPP_TESTS OFF CACHE BOOL "turn off build cpp-tests")
  133. set(BUILD_LUA_LIBS OFF CACHE BOOL "turn off build lua related targets")
  134. set(BUILD_JS_LIBS OFF CACHE BOOL "turn off build js related targets")
  135. add_subdirectory(${COCOS2D_ROOT})
  136. # MyGame
  137. if( ANDROID )
  138. add_library(${APP_NAME} SHARED ${GAME_SRC} ${GAME_HEADERS})
  139. IF(CMAKE_BUILD_TYPE MATCHES RELEASE)
  140. ADD_CUSTOM_COMMAND(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
  141. ENDIF()
  142. else()
  143. add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS})
  144. endif()
  145. target_link_libraries(${APP_NAME} cocos2d)
  146. set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
  147. set_target_properties(${APP_NAME} PROPERTIES
  148. RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
  149. if ( WIN32 )
  150. #also copying dlls to binary directory for the executable to run
  151. pre_build(${APP_NAME}
  152. COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources
  153. COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources
  154. COMMAND ${CMAKE_COMMAND} -E copy ${COCOS2D_ROOT}/external/win32-specific/gles/prebuilt/glew32.dll ${APP_BIN_DIR}/${CMAKE_BUILD_TYPE}
  155. COMMAND ${CMAKE_COMMAND} -E copy ${COCOS2D_ROOT}/external/win32-specific/zlib/prebuilt/zlib1.dll ${APP_BIN_DIR}/${CMAKE_BUILD_TYPE}
  156. )
  157. elseif( ANDROID )
  158. else()
  159. pre_build(${APP_NAME}
  160. COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources
  161. COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}/Resources
  162. )
  163. endif()