cmake support win32 ,and support generate&use prebuilt libs (#18683)

* fix win32 prebuilt error, and set cmake as default android native build

* cpp-template support msvc

* add msvc version check

* add -D_USRLUASTATIC, fix lua lib cmake compile error

* fix cpp-empty-test res copy dir, add function needed

* improve msvc res copy

* refactor cmake copy dll logic

* fix cpp-tests compile error

* refactor copy dll temp

* refactor win32 exe using dlls

* js-project compile support cmake using msvc

* improve res mark for win32

* update the way of lua project res mark

* add D_USRLUASTATIC for lua project

* unify RELEASE Release to Release, add CMAKE_CONFIGURATION_TYPES

* improve VS shows targets, add folder

* improve mac/ios res mark

* reduce useless comments

* unify cpp src include variable

* refactor cpp test project  package logic

* improve pkg app logic

* start support prebuilt libs for cpp project using cmake

* improve prebuilt libs generate

* expand js/lua support prebuilt libs on mac

* adapt IDE generate libs path

* start do prebuilt for android

* improve the way of using external libs for prebuilt

* prebuilt libs support cpp-empty-test on android studio

* cpp-tests prebuilt libs, and remove useless

* start to improve libs using, to adapt prebuilt

* improve cpp tests prebuilt on android

* prebuilt support lua & js test on android

* prebuilt support cpp&js template

* rename prebuilt variabl, detail androd config

* finish android support prebuilt using cmake

* fix cmake script run in windows error

* reduce variable name length

* improve the way of win32 use dlls to adapt prebuilt

* loosen pick js/lua engine lib condition

* self review and start check linux build

* unify compile option location

* strict copy dlls condition

* improve libs link order

* start redo the way of copy dlls

* unify dlls copy logic

* fix linux res copy error

* update cmake copy file path in linux

* make prebuilt dir if needed, and divide Debug and Release dir

* cmake win32 divide Debug and Release dir well

* comment Lua Template project, for the unfinished lua simulator support

* add simulator cmake file

* start support simulator

* simulator support cmake build on macOS

* fix simulator compile error on win32

* add simulator prebuilt support

* improve mark cocos app macro

* improve cmake template project format

* improve cmake app files format

* fix format improve mistake

* detail cmake readme

* improve readme, useless comments

* add game.rc to template project

* check travis openssl version

* try update travis openssl

* upgrade travis openssl

* change openssl link

* change to upgrade openssl

* re install python with upgrade openssl

* add comment for macro and func, improve variable name
This commit is contained in:
leda 2018-03-07 17:47:57 -08:00 committed by minggo
parent f75172b42b
commit 50ecf00115
46 changed files with 1957 additions and 1497 deletions

View File

@ -38,15 +38,13 @@ set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
include(CocosBuildSet)
CocosBuildSet()
# TODO: use cocos prebuilt library
if(USE_COCOS_PREBUILT_LIBS)
# use prebuilt library, not build
else(USE_COCOS_PREBUILT_LIBS)
# build engine library
# default tests include lua, js test project, so we set those option on to build libs
set(BUILD_LUA_LIBS ON)
set(BUILD_JS_LIBS ON)
set(USE_SIMULATOR ON)
if(NOT USE_COCOS_PREBUILT)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
# build engine all tests project
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)
endif(USE_COCOS_PREBUILT_LIBS)
endif()
add_subdirectory(${COCOS2DX_ROOT_PATH}/tests ${ENGINE_BINARY_PATH}/tests)

View File

@ -32,6 +32,11 @@ macro(android_ndk_import_module_cpufeatures)
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
add_library(cpufeatures ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
target_link_libraries(cpufeatures dl)
set_target_properties(cpufeatures
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
endif()
endmacro()

View File

@ -1,202 +1,247 @@
macro (BuildModules)
# header files third libiary needed, such as tinyxml2.h
include_directories(
${COCOS2DX_ROOT_PATH}
${COCOS2DX_ROOT_PATH}/cocos
${COCOS2DX_ROOT_PATH}/deprecated
${COCOS2DX_ROOT_PATH}/cocos/platform
${COCOS2DX_ROOT_PATH}/extensions
${COCOS2DX_ROOT_PATH}/external
)
# header files third libiary needed, such as tinyxml2.h
include_directories(
${COCOS2DX_ROOT_PATH}
${COCOS2DX_ROOT_PATH}/cocos
${COCOS2DX_ROOT_PATH}/deprecated
${COCOS2DX_ROOT_PATH}/cocos/platform
${COCOS2DX_ROOT_PATH}/extensions
${COCOS2DX_ROOT_PATH}/external
)
# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL REQUIRED)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)
# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL REQUIRED)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)
if(LINUX OR WINDOWS)
cocos_find_package(GLEW GLEW REQUIRED)
#TODO: implement correct schema for pass cocos2d specific requirements to projects
include_directories(${GLEW_INCLUDE_DIRS})
endif()
if(LINUX OR WINDOWS)
cocos_find_package(GLEW GLEW REQUIRED)
#TODO: implement correct schema for pass cocos2d specific requirements to projects
include_directories(${GLEW_INCLUDE_DIRS})
endif()
cocos_find_package(GLFW3 GLFW3 REQUIRED)
include_directories(${GLFW3_INCLUDE_DIRS})
cocos_find_package(GLFW3 GLFW3 REQUIRED)
include_directories(${GLFW3_INCLUDE_DIRS})
if(LINUX)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
if(LINUX)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
endif()
cocos_find_package(FMOD FMOD REQUIRED)
cocos_find_package(Fontconfig FONTCONFIG REQUIRED)
cocos_find_package(GTK3 GTK3 REQUIRED)
endif()
if(WINDOWS)
cocos_find_package(Vorbis VORBIS REQUIRED)
cocos_find_package(MPG123 MPG123 REQUIRED)
cocos_find_package(OpenAL OPENAL REQUIRED)
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
endif()
endif(LINUX OR MACOSX OR WINDOWS)
if(WINDOWS)
cocos_find_package(Vorbis VORBIS REQUIRED)
cocos_find_package(MPG123 MPG123 REQUIRED)
cocos_find_package(OpenAL OPENAL REQUIRED)
# because FindOpenAL.cmake set include dir for '#include <al.h>' for portability (not for '#include <AL/al.h>'
set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES")
endif()
endif(LINUX OR MACOSX OR WINDOWS)
# Freetype required on all platforms
cocos_find_package(Freetype FREETYPE REQUIRED)
# Freetype required on all platforms
cocos_find_package(Freetype FREETYPE REQUIRED)
# WebP required if used
if(USE_WEBP)
cocos_find_package(WebP WEBP REQUIRED)
endif(USE_WEBP)
# WebP required if used
if(USE_WEBP)
cocos_find_package(WebP WEBP REQUIRED)
endif(USE_WEBP)
# Chipmunk
if(USE_CHIPMUNK)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
else(USE_CHIPMUNK)
add_definitions(-DCC_USE_PHYSICS=0)
endif(USE_CHIPMUNK)
# Chipmunk
if(USE_CHIPMUNK)
cocos_find_package(Chipmunk CHIPMUNK REQUIRED)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
else(USE_CHIPMUNK)
add_definitions(-DCC_USE_PHYSICS=0)
endif(USE_CHIPMUNK)
# Box2d
if(USE_BOX2D)
if(USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(box2d Box2D REQUIRED)
endif(USE_EXTERNAL_PREBUILT_LIBS)
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
elseif(BUILD_BOX2D)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/Box2D ${ENGINE_BINARY_PATH}/external/Box2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)
# Box2d
if(USE_BOX2D)
if(USE_EXTERNAL_PREBUILT)
cocos_find_package(box2d Box2D REQUIRED)
endif(USE_EXTERNAL_PREBUILT)
message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}")
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
elseif(BUILD_BOX2D)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/Box2D ${ENGINE_BINARY_PATH}/external/Box2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif(USE_BOX2D)
# Bullet
if(USE_BULLET)
if(USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(bullet BULLET REQUIRED)
endif()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
else(USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif(USE_BULLET)
# Bullet
if(USE_BULLET)
if(USE_EXTERNAL_PREBUILT)
cocos_find_package(bullet BULLET REQUIRED)
endif()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_PHYSICS=1)
message(STATUS "Bullet include dirs: ${BULLET_INCLUDE_DIRS}")
else(USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif(USE_BULLET)
# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/recast ${ENGINE_BINARY_PATH}/external/recast)
set(RECAST_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/recast)
set(RECAST_LIBRARIES recast)
else()
cocos_find_package(recast RECAST REQUIRED)
set(RECAST_LIBRARIES recast)
endif()
message(STATUS "Recast include dirs: ${RECAST_INCLUDE_DIRS}")
add_definitions(-DCC_USE_NAVMESH=1)
else(USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=0)
endif(USE_RECAST)
# Recast (not prebuilded, exists as source)
if(USE_RECAST)
if(USE_EXTERNAL_PREBUILT OR USE_EXTERNAL_SOURCES)
set(_recast_prefix RECAST)
set(RECAST_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/recast)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(recast RECAST_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/recast ${ENGINE_BINARY_PATH}/external/recast)
set(RECAST_LIBRARIES recast)
endif()
else()
cocos_find_package(recast RECAST REQUIRED)
set(RECAST_LIBRARIES recast)
endif()
message(STATUS "Recast include dirs: ${RECAST_INCLUDE_DIRS}")
add_definitions(-DCC_USE_NAVMESH=1)
else(USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=0)
endif(USE_RECAST)
# Tinyxml2 (not prebuilded, exists as source)
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/tinyxml2 ${ENGINE_BINARY_PATH}/external/tinyxml2)
set(TinyXML2_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/tinyxml2)
set(TinyXML2_LIBRARIES tinyxml2)
else()
cocos_find_package(TinyXML2 TinyXML2 REQUIRED)
endif()
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")
# Tinyxml2 (not prebuilded, exists as source)
if(USE_EXTERNAL_PREBUILT OR USE_EXTERNAL_SOURCES)
set(_tinyxml2_prefix TinyXML2)
set(TinyXML2_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/tinyxml2)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(tinyxml2 TinyXML2_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/tinyxml2 ${ENGINE_BINARY_PATH}/external/tinyxml2)
set(TinyXML2_LIBRARIES tinyxml2)
endif()
else()
cocos_find_package(TinyXML2 TinyXML2 REQUIRED)
endif()
message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}")
# need review
if(NOT IOS)
cocos_find_package(ZLIB ZLIB REQUIRED)
endif()
if(IOS)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)
endif(IOS)
if(NOT IOS)
cocos_find_package(ZLIB ZLIB REQUIRED)
endif()
if(IOS)
cocos_find_package(SQLite3 SQLITE3 REQUIRED)
endif(IOS)
if(ANDROID)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec ${ENGINE_BINARY_PATH}/external/android-specific/pvmp3dec)
set(PVMP3DEC_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/include ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/src)
set(PVMP3DEC_LIBRARIES pvmp3dec)
message(STATUS "pvmp3dec include dirs: ${PVMP3DEC_INCLUDE_DIRS}")
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo ${ENGINE_BINARY_PATH}/external/android-specific/tremolo)
set(TREMOLO_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo)
set(TREMOLO_LIBRARIES tremolo)
message(STATUS "Tremolo include dirs: ${TREMOLO_INCLUDE_DIRS}")
endif()
if(ANDROID)
set(_pvmp3dec_prefix PVMP3DEC)
set(PVMP3DEC_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/include ${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec/src)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(pvmp3dec PVMP3DEC_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/pvmp3dec ${ENGINE_BINARY_PATH}/external/android-specific/pvmp3dec)
set(PVMP3DEC_LIBRARIES pvmp3dec)
endif()
message(STATUS "pvmp3dec include dirs: ${PVMP3DEC_INCLUDE_DIRS}")
set(_tremolo_prefix TREMOLO)
set(TREMOLO_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(tremolo TREMOLO_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/android-specific/tremolo ${ENGINE_BINARY_PATH}/external/android-specific/tremolo)
set(TREMOLO_LIBRARIES tremolo)
endif()
message(STATUS "Tremolo include dirs: ${TREMOLO_INCLUDE_DIRS}")
set(_cpufeatures_prefix CPUFEATURES)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(cpufeatures CPUFEATURES_LIBRARIES)
else()
include(${CMAKE_MODULE_PATH}/../AndroidNdkModules.cmake)
android_ndk_import_module_cpufeatures()
set(CPUFEATURES_LIBRARIES cpufeatures)
endif()
endif()
# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
# only msys2 currently provides package for this variant, all other
# dists have packages from zlib, thats very old for us.
# moreover our embedded version modified to quick provide
# functionality needed by cocos.
if(USE_EXTERNAL_PREBUILT_LIBS OR NOT MINGW OR USE_SOURCES_EXTERNAL)
#TODO: hack! should be in external/unzip/CMakeLists.txt
include_directories(${ZLIB_INCLUDE_DIRS})
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/unzip ${ENGINE_BINARY_PATH}/external/unzip)
set(MINIZIP_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/unzip ${ZLIB_INCLUDE_DIRS})
set(MINIZIP_LIBRARIES unzip ${ZLIB_LIBRARIES})
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
else()
cocos_find_package(MINIZIP MINIZIP REQUIRED)
# double check that we have needed functions
include(CheckLibraryExists)
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()
# Jpeg
if(USE_JPEG)
cocos_find_package(JPEG JPEG REQUIRED)
add_definitions(-DCC_USE_JPEG=1)
else(USE_JPEG)
add_definitions(-DCC_USE_JPEG=0)
endif(USE_JPEG)
# minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip)
# only msys2 currently provides package for this variant, all other
# dists have packages from zlib, thats very old for us.
# moreover our embedded version modified to quick provide
# functionality needed by cocos.
if(USE_EXTERNAL_PREBUILT OR NOT MINGW OR USE_EXTERNAL_SOURCES)
set(_unzip_prefix MINIZIP)
include_directories(${ZLIB_INCLUDE_DIRS})
set(MINIZIP_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/unzip ${ZLIB_INCLUDE_DIRS})
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(unzip MINIZIP_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/unzip ${ENGINE_BINARY_PATH}/external/unzip)
# set(MINIZIP_LIBRARIES unzip ${ZLIB_LIBRARIES})
set(MINIZIP_LIBRARIES unzip)
endif()
message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}")
else()
cocos_find_package(MINIZIP MINIZIP REQUIRED)
# double check that we have needed functions
include(CheckLibraryExists)
add_definitions(-DMINIZIP_FROM_SYSTEM)
endif()
# Jpeg
if(USE_JPEG)
cocos_find_package(JPEG JPEG REQUIRED)
add_definitions(-DCC_USE_JPEG=1)
else(USE_JPEG)
add_definitions(-DCC_USE_JPEG=0)
endif(USE_JPEG)
# Tiff
if(USE_TIFF)
cocos_find_package(TIFF TIFF REQUIRED)
add_definitions(-DCC_USE_TIFF=1)
else(USE_TIFF)
add_definitions(-DCC_USE_TIFF=0)
endif(USE_TIFF)
# Tiff
if(USE_TIFF)
cocos_find_package(TIFF TIFF REQUIRED)
add_definitions(-DCC_USE_TIFF=1)
else(USE_TIFF)
add_definitions(-DCC_USE_TIFF=0)
endif(USE_TIFF)
# Png
if(USE_PNG)
cocos_find_package(PNG PNG REQUIRED)
add_definitions(-DCC_USE_PNG=1)
else(USE_PNG)
# Png
if(USE_PNG)
cocos_find_package(PNG PNG REQUIRED)
add_definitions(-DCC_USE_PNG=1)
else(USE_PNG)
add_definitions(-DCC_USE_PNG=0)
endif(USE_PNG)
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
if(NOT USE_EXTERNAL_PREBUILT_LIBS)
cocos_find_package(OpenSSL OPENSSL REQUIRED)
endif()
endif(USE_PNG)
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
if(NOT USE_EXTERNAL_PREBUILT)
cocos_find_package(OpenSSL OPENSSL REQUIRED)
endif()
# flatbuffers
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/flatbuffers ${ENGINE_BINARY_PATH}/external/flatbuffers)
set(FLATBUFFERS_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
cocos_find_package(flatbuffers flatbuffers REQUIRED)
endif()
# flatbuffers
if(USE_EXTERNAL_PREBUILT OR USE_EXTERNAL_SOURCES)
set(_flatbuffers_prefix FLATBUFFERS)
set(FLATBUFFERS_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(flatbuffers FLATBUFFERS_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/flatbuffers ${ENGINE_BINARY_PATH}/external/flatbuffers)
set(FLATBUFFERS_LIBRARIES flatbuffers)
endif()
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
else()
cocos_find_package(flatbuffers FLATBUFFERS REQUIRED)
endif()
# xxhash
if(USE_EXTERNAL_PREBUILT_LIBS OR USE_SOURCES_EXTERNAL)
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/xxhash ${ENGINE_BINARY_PATH}/external/xxhash)
set(XXHASH_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()
# xxhash
if(USE_EXTERNAL_PREBUILT OR USE_EXTERNAL_SOURCES)
set(_xxhash_prefix XXHASH)
set(XXHASH_INCLUDE_DIRS ${COCOS2DX_ROOT_PATH}/external/xxhash)
if(USE_COCOS_PREBUILT)
cocos_find_prebuilt_lib_by_name(xxhash XXHASH_LIBRARIES)
else()
add_subdirectory(${COCOS2DX_ROOT_PATH}/external/xxhash ${ENGINE_BINARY_PATH}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
endif()
message(STATUS "xxhash include dirs: ${XXHASH_INCLUDE_DIRS}")
else()
cocos_find_package(xxhash xxhash REQUIRED)
endif()
endmacro(BuildModules)

View File

@ -1,44 +1,136 @@
include(CMakeParseArguments)
# copy libs to static libs folder
# error function, have bug
function(cocos_put_static_libs lib_target lib_dir)
add_custom_command(TARGET ${lib_target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${lib_dir}/lib${lib_target}.a ${COCOS_PREBUILT_LIBS_PATH}/lib${lib_target}.a
COMMENT "${TARGET_NAME} POST_BUILD ..."
)
# find a prebuilt lib by `lib_name` and save the result in `lib_out`
function(cocos_find_prebuilt_lib_by_name lib_name lib_out)
set(search_path ${COCOS_PREBUILT_PATH})
if(XCODE OR VS)
set(search_path ${COCOS_PREBUILT_PATH}/${CMAKE_BUILD_TYPE})
endif()
message(STATUS "search_path cocos prebuilt library: ${search_path}")
find_library(found_lib ${lib_name} PATHS ${search_path} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
if(found_lib)
message(STATUS "find cocos prebuilt library: ${found_lib}")
else()
message(STATUS "can't find cocos prebuilt library: ${lib_name}")
endif()
set(${lib_out} ${found_lib} PARENT_SCOPE)
unset(found_lib CACHE)
endfunction()
# lib_name eg cocos2d/cocos2djs
macro(cocos_find_static_libs lib_name)
# only search COCOS_PREBUILT_LIBS_PATH
MESSAGE( STATUS "cocos static library path: ${COCOS_PREBUILT_LIBS_PATH}")
FIND_LIBRARY(LIB_FOUND ${lib_name} PATHS ${COCOS_PREBUILT_LIBS_PATH} DOC "using cocos static library: lib${lib_name}.a" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
# set flag
if(${LIB_FOUND} STREQUAL LIB_FOUND-NOTFOUND)
set(FIND_COCOS_STATIC_LIBS OFF)
else()
set(FIND_COCOS_STATIC_LIBS ON)
MESSAGE( STATUS "using cocos static library: ${LIB_FOUND}")
endif()
endmacro()
macro(pre_build TARGET_NAME)
add_custom_target( ${TARGET_NAME}_PRE_BUILD ALL )
add_custom_command(
TARGET ${TARGET_NAME}_PRE_BUILD
${ARGN}
PRE_BUILD
COMMENT "${TARGET_NAME}_PRE_BUILD ..."
# copy resource `FILES` and `FOLDERS` to `COPY_TO` folder before `cocos_target` build
function(cocos_copy_target_res cocos_target)
set(oneValueArgs COPY_TO)
set(multiValueArgs FILES FOLDERS)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# copy files
foreach(cc_file ${opt_FILES})
get_filename_component(file_name ${cc_file} NAME)
add_custom_command(TARGET ${cocos_target} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${cc_file}
"${opt_COPY_TO}/${file_name}"
)
endforeach()
# copy folders
foreach(cc_folder ${opt_FOLDERS})
add_custom_command(TARGET ${cocos_target} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${cc_folder}
${opt_COPY_TO}
)
endforeach()
endfunction()
add_custom_target(${TARGET_NAME}_CORE_PRE_BUILD)
add_dependencies(${TARGET_NAME}_PRE_BUILD ${TARGET_NAME}_CORE_PRE_BUILD)
add_dependencies(${TARGET_NAME} ${TARGET_NAME}_PRE_BUILD)
endmacro()
# mark `FILES` and files in `FOLDERS` as resource files, the destination is `RES_TO` folder
# save all marked files in `res_out`
function(cocos_mark_multi_resources res_out)
set(oneValueArgs RES_TO)
set(multiValueArgs FILES FOLDERS)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(tmp_file_list)
foreach(cc_file ${opt_FILES})
get_filename_component(file_dir ${cc_file} DIRECTORY)
cocos_mark_resources(FILES ${cc_file} BASEDIR ${file_dir} RESOURCEBASE ${opt_RES_TO})
endforeach()
list(APPEND tmp_file_list ${opt_FILES})
foreach(cc_folder ${opt_FOLDERS})
file(GLOB_RECURSE folder_files "${cc_folder}/*")
list(APPEND tmp_file_list ${folder_files})
cocos_mark_resources(FILES ${folder_files} BASEDIR ${cc_folder} RESOURCEBASE ${opt_RES_TO})
endforeach()
set(${res_out} ${tmp_file_list} PARENT_SCOPE)
endfunction()
# get `cocos_target` depend all dlls, save the result in `all_depend_dlls_out`
function(get_target_depends_ext_dlls cocos_target all_depend_dlls_out)
set(all_depend_ext_dlls)
set(targets_prepare_search ${cocos_target})
# targets_prepare_search, target need find ext libs
set(have_searched_targets)
set(need_search_targets)
while(true)
foreach(tmp_target ${targets_prepare_search})
get_target_property(tmp_depend_libs ${tmp_target} LINK_LIBRARIES)
list(REMOVE_ITEM targets_prepare_search ${tmp_target})
# target itself use_cocos_pkg
list(APPEND tmp_depend_libs ${tmp_target})
foreach(depend_lib ${tmp_depend_libs})
if(TARGET ${depend_lib})
get_target_property(tmp_dlls ${depend_lib} DEPEND_DLLS)
if(tmp_dlls)
list(APPEND all_depend_ext_dlls ${tmp_dlls})
endif()
if(NOT (depend_lib STREQUAL tmp_target))
list(APPEND targets_prepare_search ${depend_lib})
endif()
endif()
endforeach()
endforeach()
list(LENGTH targets_prepare_search targets_prepare_search_size)
if(targets_prepare_search_size LESS 1)
break()
endif()
endwhile(true)
set(${all_depend_dlls_out} ${all_depend_ext_dlls} PARENT_SCOPE)
endfunction()
# copy the `cocos_target` needed dlls into `COPY_TO` folder
function(cocos_copy_target_dll cocos_target)
set(oneValueArgs COPY_TO)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_target_depends_ext_dlls(${cocos_target} all_depend_dlls)
# remove repeat items
list(REMOVE_DUPLICATES all_depend_dlls)
message(STATUS "prepare to copy external dlls for ${cocos_target}:${all_depend_dlls}")
foreach(single_target_dll ${all_depend_dlls} )
add_custom_command(TARGET ${cocos_target} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${all_depend_dlls}
${opt_COPY_TO}
)
endforeach(single_target_dll)
endfunction()
# find dlls in a dir which `LIB_ABS_PATH` located, and save the result in `dlls_out`
function(cocos_find_dlls_for_lib dlls_out)
set(oneValueArgs LIB_ABS_PATH)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
get_filename_component(lib_dir ${opt_LIB_ABS_PATH} DIRECTORY)
file(GLOB lib_dir_files "${lib_dir}/*")
set(cc_dlls)
foreach(dir_file ${lib_dir_files})
if(${dir_file} MATCHES "dll$")
list(APPEND cc_dlls ${dir_file})
endif()
endforeach()
set(${dlls_out} ${cc_dlls} PARENT_SCOPE)
endfunction()
# mark `FILES` as resources, files will be put into sub-dir tree depend on its absolute path
function(cocos_mark_resources)
set(oneValueArgs BASEDIR RESOURCEBASE)
set(multiValueArgs FILES)
@ -65,7 +157,7 @@ function(cocos_mark_resources)
endforeach()
endfunction()
# mark the files in the sub dir of CMAKE_CURRENT_SOURCE_DIR
# mark the code sources of `cocos_target` into sub-dir tree
function(cocos_mark_code_files cocos_target)
set(oneValueArgs GROUPBASE)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@ -94,6 +186,96 @@ function(cocos_mark_code_files cocos_target)
endfunction()
# build a cocos application
# hrough compile the files `APP_SRC`, link the libs in `*LIBS`, use the packages in `*.PKGS`
# this method hide the link lib details, those is prebuilt libs or not
macro(cocos_build_app app_name)
set(multiValueArgs
APP_SRC
DEPEND_COMMON_LIBS
DEPEND_ANDROID_LIBS
COMMON_USE_PKGS
LINUX_USE_PKGS
DEPEND_MACOSX_LIBS
DEPEND_WINDOWS_LIBS
)
cmake_parse_arguments(opt "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(ANDROID)
add_library(${app_name} SHARED ${opt_APP_SRC})
foreach(android_lib ${opt_DEPEND_ANDROID_LIBS})
if(USE_COCOS_PREBUILT)
target_link_libraries(${app_name} -Wl,-whole-archive "${${_${android_lib}_prefix}_LIBRARIES}" -Wl,-no-whole-archive)
else()
target_link_libraries(${app_name} -Wl,-whole-archive ${android_lib} -Wl,-no-whole-archive)
add_dependencies(${app_name} ${android_lib})
endif()
endforeach()
else()
add_executable(${app_name} ${opt_APP_SRC})
endif()
# set target PROPERTIES, depend different platforms
if(APPLE)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
set_target_properties(${app_name} PROPERTIES MACOSX_BUNDLE 1
)
elseif(MSVC)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}/$<CONFIG>")
set(APP_RES_DIR "${APP_BIN_DIR}")
#Visual Studio Defaults to wrong type
set_target_properties(${app_name} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
else(LINUX)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}/${APP_NAME}")
set(APP_RES_DIR "${APP_BIN_DIR}/Resources")
endif()
set_target_properties(${app_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
if(MACOSX)
list(APPEND opt_DEPEND_COMMON_LIBS ${opt_DEPEND_MACOSX_LIBS})
elseif(WINDOWS)
list(APPEND opt_DEPEND_COMMON_LIBS ${opt_DEPEND_WINDOWS_LIBS})
endif()
# link commom libs, and common libs need external or system libs
if(USE_COCOS_PREBUILT)
include(CocosUseLibs)
foreach(common_lib ${opt_DEPEND_COMMON_LIBS})
message(STATUS "${app_name} prepare to link engine lib: ${common_lib}")
cocos_use_pkg(${app_name} ${_${common_lib}_prefix})
if(common_lib STREQUAL "cocos2d")
target_use_cocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "jscocos2d")
target_use_jscocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "luacocos2d")
target_use_luacocos2d_depend_libs(${app_name})
elseif(common_lib STREQUAL "simulator")
target_use_simulator_depend_libs(${app_name})
endif()
endforeach()
else()
foreach(common_lib ${opt_DEPEND_COMMON_LIBS})
target_link_libraries(${app_name} ${common_lib})
add_dependencies(${app_name} ${common_lib})
endforeach()
endif()
if(LINUX)
foreach(_pkg ${opt_LINUX_USE_PKGS})
cocos_use_pkg(${app_name} ${_pkg})
endforeach()
endif()
foreach(_pkg ${opt_COMMON_USE_PKGS})
cocos_use_pkg(${app_name} ${_pkg})
endforeach()
# auto mark code files for IDE when mark app
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()
# generate prebuilt auto when build app if GEN_COCOS_PREBUILT=ON
if(GEN_COCOS_PREBUILT)
add_dependencies(${APP_NAME} prebuilt)
endif()
endmacro()
# if cc_variable not set, then set it cc_value
macro(cocos_fake_set cc_variable cc_value)
if(NOT DEFINED ${cc_variable})
@ -101,7 +283,7 @@ macro(cocos_fake_set cc_variable cc_value)
endif()
endmacro()
# macos package, need review
# generate macOS app package infomations, need improve for example, the using of info.plist
macro(cocos_pak_xcode cocos_target)
set(oneValueArgs
INFO_PLIST
@ -149,12 +331,9 @@ macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
endmacro (set_xcode_property)
# cocos_find_package(pkg args...)
# works same as find_package, but do additional care to properly find
# prebuilt libs for cocos
# need review
macro(cocos_find_package pkg_name pkg_prefix)
if(NOT USE_EXTERNAL_PREBUILT_LIBS OR NOT ${pkg_prefix}_FOUND)
if(NOT USE_EXTERNAL_PREBUILT OR NOT ${pkg_prefix}_FOUND)
find_package(${pkg_name} ${ARGN})
endif()
if(NOT ${pkg_prefix}_INCLUDE_DIRS AND ${pkg_prefix}_INCLUDE_DIR)
@ -184,7 +363,7 @@ function(cocos_use_pkg target pkg)
endif()
if(_include_dirs)
include_directories(${_include_dirs})
message(STATUS "${pkg} add to include_dirs: ${_include_dirs}")
# message(STATUS "${pkg} add to include_dirs: ${_include_dirs}")
endif()
set(_library_dirs)
@ -193,7 +372,7 @@ function(cocos_use_pkg target pkg)
endif()
if(_library_dirs)
link_directories(${_library_dirs})
message(STATUS "${pkg} add to link_dirs: ${_library_dirs}")
# message(STATUS "${pkg} add to link_dirs: ${_library_dirs}")
endif()
set(_libs)
@ -205,7 +384,7 @@ function(cocos_use_pkg target pkg)
endif()
if(_libs)
target_link_libraries(${target} ${_libs})
message(STATUS "${pkg} libs added to '${target}': ${_libs}")
# message(STATUS "${pkg} libs added to '${target}': ${_libs}")
endif()
set(_defs)
@ -214,7 +393,28 @@ function(cocos_use_pkg target pkg)
endif()
if(_defs)
add_definitions(${_defs})
message(STATUS "${pkg} add definitions: ${_defs}")
# message(STATUS "${pkg} add definitions: ${_defs}")
endif()
set(_dlls)
if(NOT _dlls)
set(_dlls ${${prefix}_DLLS})
endif()
if(_dlls)
if(MSVC)
# message(STATUS "${target} add dll: ${_dlls}")
get_property(pre_dlls
TARGET ${target}
PROPERTY DEPEND_DLLS)
if(pre_dlls)
set(_dlls ${pre_dlls} ${_dlls})
endif()
set_property(TARGET ${target}
PROPERTY
DEPEND_DLLS ${_dlls}
)
endif()
endif()
endfunction()

View File

@ -6,6 +6,10 @@ if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
")
endif()
if(DEFINED CMAKE_TOOLCHAIN_FILE)
message(STATUS "using toolchain file: ${CMAKE_TOOLCHAIN_FILE}")
endif()
macro(CocosBuildSet)
# It ensures that when Find*.cmake files included from cmake's Modules dir
@ -26,37 +30,12 @@ macro(CocosBuildSet)
# some useful variables for every one cocos project
set(COCOS_EXTERNAL_DIR ${COCOS2DX_ROOT_PATH}/external)
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)
set(COCOS_PREBUILT_LIBS_PATH ${COCOS2DX_ROOT_PATH}/prebuilt)
message(STATUS "COCOS2DX_ROOT_PATH:" ${COCOS2DX_ROOT_PATH})
message(STATUS "CMAKE_MODULE_PATH:" ${CMAKE_MODULE_PATH})
message(STATUS "COCOS_EXTERNAL_DIR:" ${COCOS_EXTERNAL_DIR})
message(STATUS "ENGINE_BINARY_PATH:" ${ENGINE_BINARY_PATH})
# architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_DIR "64-bit")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_DIR "32-bit")
else()
message(WARN "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}")
endif()
# CMAKE_BUILD_TYPE has precedence over DEBUG_MODE
# Still supporting DEBUG_MODE for backwards compatibility
if(NOT CMAKE_BUILD_TYPE)
if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE DEBUG)
else(DEBUG_MODE)
set(CMAKE_BUILD_TYPE RELEASE)
endif(DEBUG_MODE)
endif(NOT CMAKE_BUILD_TYPE)
# Define other useful variables not defined by CMake
if(CMAKE_GENERATOR STREQUAL Xcode)
set (XCODE TRUE)
elseif(CMAKE_GENERATOR MATCHES Visual)
set (VS TRUE)
endif()
include(CocosBuildHelpers)
@ -68,15 +47,12 @@ macro(CocosBuildSet)
include(SetCompilerOptions)
SetCompilerOptions()
if(CMAKE_FIND_ROOT_PATH AND USE_EXTERNAL_PREBUILT_LIBS)
# Adds cocos2d-x external folder to the list of valid include/library paths when cross-compiling and using prebuilds
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${COCOS_EXTERNAL_DIR})
endif()
if(USE_EXTERNAL_PREBUILT_LIBS)
include(CocosUsePrebuiltLibs)
# collect prebuilt libraries
if(USE_EXTERNAL_PREBUILT OR USE_COCOS_PREBUILT)
include(CocosPickLibs)
endif()
# compile source libraries, find prebuilt package
include(BuildModules)
BuildModules()
endmacro(CocosBuildSet)

View File

@ -1,15 +1,21 @@
# CocosUsePrebuiltLibs - sets external libs variables to link with
# CocosPickLibs - sets external libs variables to link with
# START CONFIG
# record all the prebuilt libs which found for specific platform
set(COCOS_EXTERNAL_LIBS)
# lib location is Debug folder or release folder
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_FOLDER)
set(_chipmunk_inc chipmunk/chipmunk.h)
set(_chipmunk_inc_paths include)
if(WINDOWS)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
set(_chipmunk_libs chipmunk libchipmunk-2015)
if (MSVC)
set(_chipmunk_libs chipmunk libchipmunk libchipmunk-2015)
else()
set(_chipmunk_libs chipmunk libchipmunk)
endif(${MSVC_VERSION})
endif()
else()
set(_chipmunk_libs chipmunk libchipmunk)
endif(WINDOWS)
@ -18,6 +24,9 @@ set(_bullet_inc bullet/Bullet-C-Api.h BulletCollision/btBulletCollisionCommon.h)
set(_bullet_inc_paths bullet)
# sequence is important
set(_bullet_libs BulletDynamics libBulletDynamics BulletCollision libBulletCollision BulletMultiThreaded libBulletMultiThreaded LinearMath libLinearMath MiniCL libMiniCL)
if (MSVC)
set(_bullet_libs bullet libbullet)
endif()
set(_Box2D_inc Box2D/Box2D.h)
set(_Box2D_inc_paths include)
@ -38,33 +47,33 @@ set(_freetype2_libs freetype freetype250)
set(_jpeg_inc jpeglib.h)
if(WINDOWS)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
set(_jpeg_libs jpeg libjpeg-2015)
if (MSVC)
set(_jpeg_libs jpeg libjpeg libjpeg-2015)
else()
set(_jpeg_libs jpeg libjpeg)
endif(${MSVC_VERSION})
endif()
else()
set(_jpeg_libs jpeg libjpeg)
endif(WINDOWS)
set(_png_inc png.h)
if(WINDOWS)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
set(_png_libs png libpng-2015)
if (MSVC)
set(_png_libs png libpng libpng-2015)
else()
set(_png_libs png libpng)
endif(${MSVC_VERSION})
endif()
else()
set(_png_libs png libpng)
endif(WINDOWS)
set(_tiff_inc tiff.h)
if(WINDOWS)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
set(_tiff_libs tiff libtiff-2015)
if (MSVC)
set(_tiff_libs tiff libtiff libtiff-2015)
else()
set(_tiff_libs tiff libtiff)
endif(${MSVC_VERSION})
endif()
else()
set(_tiff_libs tiff libtiff)
endif(WINDOWS)
@ -77,17 +86,9 @@ set(_websockets_libs websockets libwebsockets)
set(_openssl_inc openssl/ssl.h)
set(_openssl_libs ssl crypto)
set(_glfw3_inc glfw3.h)
if(WINDOWS)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
set(_glfw3_libs glfw3-2015 libglfw3)
else()
set(_glfw3_libs glfw3 libglfw3)
endif(${MSVC_VERSION})
else()
set(_glfw3_libs glfw3 libglfw3)
endif(WINDOWS)
if (MSVC)
set(_openssl_libs ssl crypto libssl libcrypto)
endif()
set(_sqlite3_inc sqlite3.h)
set(_sqlite3_libs sqlite3)
@ -116,6 +117,12 @@ set(_OpenalSoft_libs OpenAL32)
set(_zlib_inc zlib.h)
set(_zlib_libs z libzlib libz)
if (MSVC)
set(_zlib_libs libzlib)
# zlib's dll is so special, lib name and dll name is different
# single special
set(_zlib_dll zlib1)
endif()
set(_fmod_prefix FMOD)
set(_fmod_inc fmod.hpp)
@ -124,6 +131,16 @@ set(_fmod_libs fmod fmod64 fmod fmod64)
set(_luajit_prefix LUAJIT)
set(_luajit_inc lua.hpp)
set(_luajit_libs luajit)
if (MSVC)
set(_luajit_libs lua51)
endif()
set(_spidermonkey_prefix SPIDERMONKEY)
set(_spidermonkey_inc jsapi.h)
set(_spidermonkey_libs js_static)
if (MSVC)
set(_spidermonkey_libs mozjs-33)
endif()
set(all_prebuilt_libs
chipmunk
@ -138,6 +155,7 @@ set(all_prebuilt_libs
bullet
Box2D
luajit
spidermonkey
)
@ -166,6 +184,7 @@ foreach(_lib ${all_prebuilt_libs})
else()
# auto-prefix is uppercased name
string(TOUPPER ${_lib} _prefix)
set(_${_lib}_prefix ${_prefix})
endif()
set(roots
@ -202,40 +221,88 @@ foreach(_lib ${all_prebuilt_libs})
endforeach()
if(include_dirs)
set(${_prefix}_INCLUDE_DIRS ${include_dirs} CACHE PATH "Path to includes for ${_prefix}" FORCE)
endif()
message(STATUS "${_lib} ${_prefix}_INCLUDE_DIRS: ${${_prefix}_INCLUDE_DIRS}")
message(STATUS "${_lib} ${_prefix}_INCLUDE_DIRS: ${${_prefix}_INCLUDE_DIRS}")
# don't find lib, if not find include in once ${_root} search
set(lib_dir_candidates
${_root}/prebuilt/${PLATFORM_FOLDER}
${_root}/prebuilt/${PLATFORM_FOLDER}/${BUILD_TYPE_FOLDER}
${_root}/prebuilt/${PLATFORM_FOLDER}/${BUILD_TYPE_FOLDER}-lib
${_root}/libraries/${PLATFORM_FOLDER}
${_root}/prebuilt
)
if(ANDROID_ABI)
list(APPEND lib_dir_candidates ${_root}/prebuilt/${PLATFORM_FOLDER}/${ANDROID_ABI})
endif()
if(ARCH_DIR)
list(APPEND lib_dir_candidates ${_root}/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR})
list(APPEND lib_dir_candidates ${_root}/prebuilt/${ARCH_DIR})
endif()
set(libs)
set(dlls)
foreach(_dir ${lib_dir_candidates})
if(EXISTS ${_dir})
# find all libs
foreach(_lib_name ${_${_lib}_libs})
find_library(_lib_tmp ${_lib_name} PATHS ${_dir} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
if(_lib_tmp)
list(APPEND libs ${_lib_tmp})
#find dlls for _lib_tmp
if(MSVC)
cocos_find_dlls_for_lib(_dll_tmp LIB_ABS_PATH ${_lib_tmp})
endif()
list(APPEND dlls ${_dll_tmp})
unset(_dll_tmp CACHE)
endif()
unset(_lib_tmp CACHE)
endforeach()
endif(EXISTS ${_dir})
endforeach()
set(lib_dir_candidates
${_root}/prebuilt/${PLATFORM_FOLDER}/${ANDROID_ABI}
${_root}/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
${_root}/prebuilt/${PLATFORM_FOLDER}
${_root}/prebuilt/${PLATFORM_FOLDER}/release-lib
${_root}/prebuilt/${ARCH_DIR}
${_root}/libraries/${PLATFORM_FOLDER}
${_root}/prebuilt
)
set(libs)
foreach(_dir ${lib_dir_candidates})
if(EXISTS ${_dir})
# find all libs
foreach(_lib_name ${_${_lib}_libs})
unset(_lib_tmp CACHE)
find_library(_lib_tmp ${_lib_name} PATHS ${_dir} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
if(_lib_tmp)
list(APPEND libs ${_lib_tmp})
endif()
endforeach()
endif(EXISTS ${_dir})
endforeach()
if(libs)
set(${_prefix}_LIBRARIES ${libs} CACHE STRING "Libraries to link for ${_prefix}" FORCE)
if(libs)
set(${_prefix}_LIBRARIES ${libs} CACHE STRING "Libraries to link for ${_prefix}" FORCE)
message(STATUS "${_lib} ${_prefix}_LIBRARIES: ${${_prefix}_LIBRARIES}")
endif()
if(MSVC)
if(dlls)
# remove repeat items
list(REMOVE_DUPLICATES dlls)
# set dlls into var ${_prefix}_DLLS
set(${_prefix}_DLLS ${dlls} CACHE STRING "dlls to link for ${_prefix}" FORCE)
message(STATUS "${_lib} ${_prefix}_DLLS: ${${_prefix}_DLLS}")
endif(dlls)
endif()
if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS)
set(${_prefix}_FOUND YES)
list(APPEND COCOS_EXTERNAL_LIBS ${${_prefix}_LIBRARIES})
endif()
endif()
message(STATUS "${_lib} ${_prefix}_LIBRARIES: ${${_prefix}_LIBRARIES}")
if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS)
set(${_prefix}_FOUND YES)
endif()
endif(EXISTS ${_root})
endforeach()
endforeach()
# use engine prebuilt libs, try to pick all engine libs
if(USE_COCOS_PREBUILT)
# cocos2d/jscocos2d/luacocos2d
set(_cocos2d_prefix COCOS2D)
cocos_find_prebuilt_lib_by_name(cocos2d COCOS2D_LIBRARIES)
set(_jscocos2d_prefix JSCOCOS2D)
cocos_find_prebuilt_lib_by_name(jscocos2d JSCOCOS2D_LIBRARIES)
set(_luacocos2d_prefix LUACOCOS2D)
cocos_find_prebuilt_lib_by_name(luacocos2d LUACOCOS2D_LIBRARIES)
set(_simulator_prefix SIMULATOR)
cocos_find_prebuilt_lib_by_name(simulator SIMULATOR_LIBRARIES)
if(ANDROID)
set(_cocos2d_android_prefix ANDROID_COCOS2D)
cocos_find_prebuilt_lib_by_name(cocos2d_android ANDROID_COCOS2D_LIBRARIES)
endif()
endif(USE_COCOS_PREBUILT)

View File

@ -0,0 +1,211 @@
macro(cocos2d_depend_libs)
# confim the libs, prepare to link
set(PLATFORM_SPECIFIC_LIBS)
# confim the prebuilt libs, prepare to use
set(PREBUILT_SPECIFIC_LIBS)
if(WINDOWS)
foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL SQLITE3)
list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
endforeach()
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm Version Iphlpapi)
if(MINGW)
list(APPEND PLATFORM_SPECIFIC_LIBS shlwapi version)
endif()
elseif(LINUX)
# need review those libs: X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m
list(APPEND PLATFORM_SPECIFIC_LIBS dl X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m)
foreach(_pkg OPENGL GLEW GLFW3 FMOD FONTCONFIG THREADS GTK3)
list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
endforeach()
elseif(ANDROID)
list(APPEND PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
list(APPEND PREBUILT_SPECIFIC_LIBS TREMOLO PVMP3DEC CPUFEATURES)
elseif(APPLE)
include_directories(/System/Library/Frameworks)
find_library(ICONV_LIBRARY iconv)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
find_library(FOUNDATION_LIBRARY Foundation)
find_library(OPENAL_LIBRARY OpenAL )
find_library(QUARTZCORE_LIBRARY QuartzCore )
set(COCOS_APPLE_LIBS
${OPENAL_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
${QUARTZCORE_LIBRARY}
${FOUNDATION_LIBRARY}
${ICONV_LIBRARY}
)
if(MACOSX)
list(APPEND PREBUILT_SPECIFIC_LIBS GLFW3)
find_library(COCOA_LIBRARY Cocoa)
find_library(OPENGL_LIBRARY OpenGL )
find_library(APPLICATIONSERVICES_LIBRARY ApplicationServices)
find_library(IOKIT_LIBRARY IOKit)
list(APPEND PLATFORM_SPECIFIC_LIBS
${COCOA_LIBRARY}
${OPENGL_LIBRARY}
${APPLICATIONSERVICES_LIBRARY}
${IOKIT_LIBRARY}
${COCOS_APPLE_LIBS}
)
elseif(IOS)
# Locate system libraries on iOS
find_library(UIKIT_LIBRARY UIKit)
find_library(OPENGLES_LIBRARY OpenGLES )
find_library(CORE_MOTION_LIBRARY CoreMotion)
find_library(MEDIA_PLAYER_LIBRARY MediaPlayer)
find_library(CORE_TEXT_LIBRARY CoreText)
find_library(SECURITY_LIBRARY Security)
find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
find_library(AV_FOUNDATION_LIBRARY AVFoundation)
find_library(Z_LIBRARY z)
list(APPEND PLATFORM_SPECIFIC_LIBS
${UIKIT_LIBRARY}
${OPENGLES_LIBRARY}
${CORE_MOTION_LIBRARY}
${MEDIA_PLAYER_LIBRARY}
${CORE_TEXT_LIBRARY}
${SECURITY_LIBRARY}
${CORE_GRAPHICS_LIBRARY}
${AV_FOUNDATION_LIBRARY}
${Z_LIBRARY}
${COCOS_APPLE_LIBS}
)
endif()
else()
message(FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
foreach(_pkg ZLIB MINIZIP TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
list(APPEND PREBUILT_SPECIFIC_LIBS ${_pkg})
endforeach()
if(NOT EMSCRIPTEN)
list(APPEND PREBUILT_SPECIFIC_LIBS OPENSSL)
endif()
if(USE_JPEG)
add_definitions(-DCC_USE_JPEG=1)
list(APPEND PREBUILT_SPECIFIC_LIBS JPEG)
else()
add_definitions(-DCC_USE_JPEG=0)
endif()
if(USE_WEBP)
add_definitions(-DCC_USE_WEBP=1)
list(APPEND PREBUILT_SPECIFIC_LIBS WEBP)
else()
add_definitions(-DCC_USE_WEBP=0)
endif()
if(USE_TIFF)
add_definitions(-DCC_USE_TIFF=1)
list(APPEND PREBUILT_SPECIFIC_LIBS TIFF)
else()
add_definitions(-DCC_USE_TIFF=0)
endif()
if(USE_PNG)
add_definitions(-DCC_USE_PNG=1)
list(APPEND PREBUILT_SPECIFIC_LIBS PNG)
else()
add_definitions(-DCC_USE_PNG=0)
endif()
if(USE_CHIPMUNK)
list(APPEND PREBUILT_SPECIFIC_LIBS CHIPMUNK)
endif()
if(USE_BOX2D)
list(APPEND PREBUILT_SPECIFIC_LIBS Box2D)
endif()
if(USE_BULLET)
list(APPEND PREBUILT_SPECIFIC_LIBS BULLET)
endif()
if(USE_RECAST)
list(APPEND PREBUILT_SPECIFIC_LIBS RECAST)
endif()
endmacro()
macro(target_use_cocos2d_depend_libs target)
cocos2d_depend_libs()
message(STATUS "${target} prepare to use cpp needed libs: ${PREBUILT_SPECIFIC_LIBS}")
# message(STATUS "${target} prepare to link cpp needed libs: ${PLATFORM_SPECIFIC_LIBS}")
foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
cocos_use_pkg(${target} ${prebuilt_lib})
endforeach()
foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(${target} ${platform_lib})
endforeach()
endmacro()
macro(jscocos2d_depend_libs)
set(PLATFORM_SPECIFIC_LIBS)
set(PREBUILT_SPECIFIC_LIBS)
list(APPEND PREBUILT_SPECIFIC_LIBS SPIDERMONKEY SQLITE3)
if(APPLE)
find_library(GAME_CONTROLLER GameController)
list(APPEND PLATFORM_SPECIFIC_LIBS ${GAME_CONTROLLER})
endif()
endmacro()
macro(target_use_jscocos2d_depend_libs target)
jscocos2d_depend_libs()
message(STATUS "${target} prepare to use js needed libs: ${PREBUILT_SPECIFIC_LIBS}")
# message(STATUS "${target} prepare to link js needed libs: ${PLATFORM_SPECIFIC_LIBS}")
foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
cocos_use_pkg(${target} ${prebuilt_lib})
endforeach()
foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(${target} ${platform_lib})
endforeach()
endmacro()
macro(luacocos2d_depend_libs)
set(PLATFORM_SPECIFIC_LIBS)
set(PREBUILT_SPECIFIC_LIBS)
list(APPEND PREBUILT_SPECIFIC_LIBS LUAJIT)
endmacro()
macro(target_use_luacocos2d_depend_libs target)
luacocos2d_depend_libs()
message(STATUS "${target} prepare to use lua needed libs: ${PREBUILT_SPECIFIC_LIBS}")
# message(STATUS "${target} prepare to link lua needed libs: ${PLATFORM_SPECIFIC_LIBS}")
foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
cocos_use_pkg(${target} ${prebuilt_lib})
endforeach()
foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(${target} ${platform_lib})
endforeach()
endmacro()
macro(simulator_depend_libs)
set(PLATFORM_SPECIFIC_LIBS)
set(PREBUILT_SPECIFIC_LIBS)
if(MACOSX)
include_directories(/System/Library/Frameworks)
find_library(APPKIT_LIBRARY AppKit)
list(APPEND PLATFORM_SPECIFIC_LIBS ${APPKIT_LIBRARY})
elseif(WINDOWS)
list(APPEND PREBUILT_SPECIFIC_LIBS TinyXML2 CURL)
endif()
endmacro()
macro(target_use_simulator_depend_libs target)
simulator_depend_libs()
message(STATUS "${target} prepare to use simulator needed libs: ${PREBUILT_SPECIFIC_LIBS}")
# message(STATUS "${target} prepare to link simulator needed libs: ${PLATFORM_SPECIFIC_LIBS}")
foreach(prebuilt_lib ${PREBUILT_SPECIFIC_LIBS})
cocos_use_pkg(${target} ${prebuilt_lib})
endforeach()
foreach(platform_lib ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(${target} ${platform_lib})
endforeach()
endmacro()

View File

@ -6,18 +6,18 @@ macro (SelectModule)
set(USE_WEBP_DEFAULT OFF)
endif()
set(USE_PREBUILT_LIBS_DEFAULT ON)
set(USE_EXTERNAL_PREBUILT_DEFAULT ON)
if(MINGW)
set(USE_PREBUILT_LIBS_DEFAULT OFF)
set(USE_EXTERNAL_PREBUILT_DEFAULT OFF)
endif()
# opition for using cocos prebuild lib, not done
set(USE_COCOS_PREBUILT_LIBS_DEFAULT OFF)
set(GEN_COCOS_PREBUILT_DEFAULT OFF)
set(USE_COCOS_PREBUILT_DEFAULT OFF)
set(BUILD_LUA_LIBS_DEFAULT OFF)
set(BUILD_JS_LIBS_DEFAULT OFF)
set(USE_SOURCES_EXTERNAL_DEFAULT OFF)
set(USE_EXTERNAL_SOURCES_DEFAULT OFF)
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
@ -28,7 +28,7 @@ macro (SelectModule)
option(USE_TIFF "Use TIFF codec" ON)
option(USE_JPEG "Use JPEG codec" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(DEBUG_MODE "Debug or release?" ON)
option(DEBUG_MODE "Debug or Release?" ON)
option(BUILD_EXTENSIONS "Build extension library" ON)
option(BUILD_EDITOR_SPINE "Build editor support for spine" ON)
option(BUILD_EDITOR_COCOSTUDIO "Build editor support for cocostudio" ON)
@ -36,12 +36,12 @@ macro (SelectModule)
option(BUILD_BOX2D "Build box2d external without using it for physics library" OFF)
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_JS_LIBS "Build js libraries" ${BUILD_JS_LIBS_DEFAULT})
# need review
option(USE_EXTERNAL_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
option(USE_COCOS_PREBUILT_LIBS "use cocos static libraries, return error if not find" ${USE_COCOS_PREBUILT_LIBS_DEFAULT})
option(USE_SOURCES_EXTERNAL "Use sources in external directory (automatically ON when USE_EXTERNAL_PREBUILT_LIBS is ON)" ${USE_SOURCES_EXTERNAL_DEFAULT})
option(USE_EXTERNAL_PREBUILT "Use prebuilt libraries in external directory" ${USE_EXTERNAL_PREBUILT_DEFAULT})
option(GEN_COCOS_PREBUILT "generate cocos static libraries, put libraries into prebuilt folder in cocos root" ${GEN_COCOS_PREBUILT_DEFAULT})
option(USE_COCOS_PREBUILT "use cocos static libraries, return warning if not find" ${USE_COCOS_PREBUILT_DEFAULT})
option(USE_EXTERNAL_SOURCES "Use sources in external directory (automatically ON when USE_EXTERNAL_PREBUILT is ON)" ${USE_EXTERNAL_SOURCES_DEFAULT})
if(USE_EXTERNAL_PREBUILT_LIBS AND MINGW)
if(USE_EXTERNAL_PREBUILT AND MINGW)
message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.")
return()
endif()

View File

@ -1,191 +1,280 @@
macro (SetCompilerOptions)
#cmake has some strange defaults, this should help us a lot
#Please use them everywhere
#WINDOWS = Windows Desktop
#WINRT = Windows RT
#WP8 = Windows Phone 8
#ANDROID = Android
#IOS = iOS
#MACOSX = MacOS X
#LINUX = Linux
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(WINRT)
set(SYSTEM_STRING "Windows RT")
elseif(WP8)
set(SYSTEM_STRING "Windows Phone 8")
else()
set(WINDOWS TRUE)
set(SYSTEM_STRING "Windows Desktop")
endif()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(SYSTEM_STRING "Android")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(ANDROID)
set(SYSTEM_STRING "Android")
else()
set(LINUX TRUE)
set(SYSTEM_STRING "Linux")
endif()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(IOS)
set(APPLE TRUE)
set(SYSTEM_STRING "IOS")
else()
set(APPLE TRUE)
set(MACOSX TRUE)
set(SYSTEM_STRING "Mac OSX")
endif()
endif()
#cmake has some strange defaults, this should help us a lot
#Please use them everywhere
#WINDOWS = Windows Desktop
#WINRT = Windows RT
#WP8 = Windows Phone 8
#ANDROID = Android
#IOS = iOS
#MACOSX = MacOS X
#LINUX = Linux
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if(WINRT)
set(SYSTEM_STRING "Windows RT")
elseif(WP8)
set(SYSTEM_STRING "Windows Phone 8")
else()
set(WINDOWS TRUE)
set(SYSTEM_STRING "Windows Desktop")
endif()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(SYSTEM_STRING "Android")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(ANDROID)
set(SYSTEM_STRING "Android")
else()
set(LINUX TRUE)
set(SYSTEM_STRING "Linux")
endif()
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(IOS)
set(APPLE TRUE)
set(SYSTEM_STRING "IOS")
else()
set(APPLE TRUE)
set(MACOSX TRUE)
set(SYSTEM_STRING "Mac OSX")
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(COMPILER_STRING ${CMAKE_CXX_COMPILER_ID})
set(CLANG TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(MINGW)
set(COMPILER_STRING "Mingw GCC")
else()
set(COMPILER_STRING "GCC")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} C++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(COMPILER_STRING "Visual Studio C++")
endif()
if(CMAKE_GENERATOR STREQUAL Xcode)
set (XCODE TRUE)
elseif(CMAKE_GENERATOR MATCHES Visual)
set (VS TRUE)
endif()
#Debug is default value
if(NOT CMAKE_BUILD_TYPE)
if(DEBUG_MODE)
set(CMAKE_BUILD_TYPE Debug)
else()
set(CMAKE_BUILD_TYPE Release)
endif()
endif()
# make configurations type keep same to cmake build type. prevent use generate debug project but switch release mode in IDE
if(CMAKE_GENERATOR)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}" CACHE STRING "Reset the configurations to what we need" FORCE)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
if(CMAKE_CROSSCOMPILING)
set(BUILDING_STRING "It appears you are cross compiling for ${SYSTEM_STRING} with ${COMPILER_STRING}")
else()
set(BUILDING_STRING "It appears you are building natively for ${SYSTEM_STRING} with ${COMPILER_STRING}")
endif()
# architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_DIR "64-bit")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(ARCH_DIR "32-bit")
else()
message(WARN "CMAKE_SIZEOF_VOID_P: ${CMAKE_SIZEOF_VOID_P}")
endif()
message(STATUS ${BUILDING_STRING})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(COMPILER_STRING ${CMAKE_CXX_COMPILER_ID})
set(CLANG TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(MINGW)
set(COMPILER_STRING "Mingw GCC")
else()
set(COMPILER_STRING "GCC")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} C++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(COMPILER_STRING "Visual Studio C++")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
if(CMAKE_CROSSCOMPILING)
set(BUILDING_STRING "It appears you are cross compiling for ${SYSTEM_STRING} with ${COMPILER_STRING}")
else()
set(BUILDING_STRING "It appears you are building natively for ${SYSTEM_STRING} with ${COMPILER_STRING}")
endif()
message(STATUS ${BUILDING_STRING})
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
# definitions for chipmunk
if (USE_CHIPMUNK)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
if (IOS OR MACOSX)
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
if (USE_CHIPMUNK)
add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1)
if (IOS OR MACOSX)
# without this chipmunk will try to use apple defined geometry types, that conflicts with cocos
add_definitions(-DCP_USE_CGPOINTS=0)
endif()
else()
add_definitions(-DCC_USE_PHYSICS=0)
endif()
endif()
else()
add_definitions(-DCC_USE_PHYSICS=0)
endif()
# definitions for box2d
if (USE_BOX2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif()
if (USE_BOX2D)
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1)
else()
add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0)
endif()
# definitions for bullet
if (USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
if (USE_BULLET)
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=1)
add_definitions(-DCC_USE_3D_PHYSICS=1)
else()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
else()
add_definitions(-DCC_ENABLE_BULLET_INTEGRATION=0)
add_definitions(-DCC_USE_3D_PHYSICS=0)
endif()
endif()
# definitions for recast
if (USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=1)
else()
add_definitions(-DCC_USE_NAVMESH=0)
endif()
if (USE_RECAST)
add_definitions(-DCC_USE_NAVMESH=1)
else()
add_definitions(-DCC_USE_NAVMESH=0)
endif()
# Compiler options
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:msvcrt /NODEFAULTLIB:libcmt")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:libcmt")
endif()
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
# Compiler options
if(MSVC)
# Use inline debug info (/Z7) format. Or internal error may occur.
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
foreach(lang C CXX)
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
endforeach()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} /MDd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /MD")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt /NODEFAULTLIB:libcmt")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmt")
else()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DCOCOS2D_DEBUG=1)
endif()
set(CMAKE_C_FLAGS_DEBUG "-g -Wall")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder -Wno-invalid-offsetof -fPIC")
if(CLANG AND NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(CLANG AND ANDROID AND ANDROID_ARM_MODE STREQUAL thumb AND ANDROID_ABI STREQUAL armeabi)
string(REPLACE "-mthumb" "-marm" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-mthumb" "-marm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
endif(MSVC)
add_definitions(-DUNICODE -D_UNICODE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
# multi thread compile option
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
# Use inline Debug info (/Z7) format. Or internal error may occur.
# Errors looks like: "xmemory0(592): error C3130: Internal Compiler Error: failed to write injected code block to PDB"
foreach(lang C CXX)
string(REGEX REPLACE "/Z[iI7]" "" CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG}")
set(CMAKE_${lang}_FLAGS_DEBUG "${CMAKE_${lang}_FLAGS_DEBUG} /Z7")
endforeach()
# Some macro definitions
if(WINDOWS)
else()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DCOCOS2D_DEBUG=1)
endif()
set(CMAKE_C_FLAGS_DEBUG "-g -Wall")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-deprecated-declarations -Wno-reorder -Wno-invalid-offsetof -fPIC")
if(CLANG AND NOT ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
if(CLANG AND ANDROID AND ANDROID_ARM_MODE STREQUAL thumb AND ANDROID_ABI STREQUAL armeabi)
string(REPLACE "-mthumb" "-marm" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-mthumb" "-marm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
endif(MSVC)
if(BUILD_SHARED_LIBS)
add_definitions(-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
else()
add_definitions(-DCC_STATIC)
endif()
# Some macro definitions
if(WINDOWS)
add_definitions(-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
set(PLATFORM_FOLDER win32)
elseif(APPLE)
add_definitions(-DUSE_FILE32API)
if(MACOSX)
add_definitions(-DTARGET_OS_MAC)
set(PLATFORM_FOLDER mac)
elseif(IOS)
# TARGET_OS_IOS
# add_definitions(-DTARGET_OS_IPHONE)
add_definitions(-DTARGET_OS_IOS)
set(PLATFORM_FOLDER ios)
endif(MACOSX)
if(BUILD_SHARED_LIBS)
add_definitions(-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL)
else()
add_definitions(-DCC_STATIC)
endif()
elseif(LINUX)
add_definitions(-DLINUX)
set(PLATFORM_FOLDER linux)
elseif(ANDROID)
add_definitions(-DUSE_FILE32API)
set(PLATFORM_FOLDER android)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -fexceptions")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -latomic")
if(CLANG AND ANDROID_ARM_MODE STREQUAL thumb AND ANDROID_ABI STREQUAL armeabi)
add_definitions(-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32)
set(PLATFORM_FOLDER win32)
elseif(APPLE)
add_definitions(-DUSE_FILE32API)
if(MACOSX)
add_definitions(-DTARGET_OS_MAC)
set(PLATFORM_FOLDER mac)
elseif(IOS)
# TARGET_OS_IOS
# add_definitions(-DTARGET_OS_IPHONE)
add_definitions(-DTARGET_OS_IOS)
set(PLATFORM_FOLDER ios)
endif(MACOSX)
elseif(LINUX)
add_definitions(-DLINUX)
set(PLATFORM_FOLDER linux)
elseif(ANDROID)
add_definitions(-DUSE_FILE32API)
set(PLATFORM_FOLDER android)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -fexceptions")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} -latomic")
if(CLANG AND ANDROID_ARM_MODE STREQUAL thumb AND ANDROID_ABI STREQUAL armeabi)
string(REPLACE "-mthumb" "-marm" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
string(REPLACE "-mthumb" "-marm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
endif()
endif()
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
return()
endif()
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
return()
endif()
if(MINGW)
add_definitions(-DGLEW_STATIC)
add_definitions(-DCURL_STATICLIB)
add_definitions(-DAL_LIBTYPE_STATIC)
add_definitions(-D__SSIZE_T)
if(MINGW)
add_definitions(-DGLEW_STATIC)
add_definitions(-DCURL_STATICLIB)
add_definitions(-DAL_LIBTYPE_STATIC)
add_definitions(-D__SSIZE_T)
if(CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
endif()
endif()
if(CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
endif()
endif()
if(CMAKE_FIND_ROOT_PATH AND USE_EXTERNAL_PREBUILT)
# Adds cocos2d-x external folder to the list of valid include/library paths when cross-compiling and using prebuilds
set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${COCOS_EXTERNAL_DIR})
endif()
if(WINDOWS)
# folder much targets
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# not support other compile tools except MSVC for now
if(MSVC)
if (${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
message(STATUS "using Windows MSVC generate cocos2d-x project, MSVC_VERSION:${MSVC_VERSION} check pass")
else()
message(FATAL_ERROR "using Windows MSVC generate cocos2d-x project, MSVC_VERSION:${MSVC_VERSION} too low" )
endif()
define_property(TARGET
PROPERTY DEPEND_DLLS
BRIEF_DOCS "depend dlls of a target"
FULL_DOCS "use to save depend dlls of a target"
)
else()
message(FATAL_ERROR "please using Windows MSVC compile cocos2d-x project, support other compile tools not yet" )
endif()
endif()
# check use prebuilt config
if(GEN_COCOS_PREBUILT AND USE_COCOS_PREBUILT)
message(FATAL_ERROR "can't generate prebuilt libs and use prebuilt libs at the same time" )
endif()
if(GEN_COCOS_PREBUILT OR USE_COCOS_PREBUILT)
if(DEFINED COCOS_PREBUILT_ROOT)
message(STATUS "pre-defined COCOS_PREBUILT_ROOT: ${COCOS_PREBUILT_ROOT}")
else()
# the default prebuilt path is cocos2d-x/prebuilt
set(COCOS_PREBUILT_ROOT $ENV{COCOS_TEMPLATES_ROOT}/../prebuilt)
endif()
if(NOT IS_DIRECTORY ${COCOS_PREBUILT_ROOT})
message(STATUS "prebuilt root directory defined but not existed, create: ${COCOS_PREBUILT_ROOT}")
file(MAKE_DIRECTORY ${COCOS_PREBUILT_ROOT})
endif()
if(IS_DIRECTORY ${COCOS_PREBUILT_ROOT})
# prebuilt libs path
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER}/${CMAKE_BUILD_TYPE})
if(XCODE OR VS)
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER})
endif()
if(ANDROID)
set(COCOS_PREBUILT_PATH ${COCOS_PREBUILT_ROOT}/${PLATFORM_FOLDER}/${ANDROID_ABI})
endif()
message(STATUS "COCOS_PREBUILT_PATH:" ${COCOS_PREBUILT_PATH})
else()
if(ANDROID)
message(WARNING "using cmake in Android Studio, can't get value of environment variable, please define COCOS_PREBUILT_ROOT manually" )
endif()
message(FATAL_ERROR "can't find prebuilt libs location" )
endif()
endif()
endmacro (SetCompilerOptions)

View File

@ -1,33 +1,96 @@
## CMake Build Instructions
# CMake
Depending on your host system your Generator flag -G may be different
CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.
Typical -G options
For using gcc and clang from a makefile
### Links
msys2 = "MSYS Makefiles"
windows = "MinGW Makefiles"
nix and mac = "Unix Makefiles"
* Official website: [cmake.org](https://cmake.org/)
For using and editor such as Visual Studio or xcode there are different flags
* Documentation: [cmake.org/documentation](https://cmake.org/documentation/)
To like all available flags for your system run
* CMake FAQ: [Wiki/CMake_FAQ](https://cmake.org/Wiki/CMake_FAQ)
cmake --help
## CMake in Cocos2d-x
1. CMake in Cocos2d-x support platform iOS, Android, macOS, Linux, Win32.
### Build Examples
1. Open your terminal, input `cmake --version`, if the cmake version is lower than 3.1, please upgrade
#### using CMake in macOS terminal
2. You should use out-of-source build, that is said you need to create a different directory from `$cocos2dx_root` to execute cmake command.
## Build Options
### CMake Common
1. __`-G`__, generate native build project you specified, for example
* `-GXcode` generate Xcode project files.
* `-GVisual Studio 15 2017` generate Visual Studio 2017 project, the default toolset is v141, add `-T` option to specify toolset, like this `-Tv140`
1. __`CMAKE_BUILD_TYPE`__, specify the build mode, Debug or Release
* `-DCMAKE_BUILD_TYPE=Release` to generate the Release mode project, the default build mode is Debug
1. __`-H -B`__, `-H` specify the CMake project Home directory, `-B` specify CMake-generated project binary directory. for example
* `-H..\cocos2d-x -Bmsvc_build` the generated native project's location will be `msvc_build` directory.
1. __`--build <dir>`__, build a CMake-generated project binary tree, for example
* `cmake --build ./msvc_build`, cmake will sellect corresponding build tools.
### Cocos2d-x Options
1. __`GEN_COCOS_PREBUILT`__, control the project have the feature to generate pre-build libraries or not. Default value is `OFF`
* `-DGEN_COCOS_PREBUILT=ON`, will add target prebuilt, build this target will generate prebuilt libraries
1. __`USE_COCOS_PREBUILT`__, control the project have the feature to use pre-build libraries or not. Default value is `OFF`
* `-DUSE_COCOS_PREBUILT=ON`, will disable libraries target, and make app target use prebuilt libraries
1. __`COCOS_PREBUILT_ROOT`__, a path means the prebuilt libraries root location, it's not optional for Android Project on Android Studio, optional for other supported platforms. the default value is $cocos2dx_root/prebuilt if the cmake can access to cocos2d-x environment variable. for example
* `arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"` set this value on [app/build.gradle](./../tests/cpp-empty-test/proj.android/app/build.gradle)
1. Any options in [SelectModule.cmake](./Modules/SelectModule.cmake) can be set manually. Do it if you know what you're doing.
## Build Examples
### build specified target in Linux
```sh
cmake -H$COCOS_TEMPLATES_ROOT/.. -Bbuild_cocos2dx
cd build_cocos2dx
make all -j 4
mkdir linux-build
cd linux-build
cmake $cocos2dx_root
make cpp_empty_test
```
execute `make help` in generated make project to see all build targets
### MSVC build on Terminal or Visual Studio
```sh
cmake -H"..\cocos2d-x\" -Bmsvc_build -G"Visual Studio 15 2017" -Tv141 -DCMAKE_BUILD_TYPE=Debug
```
#### Generate Xcode Project for macOS platform
execute `cmake --build ./msvc_build` or open `Cocos2d-x.sln` in Explorer to use the generated native project.
### using CMake in Android Studio
see the Gradle properties: `PROP_NDK_MODE`, it control the way of native build
```sh
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
PROP_NDK_MODE=cmake
```
add cmake arguments in `externalNativeBuild/cmake` block of [app/build.gradle](./../tests/cpp-empty-test/proj.android/app/build.gradle) file.
### Generate Xcode macOS Project
```sh
cmake -H$COCOS_TEMPLATES_ROOT/.. -Bbuild_mac -GXcode
@ -35,29 +98,21 @@ cd build_mac
open Cocos2d-x.xcodeproj
```
#### Generate Xcode Project for iOS platform
### Generate Xcode iOS Project
```sh
cd any_dir_you_want
cd build_ios
cmake -DCMAKE_TOOLCHAIN_FILE=$COCOS_TEMPLATES_ROOT/../cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR64 -H$COCOS_TEMPLATES_ROOT/.. -Bbuild_ios_sim64 -GXcode
cd build_ios_sim64
open Cocos2d-x.xcodeproj
```
#### using CMake in Android Studio
## TODO
see the Gradle properties: `PROP_NDK_MODE`, it control the way of build Native
1. better support package iOS/MacOS App
1. improve and refactor
1. support MinGW on Windows
```sh
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
```
## Issues
#### TODO
1. make cmake build support windows
2. generate Visual Studio project
3. test cmake build again on Linux
4. add examples and more details in this manual
1. info.plist always been generated when `cmake -GXcode`, it's bad friendly to custom info.plist

View File

@ -97,177 +97,59 @@ set(COCOS_SRC cocos2d.cpp
include_directories(../external/xxtea)
include_directories(../external/clipper)
add_library(${COCOS_CORE_LIB} ${COCOS_SRC})
add_library(cocos2d ${COCOS_SRC})
set_target_properties(${COCOS_CORE_LIB}
# use necessary external libs and system libs
include(CocosUseLibs)
target_use_cocos2d_depend_libs(cocos2d)
set_target_properties(cocos2d
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
VERSION "${COCOS2D_X_VERSION}"
FOLDER "Internal"
)
set(PLATFORM_SPECIFIC_LIBS)
if(WINDOWS)
foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL)
cocos_use_pkg(${COCOS_CORE_LIB} ${_pkg})
endforeach()
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm Version Iphlpapi)
if(MINGW)
list(APPEND PLATFORM_SPECIFIC_LIBS shlwapi version)
endif()
elseif(LINUX)
foreach(_pkg OPENGL GLEW GLFW3 FMOD FONTCONFIG THREADS GTK3)
cocos_use_pkg(${COCOS_CORE_LIB} ${_pkg})
endforeach()
elseif(APPLE)
include_directories(/System/Library/Frameworks )
find_library(ICONV_LIBRARY iconv)
find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox)
find_library(FOUNDATION_LIBRARY Foundation)
find_library(OPENAL_LIBRARY OpenAL )
find_library(QUARTZCORE_LIBRARY QuartzCore )
set(COCOS_APPLE_LIBS
${OPENAL_LIBRARY}
${AUDIOTOOLBOX_LIBRARY}
${QUARTZCORE_LIBRARY}
${FOUNDATION_LIBRARY}
${ICONV_LIBRARY}
)
if(MACOSX)
cocos_use_pkg(${COCOS_CORE_LIB} GLFW3)
find_library(COCOA_LIBRARY Cocoa)
find_library(OPENGL_LIBRARY OpenGL )
find_library(APPLICATIONSERVICES_LIBRARY ApplicationServices)
find_library(IOKIT_LIBRARY IOKit)
set(PLATFORM_SPECIFIC_LIBS
${COCOA_LIBRARY}
${OPENGL_LIBRARY}
${APPLICATIONSERVICES_LIBRARY}
${IOKIT_LIBRARY}
${COCOS_APPLE_LIBS}
# set custom target: prebuilt, to copy all libs to prebuilt libs folder
if(GEN_COCOS_PREBUILT)
add_custom_target(prebuilt ALL)
add_dependencies(prebuilt cocos2d)
set_target_properties(prebuilt
PROPERTIES
FOLDER "Internal"
)
elseif(IOS)
# Locate system libraries on iOS
find_library(UIKIT_LIBRARY UIKit)
find_library(OPENGLES_LIBRARY OpenGLES )
find_library(CORE_MOTION_LIBRARY CoreMotion)
find_library(MEDIA_PLAYER_LIBRARY MediaPlayer)
find_library(CORE_TEXT_LIBRARY CoreText)
find_library(SECURITY_LIBRARY Security)
find_library(CORE_GRAPHICS_LIBRARY CoreGraphics)
find_library(AV_FOUNDATION_LIBRARY AVFoundation)
find_library(Z_LIBRARY z)
set(PLATFORM_SPECIFIC_LIBS
${UIKIT_LIBRARY}
${OPENGLES_LIBRARY}
${CORE_MOTION_LIBRARY}
${MEDIA_PLAYER_LIBRARY}
${CORE_TEXT_LIBRARY}
${SECURITY_LIBRARY}
${CORE_GRAPHICS_LIBRARY}
${AV_FOUNDATION_LIBRARY}
${Z_LIBRARY}
${COCOS_APPLE_LIBS}
add_custom_command(TARGET "prebuilt"
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_BINARY_DIR}/lib"
"${COCOS_PREBUILT_PATH}"
COMMENT "copy library directory:${CMAKE_BINARY_DIR}/lib to directory:${COCOS_PREBUILT_PATH}"
)
endif()
elseif(ANDROID)
set(PLATFORM_SPECIFIC_LIBS GLESv2 EGL log android OpenSLES)
include(../cmake/AndroidNdkModules.cmake)
android_ndk_import_module_cpufeatures()
cocos_use_pkg(${COCOS_CORE_LIB} TREMOLO)
cocos_use_pkg(${COCOS_CORE_LIB} PVMP3DEC)
include_directories(../external/android-specific/tremolo)
include_directories(../external/android-specific/pvmp3dec/include)
include_directories(../external/android-specific/pvmp3dec/src)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
if(BUILD_LUA_LIBS)
add_dependencies(prebuilt luacocos2d)
endif()
if(BUILD_JS_LIBS)
add_dependencies(prebuilt jscocos2d)
endif()
if(USE_SIMULATOR AND (MACOSX OR WINDOWS))
add_dependencies(prebuilt simulator)
endif()
endif()
foreach(pkg ZLIB MINIZIP TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
cocos_use_pkg(${COCOS_CORE_LIB} ${pkg})
endforeach()
if(NOT EMSCRIPTEN)
cocos_use_pkg(${COCOS_CORE_LIB} OPENSSL)
endif()
if(LINUX)
set(glfw_other_linker_flags X11 Xi Xrandr Xxf86vm Xinerama Xcursor rt m)
endif(LINUX)
target_link_libraries(${COCOS_CORE_LIB} ${PLATFORM_SPECIFIC_LIBS} ${glfw_other_linker_flags})
if(USE_JPEG)
add_definitions(-DCC_USE_JPEG=1)
cocos_use_pkg(${COCOS_CORE_LIB} JPEG)
else()
add_definitions(-DCC_USE_JPEG=0)
endif()
if(USE_WEBP)
add_definitions(-DCC_USE_WEBP=1)
cocos_use_pkg(${COCOS_CORE_LIB} WEBP)
else()
add_definitions(-DCC_USE_WEBP=0)
endif()
if(USE_TIFF)
add_definitions(-DCC_USE_TIFF=1)
cocos_use_pkg(${COCOS_CORE_LIB} TIFF)
else()
add_definitions(-DCC_USE_TIFF=0)
endif()
if(USE_PNG)
add_definitions(-DCC_USE_PNG=1)
cocos_use_pkg(${COCOS_CORE_LIB} PNG)
else()
add_definitions(-DCC_USE_PNG=0)
endif()
if(USE_CHIPMUNK)
cocos_use_pkg(${COCOS_CORE_LIB} CHIPMUNK)
endif()
if(USE_BOX2D)
cocos_use_pkg(${COCOS_CORE_LIB} Box2D)
endif()
if(USE_BULLET)
cocos_use_pkg(${COCOS_CORE_LIB} BULLET)
endif()
if(USE_RECAST)
cocos_use_pkg(${COCOS_CORE_LIB} RECAST)
endif()
if(ANDROID)
target_link_libraries(${COCOS_CORE_LIB} cpufeatures)
elseif(LINUX)
target_link_libraries(${COCOS_CORE_LIB} dl)
endif()
set_target_properties(${COCOS_CORE_LIB}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
VERSION "${COCOS2D_X_VERSION}"
)
## Lua bindings lib
if(BUILD_LUA_LIBS OR (CMAKE_PROJECT_NAME STREQUAL Cocos2d-x))
if(BUILD_LUA_LIBS)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings ${ENGINE_BINARY_PATH}/cocos/lua-bindings)
endif()
## JS bindings lib
if(BUILD_JS_LIBS OR (CMAKE_PROJECT_NAME STREQUAL Cocos2d-x))
if(BUILD_JS_LIBS)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings ${ENGINE_BINARY_PATH}/cocos/js-bindings)
endif()
# simulator
if(USE_SIMULATOR AND (MACOSX OR WINDOWS))
add_subdirectory(${COCOS2DX_ROOT_PATH}/tools/simulator/libsimulator ${ENGINE_BINARY_PATH}/cocos/libsimulator)
endif()
if(XCODE OR VS)
cocos_mark_code_files("${COCOS_CORE_LIB}")
endif()
cocos_mark_code_files("cocos2d")
endif()

View File

@ -39,7 +39,7 @@ else()
)
endif()
if(MSVC)
if(WINDOWS)
set(COCOS_NETWORK_LINK
libcurl_imp
${PLATFORM_LINK}

View File

@ -27,6 +27,7 @@ set(cocos_root ${COCOS2DX_ROOT_PATH})
#platform
if(WIN32) # Win32
set(PLATFORM_FOLDER win32)
add_definitions(-D_USRJSSTATIC)
elseif(APPLE)# osx or ios
set(PLATFORM_FOLDER mac)
set(PLATFORM_SRC manual/platform/ios/JavaScriptObjCBridge.mm)
@ -94,58 +95,31 @@ set(JSBINDING_SRC
${PLATFORM_SRC}
)
# if(USE_CHIPMUNK)
# include_directories(${CHIPMUNK_INCLUDE_DIRS})
# endif()
include_directories(
${cocos_root}/external/spidermonkey/include/${PLATFORM_FOLDER}
${cocos_root}/cocos
${cocos_root}/cocos/platform/${PLATFORM_FOLDER}
${cocos_root}/cocos/editor-support
${cocos_root}/extensions
${cocos_root}/external
${CHIPMUNK_INCLUDE_DIRS}
${cocos_root}/external/spidermonkey/include/${PLATFORM_FOLDER}
)
add_library(jscocos2d STATIC
${JSBINDING_SRC}
)
find_library(SPIDERMONKEY_LIBRARY NAMES js_static mozjs HINTS
${cocos_root}/external/spidermonkey/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR}
${cocos_root}/external/spidermonkey/prebuilt/${PLATFORM_FOLDER}/${ANDROID_ABI}
${cocos_root}/external/spidermonkey/prebuilt/${PLATFORM_FOLDER}
NO_CMAKE_FIND_ROOT_PATH
)
message("SPIDERMONKEY_LIBRARY: ${SPIDERMONKEY_LIBRARY}")
cocos_use_pkg(jscocos2d SQLITE3)
# should change to cocos_use_pkg() about,sqlite3 or set some flag
target_link_libraries(jscocos2d
${SPIDERMONKEY_LIBRARY}
)
if(APPLE)
FIND_LIBRARY(GAME_CONTROLLER GameController)
target_link_libraries(jscocos2d
${GAME_CONTROLLER}
)
endif()
cocos_use_pkg(jscocos2d xxhash)
target_link_libraries(jscocos2d cocos2d)
add_dependencies(jscocos2d cocos2d)
# use necessary external libs and system libs
target_use_jscocos2d_depend_libs(jscocos2d)
set_target_properties(jscocos2d
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
FOLDER "Internal"
)
if(USE_BULLET)
include_directories(${BULLET_INCLUDE_DIRS})
endif()
if(XCODE OR VS)
cocos_mark_code_files("jscocos2d")
endif()

View File

@ -41,7 +41,7 @@ if(WINDOWS)
if(MINGW)
add_definitions(-DLUASOCKET_INET_ATON -DLUASOCKET_INET_PTON)
endif()
add_definitions(-DWIN32 -D_WINDOWS)
add_definitions(-D_USRLUASTATIC)
list(APPEND lua_cocos2d_source_files
${cocos_root}/external/lua/luasocket/wsocket.c
)
@ -97,7 +97,7 @@ set(lua_bindings_manual_files
manual/spine/LuaSkeletonAnimation.cpp
manual/ui/lua_cocos2dx_experimental_video_manual.cpp
manual/ui/lua_cocos2dx_ui_manual.cpp
# android.mk not include this, need review
# android.mk not include this
# manual/video/lua_cocos2dx_experimental_video_manual.cpp
manual/audioengine/lua_cocos2dx_audioengine_manual.cpp
manual/physics3d/lua_cocos2dx_physics3d_manual.cpp
@ -157,12 +157,14 @@ add_library(luacocos2d ${lua_bindings_files})
target_link_libraries(luacocos2d cocos2d)
add_dependencies(luacocos2d cocos2d)
cocos_use_pkg(luacocos2d LUAJIT)
# use necessary external libs and system libs
target_use_luacocos2d_depend_libs(luacocos2d)
set_target_properties(luacocos2d
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
FOLDER "Internal"
)
if(XCODE OR VS)

View File

@ -1,4 +1,3 @@
# need review
set(COCOS_VR_SRC)
if(NOT IOS)
set(COCOS_VR_SRC

View File

@ -18,7 +18,8 @@
"cmake/Modules/CMakeParseArguments.cmake",
"cmake/Modules/CocosBuildHelpers.cmake",
"cmake/Modules/CocosBuildSet.cmake",
"cmake/Modules/CocosUsePrebuiltLibs.cmake",
"cmake/Modules/CocosPickLibs.cmake",
"cmake/Modules/CocosUseLibs.cmake",
"cmake/Modules/FindCURL.cmake",
"cmake/Modules/FindChipmunk.cmake",
"cmake/Modules/FindFMOD.cmake",

View File

@ -29,179 +29,105 @@ set(APP_NAME TemplateCpp)
project (${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
# set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)
# engine path changed, after cocos new
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cocos2d)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
if(NOT USE_COCOS_PREBUILT)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
endif()
# add engine directory, get cocos library
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
# mark app resources
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/Resources"
)
if(APPLE OR VS)
cocos_mark_multi_resources(cc_common_res RES_TO "Resources" FOLDERS ${res_res_folders})
endif()
include_directories(
${COCOS2DX_ROOT_PATH}/cocos/audio/include/
Classes
)
# add cross-platforms source files and header files
set(common_code_files
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
)
set(common_header_files
Classes/AppDelegate.h
Classes/HelloWorldScene.h
)
# add platform specific source files, save to platform_specific_src
if(ANDROID)
# change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
set(APP_NAME MyGame)
endif(ANDROID)
if(ANDROID)
set(PLATFORM_SPECIFIC_SRC proj.android/app/jni/hellocpp/main.cpp)
set(RES_PREFIX "/Resources")
set(platform_specific_src proj.android/app/jni/hellocpp/main.cpp)
elseif(LINUX)
set(platform_specific_src proj.linux/main.cpp)
elseif(WINDOWS)
set(PLATFORM_SPECIFIC_SRC proj.win32/main.cpp)
set(PLATFORM_SPECIFIC_HEADERS
proj.win32/main.h
proj.win32/resource.h
)
set(RES_PREFIX "")
set(windows_src
proj.win32/main.cpp
proj.win32/game.rc
)
set(platform_specific_header
proj.win32/main.h
proj.win32/resource.h
)
set(platform_specific_src ${cc_common_res} ${windows_src})
elseif(APPLE)
file(GLOB_RECURSE RES_FILES Resources/*)
cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources)
if(IOS)
set(IOS_SRC
set(ios_code_files
proj.ios_mac/ios/main.m
proj.ios_mac/ios/AppController.mm
proj.ios_mac/ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios_mac/ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios_mac/ios)
file(GLOB_RECURSE RES_LSBG proj.ios_mac/ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios_mac/ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(MAC_SRC proj.ios_mac/mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.ios_mac/mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.ios_mac/mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
set(mac_code_files proj.ios_mac/mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
set(PLATFORM_SPECIFIC_SRC ${RES_FILES} ${APPLE_SRC})
elseif(LINUX)
set(PLATFORM_SPECIFIC_SRC proj.linux/main.cpp)
set(RES_PREFIX "/Resources")
set(platform_specific_src ${cc_common_res} ${apple_src_files})
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
message(FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
include_directories(
${COCOS2DX_ROOT_PATH}/cocos/audio/include/
Classes
# mark app complie info and libs info
set(cocos_app_src
${platform_specific_src}
${common_header_files}
${common_code_files}
${common_header_files}
${common_code_files}
)
cocos_build_app(${APP_NAME}
APP_SRC "${cocos_app_src}"
DEPEND_COMMON_LIBS "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
if (WINDOWS)
include_directories(
${COCOS2DX_ROOT_PATH}/external/glfw3/include/${PLATFORM_FOLDER}
${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/gles/include/OGLES
)
elseif (APPLE)
if (MACOSX)
include_directories(
${COCOS2DX_ROOT_PATH}/external/glfw3/include/mac
)
endif()
elseif(LINUX)
include_directories(
/usr/local/include/GLFW
/usr/include/GLFW
)
endif(WINDOWS)
set(GAME_SRC
${PLATFORM_SPECIFIC_SRC}
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
)
set(GAME_HEADERS
${PLATFORM_SPECIFIC_HEADERS}
Classes/AppDelegate.h
Classes/HelloWorldScene.h
)
# add the executable
if(ANDROID)
add_library(${APP_NAME} SHARED ${GAME_SRC} ${GAME_HEADERS})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
elseif(MSVC)
add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS} proj.win32/game.rc)
else()
add_executable(${APP_NAME} ${GAME_SRC} ${GAME_HEADERS})
endif()
target_link_libraries(${APP_NAME} cocos2d)
if(MSVC)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${PLATFORM_FOLDER}/$<CONFIG>")
#get our resources
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR})
# create a list of dlls to copy
file(GLOB THIRD_PARTY_DLLS
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/zlib/prebuilt/zlib1.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libogg.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libvorbis.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/OggDecoder/prebuilt/libvorbisfile.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt/libmpg123.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/OpenalSoft/prebuilt/OpenAL32.dll"
"${COCOS2DX_ROOT_PATH}/external/${PLATFORM_FOLDER}-specific/icon/prebuilt/iconv.dll"
"${COCOS2DX_ROOT_PATH}/external/tiff/prebuilt/${PLATFORM_FOLDER}/libtiff.dll"
)
list(SORT THIRD_PARTY_DLLS)
# do the copying
foreach( file_i ${THIRD_PARTY_DLLS})
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${file_i}
${APP_BIN_DIR}
)
endforeach( file_i )
#Visual Studio Defaults to wrong type
set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS"
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
elseif(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(APPLE)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "Cpp Hello Test")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $<TARGET_FILE_DIR:${APP_NAME}>${RES_PREFIX}
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${res_res_folders})
endif()

View File

@ -24,9 +24,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
targets 'MyGame'
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -32,137 +32,111 @@ project(${APP_NAME})
set(RUNTIME_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/runtime-src)
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
# set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)
# engine path changed, after cocos new
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
if(NOT USE_COCOS_PREBUILT)
set(BUILD_JS_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT USE_COCOS_PREBUILT)
endif()
# add engine directory, get cocos library
set(BUILD_JS_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
# script and source files info, not need to compile
set(res_main_files
"${CMAKE_CURRENT_SOURCE_DIR}/main.js"
"${CMAKE_CURRENT_SOURCE_DIR}/project.json"
)
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/res"
)
set(res_src_folders
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
set(res_script_folders
"${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script"
)
if(APPLE OR VS)
cocos_mark_multi_resources(res_main RES_TO "Resources" FILES ${res_main_files})
cocos_mark_multi_resources(res_res RES_TO "Resources/res" FOLDERS ${res_res_folders})
cocos_mark_multi_resources(res_src RES_TO "Resources/src" FOLDERS ${res_src_folders})
cocos_mark_multi_resources(res_script RES_TO "Resources/script" FOLDERS ${res_script_folders})
set(cc_common_res ${res_main} ${res_res} ${res_src} ${res_script})
endif()
# sources need to compile info, include dirs and source files
include_directories(
${RUNTIME_SRC_ROOT}/Classes
${COCOS2DX_ROOT_PATH}/cocos/editor-support
${COCOS2DX_ROOT_PATH}/external/spidermonkey/include/${PLATFORM_FOLDER}
)
set(GAME_SRC ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp)
if(ANDROID)
# change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
set(APP_NAME cocos2djs)
endif(ANDROID)
include_directories(
${COCOS2DX_ROOT_PATH}
${COCOS2DX_ROOT_PATH}/cocos
${COCOS2DX_ROOT_PATH}/deprecated
${COCOS2DX_ROOT_PATH}/cocos/platform
${COCOS2DX_ROOT_PATH}/extensions
${COCOS2DX_ROOT_PATH}/external
${COCOS2DX_ROOT_PATH}/external/spidermonkey/include/${PLATFORM_FOLDER}
${COCOS2DX_ROOT_PATH}/cocos/editor-support
)
include_directories(${RUNTIME_SRC_ROOT}/Classes)
set(GAME_SRC ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp
)
if(ANDROID)
list(APPEND GAME_SRC ${RUNTIME_SRC_ROOT}/proj.android/app/jni/hellojavascript/main.cpp)
elseif(LINUX)
list(APPEND GAME_SRC ${RUNTIME_SRC_ROOT}/proj.linux/main.cpp)
elseif(WINDOWS)
set(WINDOWS_SRC ${RUNTIME_SRC_ROOT}/proj.win32/main.cpp)
list(APPEND WINDOWS_SRC ${RUNTIME_SRC_ROOT}/proj.win32/game.rc)
set(PLATFORM_SPECIFIC_HEADERS
${RUNTIME_SRC_ROOT}/proj.win32/main.h
${RUNTIME_SRC_ROOT}/proj.win32/resource.h
)
list(APPEND GAME_SRC ${WINDOWS_SRC} ${PLATFORM_SPECIFIC_HEADERS} ${cc_common_res})
elseif(APPLE)
if(IOS)
set(IOS_SRC
set(ios_code_files
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/main.m
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/AppController.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios)
file(GLOB_RECURSE RES_LSBG ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
elseif(MACOSX)
set(MAC_SRC ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/main.cpp)
file(GLOB_RECURSE RES_ICON ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
endif()
set(APP_MAIN
main.js
project.json
)
cocos_mark_resources(FILES ${APP_MAIN} BASEDIR ./ RESOURCEBASE Resources)
file(GLOB_RECURSE APP_RESOURCES res/*)
cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR res RESOURCEBASE Resources/res)
file(GLOB_RECURSE APP_SCRIPTS src/*)
cocos_mark_resources(FILES ${APP_SCRIPTS} BASEDIR src RESOURCEBASE Resources/src)
file(GLOB_RECURSE COCOS_SCRIPTS ${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script/*)
cocos_mark_resources(FILES ${COCOS_SCRIPTS} BASEDIR ${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script RESOURCEBASE Resources/script)
list(APPEND GAME_SRC ${APPLE_SRC} ${APP_MAIN} ${APP_RESOURCES} ${APP_SCRIPTS} ${COCOS_SCRIPTS})
endif()
if(ANDROID)
add_library(${APP_NAME} SHARED ${GAME_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
add_executable(${APP_NAME}
${GAME_SRC}
)
endif()
target_link_libraries(${APP_NAME} jscocos2d)
if(LINUX)
set(RES_PREFIX "/Resources")
else()
set(RES_PREFIX "")
endif()
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
set(ios_res_files
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreen.storyboard
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(mac_code_files ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/main.cpp)
set(mac_res_files
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
list(APPEND GAME_SRC ${apple_src_files} ${cc_common_res})
else()
message(FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${GAME_SRC}"
DEPEND_COMMON_LIBS "jscocos2d" "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
# mark app resources, resource will be copy auto after mark
if(APPLE)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "LuaTestsApp")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/script
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}${RES_PREFIX}/*.js
COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}${RES_PREFIX}/*.json
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E copy_directory ${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script ${APP_BIN_DIR}${RES_PREFIX}/script
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/main.js ${APP_BIN_DIR}${RES_PREFIX}/main.js
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/project.json ${APP_BIN_DIR}${RES_PREFIX}/project.json
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
# copy resource on linux or WINDOWS
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FILES ${res_main_files})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/script FOLDERS ${res_script_folders})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME} GROUPBASE ${RUNTIME_SRC_ROOT})
endif()

View File

@ -25,8 +25,13 @@ android {
else if (PROP_NDK_MODE == 'cmake') {
cmake {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DUSE_JSCOCOS2D=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -29,56 +29,80 @@ project(${APP_NAME})
set(RUNTIME_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/runtime-src)
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
# set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)
# engine path changed, after cocos new
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/frameworks/cocos2d-x)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
if(NOT USE_COCOS_PREBUILT)
set(BUILD_LUA_LIBS ON)
set(USE_SIMULATOR ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
endif()
# add engine directory, get cocos library
set(BUILD_LUA_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
if(ANDROID)
# change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
set(APP_NAME cocos2dlua)
endif(ANDROID)
set(GAME_SRC ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp
# script and source files info, not need to compile
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/res"
)
set(res_src_folders
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)
set(res_script_folders
"${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script"
)
if(APPLE OR VS)
cocos_mark_multi_resources(res_res RES_TO "Resources/res" FOLDERS ${res_res_folders})
cocos_mark_multi_resources(res_src RES_TO "Resources/src" FOLDERS ${res_src_folders})
cocos_mark_multi_resources(res_script RES_TO "Resources/src/cocos" FOLDERS ${res_script_folders})
set(cc_common_res ${res_res} ${res_src} ${res_script})
endif()
# sources need to compile info, include dirs and source files
include_directories(
${RUNTIME_SRC_ROOT}/Classes
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/auto
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/manual
${COCOS2DX_ROOT_PATH}/external/lua/luajit/include
${COCOS2DX_ROOT_PATH}/external/lua/tolua
${COCOS2DX_ROOT_PATH}/tools/simulator/libsimulator/lib
)
set(GAME_SRC ${RUNTIME_SRC_ROOT}/Classes/AppDelegate.cpp)
if(ANDROID)
# change APP_NAME to the share library name for Android, it's value depend on AndroidManifest.xml
set(APP_NAME cocos2dlua)
list(APPEND GAME_SRC ${RUNTIME_SRC_ROOT}/proj.android/app/jni/hellolua/main.cpp)
elseif(LINUX)
list(APPEND GAME_SRC ${RUNTIME_SRC_ROOT}/proj.linux/main.cpp)
elseif(WINDOWS)
add_definitions(-D_USRLUASTATIC -D_USRLIBSIMSTATIC)
list(APPEND GAME_SRC
${RUNTIME_SRC_ROOT}/proj.win32/game.rc
${RUNTIME_SRC_ROOT}/proj.win32/stdafx.cpp
${RUNTIME_SRC_ROOT}/proj.win32/main.cpp
${RUNTIME_SRC_ROOT}/proj.win32/SimulatorWin.cpp
${cc_common_res}
)
elseif(APPLE)
if(IOS)
set(IOS_SRC
set(ios_code_files
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/main.m
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/AppController.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios)
file(GLOB_RECURSE RES_LSBG ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
)
set(ios_res_files
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreen.storyboard
${RUNTIME_SRC_ROOT}/proj.ios_mac/ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(APPLE_RES_UI ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(MAC_SRC
set(MAC_SRC
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/main.m
# it needed tools/simulator, but not existed cmake files
# ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/SimulatorApp.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/SimulatorApp.mm
${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/ConsoleWindowController.m
)
)
file(GLOB_RECURSE RES_ICON ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR ${RUNTIME_SRC_ROOT}/proj.ios_mac/mac)
# special for lua-template
@ -94,68 +118,36 @@ elseif(APPLE)
# xib -> nib, need mark resources
set(APPLE_RES_UI ${RES_MAIN_BASE} ${RES_MAIN_EN} ${RES_MAIN_ZH} ${RES_CONSOLE})
endif()
file(GLOB_RECURSE APP_RESOURCES res/*)
cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR res RESOURCEBASE Resources/res)
file(GLOB_RECURSE APP_SCRIPTS src/*)
cocos_mark_resources(FILES ${APP_SCRIPTS} BASEDIR src RESOURCEBASE Resources/src)
file(GLOB_RECURSE COCOS_SCRIPTS ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/*)
cocos_mark_resources(FILES ${COCOS_SCRIPTS} BASEDIR ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script RESOURCEBASE Resources/src/cocos)
list(APPEND GAME_SRC ${APPLE_SRC} ${APP_RESOURCES} ${APP_SCRIPTS} ${COCOS_SCRIPTS})
list(APPEND GAME_SRC ${APPLE_SRC} ${cc_common_res})
else()
message(FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
include_directories(
${RUNTIME_SRC_ROOT}/Classes
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/auto
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/manual
${COCOS2DX_ROOT_PATH}/external/lua/luajit/include
${COCOS2DX_ROOT_PATH}/external/lua/tolua
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${GAME_SRC}"
DEPEND_COMMON_LIBS "luacocos2d" "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
DEPEND_MACOSX_LIBS "simulator"
DEPEND_WINDOWS_LIBS "simulator"
)
if(ANDROID)
add_library(${APP_NAME} SHARED ${GAME_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME} ${GAME_SRC})
endif(ANDROID)
target_link_libraries(${APP_NAME} luacocos2d)
# mark app resources
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(MACOSX)
set_target_properties(${APP_NAME} PROPERTIES
RESOURCE "${APPLE_RES_UI}"
RESOURCE "${APPLE_RES_UI}"
)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "MacOSXBundleInfo.LuaTemplate.plist.in" BUNDLE_NAME "LuaTestsApp")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}/Resources
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res ${APP_BIN_DIR}/Resources/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${APP_BIN_DIR}/Resources/src
COMMAND ${CMAKE_COMMAND} -E copy_directory ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME} GROUPBASE ${RUNTIME_SRC_ROOT})
# copy resource on linux or WINDOWS
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src/cocos FOLDERS ${res_script_folders})
endif()

View File

@ -25,8 +25,13 @@ android {
else if (PROP_NDK_MODE == 'cmake') {
cmake {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DUSE_LUACOCOS2D=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -26,7 +26,7 @@
# build all test projects, it need the engine library
# library have been build, on ../CMakeLists.txt
# library have been build, on ../CMakeLists.txt, uesed to prevent tests project build engine lib again
set(BUILD_ENGINE_DONE ON)
# add engine all tests project
@ -46,7 +46,7 @@ add_subdirectory(${COCOS2DX_ROOT_PATH}/templates/cpp-template-default ${ENGINE_B
add_subdirectory(${COCOS2DX_ROOT_PATH}/templates/js-template-default ${ENGINE_BINARY_PATH}/template/js-template-default)
# run on mac failed, for it need libsimulator(not cmake files)
# TODO run on mac/win didn't perfect, need to check later
add_subdirectory(${COCOS2DX_ROOT_PATH}/templates/lua-template-default ${ENGINE_BINARY_PATH}/template/lua-template-default)

View File

@ -27,124 +27,87 @@ set(APP_NAME cpp_empty_test)
project(${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
# add engine directory, get cocos library
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
if(ANDROID)
set(PLATFORM_SRC proj.android/app/jni/main.cpp)
set(RES_PREFIX "/Resources")
elseif(WINDOWS)
set(PLATFORM_SRC proj.win32/main.cpp)
set(RES_PREFIX "")
elseif(APPLE)
file(GLOB_RECURSE RES_FILES Resources/*)
cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources)
if(IOS)
set(IOS_SRC
proj.ios/main.m
proj.ios/AppController.mm
proj.ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios)
file(GLOB_RECURSE RES_LSBG proj.ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
elseif(MACOSX)
set(MAC_SRC proj.mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
if(NOT USE_COCOS_PREBUILT)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
set(PLATFORM_SRC ${RES_FILES} ${APPLE_SRC})
elseif(LINUX)
set(PLATFORM_SRC proj.linux/main.cpp)
set(RES_PREFIX "/Resources")
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
include_directories(Classes)
set(SAMPLE_SRC
${PLATFORM_SRC}
set(common_code_files
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
)
if(ANDROID)
add_library(${APP_NAME} SHARED ${SAMPLE_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME} ${SAMPLE_SRC})
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/Resources"
)
if(APPLE OR VS)
cocos_mark_multi_resources(cc_common_res RES_TO "Resources" FOLDERS ${res_res_folders})
endif()
target_link_libraries(${APP_NAME} cocos2d)
add_dependencies(${APP_NAME} cocos2d)
if(MSVC)
#get our resources
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/Resources ${CMAKE_CURRENT_BINARY_DIR})
#get our dlls
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/../../external/win32-specific/gles/prebuilt/glew32.dll
${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(TARGET ${APP_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/../../external/win32-specific/zlib/prebuilt/zlib1.dll
${CMAKE_CURRENT_BINARY_DIR}/Debug)
#Visual Studio Defaults to wrong type
set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS")
set_target_properties(${APP_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
if(ANDROID)
set(platform_specific_src proj.android/app/jni/main.cpp)
elseif(LINUX)
set(platform_specific_src proj.linux/main.cpp)
elseif(WINDOWS)
set(windows_src proj.win32/main.cpp)
set(platform_specific_src ${cc_common_res} ${windows_src})
elseif(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
if(IOS)
set(ios_code_files
proj.ios/main.m
proj.ios/AppController.mm
proj.ios/RootViewController.mm
)
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(mac_code_files proj.mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
set(platform_specific_src ${cc_common_res} ${apple_src_files})
else()
message(FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
include_directories(Classes)
set(all_code_files
${platform_specific_src}
${common_code_files}
)
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${all_code_files}"
DEPEND_COMMON_LIBS "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
# mark app resources
if(APPLE)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "Cpp Empty Test")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
add_custom_command(TARGET ${APP_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $<TARGET_FILE_DIR:${APP_NAME}>${RES_PREFIX}
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${res_res_folders})
endif()

View File

@ -24,8 +24,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
targets "cpp_empty_test"
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang",
"-DANDROID_ARM_NEON=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=ON"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -4,70 +4,61 @@ set(APP_NAME cpp_tests)
project(${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
set(ENGINE_BINARY_PATH ${PROJECT_BINARY_DIR}/engine)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
# add engine directory, get cocos library
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
if(WIN32)
set(PLATFORM_SRC proj.win32/main.cpp)
set(RES_PREFIX "")
elseif(APPLE)
file(GLOB_RECURSE RES_FILES Resources/*)
cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources)
if(IOS)
set(IOS_SRC
proj.ios/main.m
proj.ios/Classes/testsAppDelegate.mm
proj.ios/Classes/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios)
file(GLOB_RECURSE RES_LSBG proj.ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
elseif(MACOSX)
set(MAC_SRC proj.mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
if(NOT USE_COCOS_PREBUILT)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
set(PLATFORM_SRC ${RES_FILES} ${APPLE_SRC})
endif()
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/Resources"
)
if(APPLE OR VS)
cocos_mark_multi_resources(cc_common_res RES_TO "Resources" FOLDERS ${res_res_folders})
endif()
if(WINDOWS)
set(windows_src proj.win32/main.cpp)
set(platform_specific_src ${cc_common_res} ${windows_src})
elseif(APPLE)
if(IOS)
set(ios_code_files
proj.ios/main.m
proj.ios/Classes/testsAppDelegate.mm
proj.ios/Classes/RootViewController.mm
)
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(mac_code_files proj.mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
set(platform_specific_src ${cc_common_res} ${apple_src_files})
elseif(LINUX)
set(PLATFORM_SRC proj.linux/main.cpp)
set(RES_PREFIX "/Resources")
set(platform_specific_src proj.linux/main.cpp)
elseif(ANDROID)
set(PLATFORM_SRC
set(platform_specific_src
Classes/JNITest/JNITest.cpp
proj.android/app/jni/main.cpp)
set(RES_PREFIX "/Resources")
elseif(IOS)
# need check
set(PLATFORM_SRC proj.ios/main.m)
set(platform_specific_src proj.ios/main.m)
else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
# Use same method as in cocos library
if(LINUX)
foreach(_pkg FONTCONFIG GTK3)
cocos_find_package(${_pkg} ${_pkg} REQUIRED)
endforeach()
endif()
cocos_find_package(FREETYPE FREETYPE REQUIRED)
cocos_find_package(CURL CURL REQUIRED)
set(TESTS_SRC
Classes/ActionManagerTest/ActionManagerTest.cpp
Classes/ActionsEaseTest/ActionsEaseTest.cpp
@ -189,10 +180,9 @@ set(TESTS_SRC
Classes/ZwoptexTest/ZwoptexTest.cpp
Classes/SpriteFrameCacheTest/SpriteFrameCacheTest.cpp
Classes/controller.cpp
# need review
# Classes/VRTest/VRTest.cpp
# Classes/VRTest/VRTest.h
${PLATFORM_SRC}
${platform_specific_src}
)
if(ANDROID OR IOS)
@ -206,6 +196,9 @@ if(WIN32 OR MACOSX OR LINUX)
list(APPEND TESTS_SRC
Classes/WindowTest/WindowTest.cpp
)
list(APPEND TESTS_SRC
Classes/BugsTest/Bug-14327.cpp
)
endif()
if(USE_CHIPMUNK)
@ -225,7 +218,7 @@ endif()
if(USE_BULLET)
list(APPEND TESTS_SRC
Classes/Physics3DTest/Physics3DTest.cpp
Classes/Physics3DTest/Physics3DTest.cpp
)
include_directories(${BULLET_INCLUDE_DIRS})
endif()
@ -236,66 +229,41 @@ set(EXTENDED_TESTS_SRC
Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp
)
if(LINUX)
else()
if(NOT LINUX)
list(APPEND EXTENDED_TESTS_SRC
Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp
)
)
endif()
include_directories(
Classes
${COCOS2DX_ROOT_PATH}/cocos/editor-support
)
)
if(ANDROID)
add_library(${APP_NAME} SHARED ${TESTS_SRC} ${EXTENDED_TESTS_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME} ${TESTS_SRC} ${EXTENDED_TESTS_SRC})
endif()
target_link_libraries(${APP_NAME} cocos2d)
add_dependencies(${APP_NAME} cocos2d)
if(LINUX)
foreach(_pkg FONTCONFIG GTK3)
cocos_use_pkg(${APP_NAME} ${_pkg})
endforeach()
endif()
foreach(pkg FREETYPE CURL)
cocos_use_pkg(${APP_NAME} ${pkg})
endforeach()
# mark app complie info and libs info
set(cocos_app_src
${TESTS_SRC}
${EXTENDED_TESTS_SRC}
)
cocos_build_app(${APP_NAME}
APP_SRC "${cocos_app_src}"
DEPEND_COMMON_LIBS "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
COMMON_USE_PKGS "FREETYPE" "CURL"
LINUX_USE_PKGS "FONTCONFIG" "GTK3"
)
# mark app resources
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "Tests Cpp" INFO_STRING "test project for cpp")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
elseif(ANDROID)
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}${RES_PREFIX}
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FOLDERS ${res_res_folders})
endif()

View File

@ -24,9 +24,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
targets 'cpp_tests'
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -27,70 +27,73 @@ set(APP_NAME js_tests)
project(${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
# add engine directory, get cocos library
set(BUILD_JS_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
if(NOT USE_COCOS_PREBUILT)
set(BUILD_JS_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
endif()
if(WIN32)
set(res_main_files
"${CMAKE_CURRENT_SOURCE_DIR}/../main.js"
"${CMAKE_CURRENT_SOURCE_DIR}/../project.json"
)
# "${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources"
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../resjs"
"${CMAKE_CURRENT_SOURCE_DIR}/../res"
"${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources"
)
set(res_src_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
set(res_script_folders
"${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script"
)
if(APPLE OR VS)
cocos_mark_multi_resources(res_main RES_TO "Resources" FILES ${res_main_files})
cocos_mark_multi_resources(res_res RES_TO "Resources/res" FOLDERS ${res_res_folders})
cocos_mark_multi_resources(res_src RES_TO "Resources/src" FOLDERS ${res_src_folders})
cocos_mark_multi_resources(res_script RES_TO "Resources/script" FOLDERS ${res_script_folders})
set(cc_common_res ${res_main} ${res_res} ${res_src} ${res_script})
endif()
if(WINDOWS)
set(WINDOWS_SRC proj.win32/main.cpp)
set(PLATFORM_SRC ${cc_common_res} ${WINDOWS_SRC})
elseif(ANDROID)
set(PLATFORM_SRC
proj.android/app/jni/main.cpp
)
set(PLATFORM_SRC proj.android/app/jni/main.cpp)
elseif(LINUX)
set(PLATFORM_SRC
proj.linux/main.cpp
)
set(PLATFORM_SRC proj.linux/main.cpp)
elseif(APPLE)
if(IOS)
set(IOS_SRC
set(ios_code_files
proj.ios/main.m
proj.ios/NativeOcClass.m
proj.ios/AppController.mm
proj.ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios)
file(GLOB_RECURSE RES_LSBG proj.ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(MAC_SRC proj.mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
set(mac_code_files proj.mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
set(APP_MAIN
../main.js
../project.json
)
cocos_mark_resources(FILES ${APP_MAIN} BASEDIR .. RESOURCEBASE Resources)
file(GLOB_RECURSE APP_RESJS ../resjs/*)
cocos_mark_resources(FILES ${APP_RESJS} BASEDIR ../resjs RESOURCEBASE Resources/res)
file(GLOB_RECURSE APP_RESOURCES ../res/*)
cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res)
file(GLOB_RECURSE APP_SCRIPTS ../src/*)
cocos_mark_resources(FILES ${APP_SCRIPTS} BASEDIR ../src RESOURCEBASE Resources/src)
file(GLOB_RECURSE TEST_RESOURCES ${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources/*)
cocos_mark_resources(FILES ${TEST_RESOURCES} BASEDIR ${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources RESOURCEBASE Resources/res)
file(GLOB_RECURSE COCOS_SCRIPTS ${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script/*)
cocos_mark_resources(FILES ${COCOS_SCRIPTS} BASEDIR ${COCOS2DX_ROOT_PATH}/cocos/scripting/js-bindings/script RESOURCEBASE Resources/script)
set(PLATFORM_SRC ${APPLE_SRC} ${APP_MAIN} ${APP_RESJS} ${APP_RESOURCES} ${APP_SCRIPTS} ${COCOS_SCRIPTS} ${TEST_RESOURCES})
set(PLATFORM_SRC ${cc_common_res} ${apple_src_files})
endif()
set(SAMPLE_SRC
@ -111,62 +114,28 @@ include_directories(
${COCOS2DX_ROOT_PATH}/external/chipmunk/include/chipmunk
)
if(ANDROID)
add_library(${APP_NAME} SHARED ${SAMPLE_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME}
${SAMPLE_SRC}
)
endif()
target_link_libraries(${APP_NAME} jscocos2d)
add_dependencies(${APP_NAME} jscocos2d)
if(LINUX)
set(RES_PREFIX "/Resources")
else()
set(RES_PREFIX "")
endif()
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${SAMPLE_SRC}"
DEPEND_COMMON_LIBS "jscocos2d" "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
# mark app resources
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "JS Tests")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/script
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E remove_directory ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}${RES_PREFIX}/*.js
COMMAND ${CMAKE_COMMAND} -E remove ${APP_BIN_DIR}${RES_PREFIX}/*.json
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../../cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../resjs ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../../../cocos/scripting/js-bindings/script ${APP_BIN_DIR}${RES_PREFIX}/script
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../main.js ${APP_BIN_DIR}${RES_PREFIX}/main.js
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../project.json ${APP_BIN_DIR}${RES_PREFIX}/project.json
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR} FILES ${res_main_files})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/script FOLDERS ${res_script_folders})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()

View File

@ -22,9 +22,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
targets "js_tests"
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DUSE_JSCOCOS2D=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -4,60 +4,65 @@ set(APP_NAME lua_empty_test)
project(${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
# add engine directory, get cocos library
set(BUILD_LUA_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
if(NOT USE_COCOS_PREBUILT)
set(BUILD_LUA_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
endif()
endif(NOT DEFINED BUILD_ENGINE_DONE)
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../res"
)
set(res_src_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
set(res_script_folders
"${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script"
)
if(APPLE OR VS)
cocos_mark_multi_resources(res_res RES_TO "Resources/res" FOLDERS ${res_res_folders})
cocos_mark_multi_resources(res_src RES_TO "Resources/src" FOLDERS ${res_src_folders})
cocos_mark_multi_resources(res_script RES_TO "Resources/src/cocos" FOLDERS ${res_script_folders})
set(cc_common_res ${res_res} ${res_src} ${res_script})
endif()
set(SAMPLE_SRC Classes/AppDelegate.cpp)
if(LINUX)
if(ANDROID)
list(APPEND SAMPLE_SRC proj.android/app/jni/main.cpp)
elseif(LINUX)
set(SAMPLE_SRC ${SAMPLE_SRC} proj.linux/main.cpp)
set(RES_PREFIX "/Resources")
elseif(WINDOWS)
list(APPEND SAMPLE_SRC proj.win32/main.cpp)
set(RES_PREFIX "")
add_definitions(-D_USRLUASTATIC)
list(APPEND SAMPLE_SRC proj.win32/main.cpp ${cc_common_res})
elseif(APPLE)
if(IOS)
set(IOS_SRC
set(ios_code_files
proj.ios/main.m
proj.ios/AppController.mm
proj.ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios)
file(GLOB_RECURSE RES_LSBG proj.ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
)
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(MAC_SRC proj.mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
set(mac_code_files proj.mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
file(GLOB_RECURSE APP_RESOURCES ../res/*)
cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res)
file(GLOB_RECURSE APP_SCRIPTS ../src/*)
cocos_mark_resources(FILES ${APP_SCRIPTS} BASEDIR ../src RESOURCEBASE Resources/src)
file(GLOB_RECURSE COCOS_SCRIPTS ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/*)
cocos_mark_resources(FILES ${COCOS_SCRIPTS} BASEDIR ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script RESOURCEBASE Resources/src/cocos)
list(APPEND SAMPLE_SRC ${APPLE_SRC} ${APP_RESOURCES} ${APP_SCRIPTS} ${COCOS_SCRIPTS})
elseif(ANDROID)
list(APPEND SAMPLE_SRC proj.android/app/jni/main.cpp)
set(RES_PREFIX "/Resources")
list(APPEND SAMPLE_SRC ${cc_common_res} ${apple_src_files})
endif()
include_directories(
@ -70,45 +75,26 @@ include_directories(
include_directories(${LUAJIT_INCLUDE_DIRS})
if(ANDROID)
add_library(${APP_NAME} SHARED ${SAMPLE_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME} ${SAMPLE_SRC})
endif()
target_link_libraries(${APP_NAME} luacocos2d)
add_dependencies(${APP_NAME} luacocos2d)
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${SAMPLE_SRC}"
DEPEND_COMMON_LIBS "luacocos2d" "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
# mark app resources
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(MACOSX)
cocos_pak_xcode(${APP_NAME})
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E copy_directory ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src/cocos FOLDERS ${res_script_folders})
endif()

View File

@ -24,9 +24,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
targets "lua_empty_test"
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DUSE_LUACOCOS2D=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -4,70 +4,71 @@ set(APP_NAME lua_tests)
project(${APP_NAME})
# default build, not build when build engine and all tests
if(NOT DEFINED BUILD_ENGINE_DONE)
# define some variables
set(COCOS2DX_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
set(CMAKE_MODULE_PATH ${COCOS2DX_ROOT_PATH}/cmake/Modules/)
# works before libcocos2d
include(CocosBuildSet)
CocosBuildSet()
# add engine directory, get cocos library
set(BUILD_LUA_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif(NOT DEFINED BUILD_ENGINE_DONE)
if(NOT USE_COCOS_PREBUILT)
set(BUILD_LUA_LIBS ON)
add_subdirectory(${COCOS2DX_ROOT_PATH}/cocos ${ENGINE_BINARY_PATH}/cocos/core)
endif()
endif()
set(SAMPLE_SRC
Classes/AppDelegate.cpp
Classes/lua_assetsmanager_test_sample.cpp
Classes/lua_test_bindings.cpp
)
)
if(LINUX)
set(res_res_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../res"
"${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources"
)
set(res_src_folders
"${CMAKE_CURRENT_SOURCE_DIR}/../src"
)
set(res_script_folders
"${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script"
)
if(APPLE OR VS)
cocos_mark_multi_resources(res_res RES_TO "Resources/res" FOLDERS ${res_res_folders})
cocos_mark_multi_resources(res_src RES_TO "Resources/src" FOLDERS ${res_src_folders})
cocos_mark_multi_resources(res_script RES_TO "Resources/src/cocos" FOLDERS ${res_script_folders})
set(cc_common_res ${res_res} ${res_src} ${res_script})
endif()
if(ANDROID)
list(APPEND SAMPLE_SRC proj.android/app/jni/main.cpp)
elseif(LINUX)
set(SAMPLE_SRC ${SAMPLE_SRC} proj.linux/main.cpp)
set(RES_PREFIX "/Resources")
elseif(WINDOWS)
list(APPEND SAMPLE_SRC proj.win32/main.cpp)
set(RES_PREFIX "")
add_definitions(-D_USRLUASTATIC)
list(APPEND SAMPLE_SRC proj.win32/main.cpp ${cc_common_res})
elseif(APPLE)
if(IOS)
set(IOS_SRC
set(ios_code_files
proj.ios_mac/ios/main.m
proj.ios_mac/ios/LuaObjectCBridgeTest.mm
proj.ios_mac/ios/AppController.mm
proj.ios_mac/ios/RootViewController.mm
)
file(GLOB_RECURSE RES_LS proj.ios_mac/ios/LaunchScreen.storyboard)
cocos_mark_resources(FILES ${RES_LS} BASEDIR proj.ios_mac/ios)
file(GLOB_RECURSE RES_LSBG proj.ios_mac/ios/LaunchScreenBackground.png)
cocos_mark_resources(FILES ${RES_LSBG} BASEDIR proj.ios_mac/ios)
set(APPLE_SRC ${IOS_SRC} ${RES_LS} ${RES_LSBG})
set(ios_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/LaunchScreen.storyboard
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/LaunchScreenBackground.png
)
cocos_mark_multi_resources(ios_res_files RES_TO "Resources" FILES ${ios_res_files})
set(apple_src_files ${ios_code_files} ${ios_res_files})
elseif(MACOSX)
set(MAC_SRC ${MAC_SRC} proj.ios_mac/mac/main.cpp)
file(GLOB_RECURSE RES_ICON proj.ios_mac/mac/Icon.icns)
cocos_mark_resources(FILES ${RES_ICON} BASEDIR proj.ios_mac/mac)
set(APPLE_SRC ${MAC_SRC} ${RES_ICON})
set(mac_code_files proj.ios_mac/mac/main.cpp)
set(mac_res_files
${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Icon.icns
)
cocos_mark_multi_resources(mac_res_files RES_TO "Resources" FILES ${mac_res_files})
set(apple_src_files ${mac_res_files} ${mac_code_files})
endif()
file(GLOB_RECURSE APP_RESOURCES ../res/*)
# need review, Resources/res -> Resources
cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources)
file(GLOB_RECURSE APP_SCRIPTS ../src/*)
cocos_mark_resources(FILES ${APP_SCRIPTS} BASEDIR ../src RESOURCEBASE Resources/src)
file(GLOB_RECURSE COCOS_SCRIPTS ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/*)
cocos_mark_resources(FILES ${COCOS_SCRIPTS} BASEDIR ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script RESOURCEBASE Resources/src/cocos)
file(GLOB_RECURSE TEST_RESOURCES ${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources/*)
# need review
cocos_mark_resources(FILES ${TEST_RESOURCES} BASEDIR ${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources RESOURCEBASE Resources)
list(APPEND SAMPLE_SRC ${APPLE_SRC} ${APP_RESOURCES} ${APP_SCRIPTS} ${COCOS_SCRIPTS} ${TEST_RESOURCES})
elseif(ANDROID)
list(APPEND SAMPLE_SRC proj.android/app/jni/main.cpp)
set(RES_PREFIX "/Resources")
list(APPEND SAMPLE_SRC ${apple_src_files} ${cc_common_res})
endif()
include_directories(
@ -75,51 +76,30 @@ include_directories(
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/manual
${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/auto
${COCOS2DX_ROOT_PATH}/external/lua/tolua
)
)
include_directories(${LUAJIT_INCLUDE_DIRS})
if(ANDROID)
add_library(${APP_NAME} SHARED ${SAMPLE_SRC})
if(CMAKE_BUILD_TYPE MATCHES RELEASE)
add_custom_command(TARGET ${APP_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} lib${APP_NAME}.so)
endif()
target_link_libraries(${APP_NAME} -Wl,-whole-archive cocos2d_android -Wl,-no-whole-archive)
add_dependencies(${APP_NAME} cocos2d_android)
else()
# add the executable
add_executable(${APP_NAME} ${SAMPLE_SRC})
endif()
target_link_libraries(${APP_NAME} luacocos2d)
add_dependencies(${APP_NAME} luacocos2d)
# mark app complie info and libs info
cocos_build_app(${APP_NAME}
APP_SRC "${SAMPLE_SRC}"
DEPEND_COMMON_LIBS "luacocos2d" "cocos2d"
DEPEND_ANDROID_LIBS "cocos2d_android"
)
# mark app resources
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
if(MACOSX)
cocos_pak_xcode(${APP_NAME} BUNDLE_NAME "LuaTestsApp")
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
endif()
else()
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin/${APP_NAME}")
set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}")
pre_build(${APP_NAME}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../res ${APP_BIN_DIR}${RES_PREFIX}/res
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/src
COMMAND ${CMAKE_COMMAND} -E copy_directory ${COCOS2DX_ROOT_PATH}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos
COMMAND ${CMAKE_COMMAND} -E copy_directory ${COCOS2DX_ROOT_PATH}/tests/cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res
)
elseif(WINDOWS)
cocos_copy_target_dll(${APP_NAME} COPY_TO ${APP_BIN_DIR})
endif()
if(XCODE OR VS)
cocos_mark_code_files(${APP_NAME})
endif()
if(LINUX OR WINDOWS)
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/res FOLDERS ${res_res_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src FOLDERS ${res_src_folders})
cocos_copy_target_res(${APP_NAME} COPY_TO ${APP_RES_DIR}/src/cocos FOLDERS ${res_script_folders})
endif()

View File

@ -24,9 +24,15 @@ android {
}
else if (PROP_NDK_MODE == 'cmake') {
cmake {
targets 'lua_tests'
arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", \
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE"
"-DUSE_CHIPMUNK=TRUE", "-DUSE_BULLET=TRUE", "-DUSE_LUACOCOS2D=TRUE"
cppFlags "-frtti -fexceptions"
// prebuilt root must be defined as a directory which you have right to access or create if you use prebuilt
// set "-DGEN_COCOS_PREBUILT=ON" and "-DUSE_COCOS_PREBUILT=OFF" to generate prebuilt, this way build cocos2d-x libs
// set "-DGEN_COCOS_PREBUILT=OFF" and "-DUSE_COCOS_PREBUILT=ON" to use prebuilt, this way not build cocos2d-x libs
//arguments "-DCOCOS_PREBUILT_ROOT=/Users/laptop/cocos-prebuilt"
//arguments "-DGEN_COCOS_PREBUILT=OFF", "-DUSE_COCOS_PREBUILT=OFF"
}
}
}

View File

@ -38,7 +38,7 @@ PROP_APP_ABI=armeabi-v7a
# android cmake support
# uncomment it, native code will build by cmake
# keep comment, native code will build by ndkBuild
# PROP_NDK_MODE=cmake
PROP_NDK_MODE=cmake
# uncomment it and fill in sign information for release mode
#RELEASE_STORE_FILE=file path of keystore

View File

@ -0,0 +1,132 @@
#/****************************************************************************
# Copyright (c) 2014-2017 Chukong Technologies Inc.
#
# http://www.cocos2d-x.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# ****************************************************************************/
set(SIMULATOR_LIB_PATH ${COCOS2DX_ROOT_PATH}/tools/simulator/libsimulator/lib)
if(MACOSX)
# add define for mac os GLFW_EXPOSE_NATIVE_NSGL
add_definitions(-DGLFW_EXPOSE_NATIVE_NSGL)
elseif(WINDOWS)
add_definitions(-DUNICODE -D_UNICODE)
add_definitions(-D_USRLIBSIMSTATIC -DGLFW_EXPOSE_NATIVE_WIN32 -D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS)
include_directories(${SIMULATOR_LIB_PATH}/../proj.win32)
endif()
if(WIN32)
set(PLATFORM_SRC
${SIMULATOR_LIB_PATH}/../proj.win32/Runtime_win32.cpp
${SIMULATOR_LIB_PATH}/../proj.win32/stdafx.cpp
${SIMULATOR_LIB_PATH}/platform/win32/DeviceEx-win32.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerEditBoxServiceWin.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerFileDialogServiceWin.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerMenuServiceWin.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerMessageBoxServiceWin.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerTaskServiceWin.cpp
${SIMULATOR_LIB_PATH}/platform/win32/PlayerWin.cpp
# ${SIMULATOR_LIB_PATH}/platform/win32/SimulatorWin.cpp
)
elseif(MACOSX)
set(PLATFORM_SRC
${SIMULATOR_LIB_PATH}/platform/mac/DeviceEx-mac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerEditBoxServiceMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerFileDialogServiceMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerMenuServiceMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerMessageBoxServiceMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/PlayerTaskServiceMac.mm
${SIMULATOR_LIB_PATH}/platform/mac/Runtime_ios-mac.mm
${SIMULATOR_LIB_PATH}/platform/mac/openudid/OpenUDIDMac.m
)
endif()
set(PROTOBUF_SRC
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/extension_set.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/generated_message_util.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/io/coded_stream.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/io/zero_copy_stream.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/io/zero_copy_stream_impl_lite.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/message_lite.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/repeated_field.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/stubs/atomicops_internals_x86_msvc.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/stubs/common.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/stubs/once.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/stubs/stringprintf.cc
${SIMULATOR_LIB_PATH}/protobuf-lite/google/protobuf/wire_format_lite.cc
)
set(SIMELATOR_SRC
${SIMULATOR_LIB_PATH}/network/CCHTTPRequest.cpp
${SIMULATOR_LIB_PATH}/ProjectConfig/ProjectConfig.cpp
${SIMULATOR_LIB_PATH}/ProjectConfig/SimulatorConfig.cpp
${SIMULATOR_LIB_PATH}/AppEvent.cpp
${SIMULATOR_LIB_PATH}/AppLang.cpp
${SIMULATOR_LIB_PATH}/PlayerMenuServiceProtocol.cpp
${SIMULATOR_LIB_PATH}/PlayerProtocol.cpp
${SIMULATOR_LIB_PATH}/PlayerServiceProtocol.cpp
${SIMULATOR_LIB_PATH}/PlayerSettings.cpp
${SIMULATOR_LIB_PATH}/PlayerTaskServiceProtocol.cpp
${SIMULATOR_LIB_PATH}/PlayerUtils.cpp
${SIMULATOR_LIB_PATH}/runtime/ConfigParser.cpp
${SIMULATOR_LIB_PATH}/runtime/ConnectWaitLayer.cpp
${SIMULATOR_LIB_PATH}/runtime/ConsoleCommand.cpp
${SIMULATOR_LIB_PATH}/runtime/FileServer.cpp
${SIMULATOR_LIB_PATH}/runtime/Landscape_png.cpp
${SIMULATOR_LIB_PATH}/runtime/PlayDisable_png.cpp
${SIMULATOR_LIB_PATH}/runtime/PlayEnable_png.cpp
${SIMULATOR_LIB_PATH}/runtime/Portrait_png.cpp
${SIMULATOR_LIB_PATH}/runtime/Protos.pb.cc
${SIMULATOR_LIB_PATH}/runtime/Runtime.cpp
${SIMULATOR_LIB_PATH}/runtime/RuntimeCCSImpl.cpp
${SIMULATOR_LIB_PATH}/runtime/RuntimeProtocol.cpp
${SIMULATOR_LIB_PATH}/runtime/Shine_png.cpp
${SIMULATOR_LIB_PATH}/runtime/VisibleRect.cpp
${PROTOBUF_SRC}
${PLATFORM_SRC}
)
include_directories(
${SIMULATOR_LIB_PATH}
${SIMULATOR_LIB_PATH}/platform/${PLATFORM_FOLDER}
${SIMULATOR_LIB_PATH}/protobuf-lite
${SIMULATOR_LIB_PATH}/runtime
${COCOS2DX_ROOT_PATH}/cocos/editor-support
)
add_library(simulator STATIC
${SIMELATOR_SRC}
)
target_use_simulator_depend_libs(simulator)
set_target_properties(simulator
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
FOLDER "Internal"
)
if(XCODE OR VS)
cocos_mark_code_files("simulator")
endif()

View File

@ -22,7 +22,7 @@
THE SOFTWARE.
****************************************************************************/
#import <AppKit/AppKit.h>
#include "PlayerFileDialogServiceMac.h"
#include "glfw3.h"

View File

@ -26,6 +26,7 @@
#ifndef __PLAYER_MessageBoxServiceMac_h
#define __PLAYER_MessageBoxServiceMac_h
#import <AppKit/AppKit.h>
#include <vector>
#include "PlayerMacros.h"

View File

@ -32,6 +32,7 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
#include <algorithm>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stl_util.h>

View File

@ -93,6 +93,21 @@ function install_python_module_for_osx()
sudo -H pip install Cheetah
}
# fix error, URLError: <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION]
function upgrade_openssl_for_osx()
{
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew upgrade openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/Cellar/openssl/1.0.2n/bin/openssl /usr/local/bin/openssl
echo "macOS SSL: `openssl version`"
brew install python2 --with-brewed-openssl
ln -s /usr/local/opt/python@2/bin/python2 /usr/local/bin/python
echo "python SSL: `python -c "import ssl; print ssl.OPENSSL_VERSION"`"
}
# set up environment according os and target
function install_environement_for_pull_request()
{
@ -109,6 +124,7 @@ function install_environement_for_pull_request()
fi
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
upgrade_openssl_for_osx
install_python_module_for_osx
fi
@ -125,6 +141,7 @@ function install_environement_for_after_merge()
download_deps
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
upgrade_openssl_for_osx
install_python_module_for_osx
fi
}