Merge pull request #10223 from vovkasm/cmake-msvc-fixes-core

Cmake build system fixes for MSVC (partial)
This commit is contained in:
Nite Luo 2015-02-04 23:18:08 -08:00
commit ee2781e6a6
5 changed files with 50 additions and 19 deletions

View File

@ -29,6 +29,12 @@ cmake_minimum_required(VERSION 2.8)
# also from cmake's Modules dir, to not clash with per-project files.
cmake_policy(SET CMP0017 NEW)
# Use new behaviour with cmake >= 3.0:
# Only interpret if() arguments as variables or keywords when unquoted.
if(CMAKE_VERSION VERSION_GREATER 3)
cmake_policy(SET CMP0054 NEW)
endif()
project (Cocos2d-X)
# The version number
@ -49,6 +55,16 @@ if(MINGW)
set(USE_PREBUILT_LIBS_DEFAULT OFF)
endif()
set(BUILD_CPP_TESTS_DEFAULT ON)
set(BUILD_LUA_LIBS_DEFAULT ON)
set(BUILD_LUA_TESTS_DEFAULT ON)
# TODO: fix test samples for MSVC
if(MSVC)
set(BUILD_CPP_TESTS_DEFAULT OFF)
set(BUILD_LUA_LIBS_DEFAULT OFF)
set(BUILD_LUA_TESTS_DEFAULT OFF)
endif()
option(USE_CHIPMUNK "Use chipmunk for physics library" ON)
option(USE_BOX2D "Use box2d for physics library" OFF)
option(USE_WEBP "Use WebP codec" ${USE_WEBP_DEFAULT})
@ -58,9 +74,9 @@ 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)
option(BUILD_EDITOR_COCOSBUILDER "Build editor support for cocosbuilder" ON)
option(BUILD_CPP_TESTS "Build TestCpp samples" ON)
option(BUILD_LUA_LIBS "Build lua libraries" ON)
option(BUILD_LUA_TESTS "Build TestLua samples" ON)
option(BUILD_CPP_TESTS "Build TestCpp samples" ${BUILD_CPP_TESTS_DEFAULT})
option(BUILD_LUA_LIBS "Build lua libraries" ${BUILD_LUA_LIBS_DEFAULT})
option(BUILD_LUA_TESTS "Build TestLua samples" ${BUILD_LUA_TESTS_DEFAULT})
option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT})
if(USE_PREBUILT_LIBS AND MINGW)
@ -81,6 +97,14 @@ if(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
-wd4514 -wd4056 -wd4996 -wd4099)
# 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()
else()
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
@ -150,12 +174,14 @@ if(USE_PREBUILT_LIBS)
include(CocosUsePrebuiltLibs)
endif()
# GLFW3 used on Mac, Windows and Linux desktop platforms
# desktop platforms
if(LINUX OR MACOSX OR WINDOWS)
cocos_find_package(OpenGL OPENGL 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()
cocos_find_package(GLFW3 GLFW3 REQUIRED)
@ -236,9 +262,11 @@ cocos_find_package(ZLIB ZLIB REQUIRED)
# moreover our embedded version modified to quick provide
# functionality needed by cocos.
if(USE_PREBUILT_LIBS OR NOT MINGW)
#TODO: hack! should be in external/unzip/CMakeLists.txt
include_directories(${ZLIB_INCLUDE_DIRS})
add_subdirectory(external/unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip)
set(MINIZIP_LIBRARIES unzip)
set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/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)
@ -261,10 +289,10 @@ set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
# build for 3rd party libraries
if(LINUX OR APPLE)
# build xxhash
add_subdirectory(external/xxhash)
endif()
set(XXHASH_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/xxhash)
set(XXHASH_LIBRARIES xxhash)
# libcocos2d.a
add_subdirectory(cocos)

View File

@ -36,7 +36,7 @@ set(_sqlite3_inc sqlite3.h)
set(_sqlite3_libs sqlite3)
set(_gles_prefix GLEW)
set(_gles_inc glew.h)
set(_gles_inc GL/glew.h)
set(_gles_inc_paths OGLES)
set(_gles_libs glew32)

View File

@ -79,9 +79,7 @@ set(COCOS_SRC cocos2d.cpp
)
#todo: provide prebuild versions of the xx libs for all platforms
include_directories(
../external/xxhash
../external/xxtea)
include_directories(../external/xxtea)
add_library(cocos2d ${COCOS_SRC})
@ -127,11 +125,11 @@ else()
message( FATAL_ERROR "Unsupported platform, CMake will exit" )
endif()
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS)
foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL FLATBUFFERS XXHASH)
cocos_use_pkg(cocos2d ${pkg})
endforeach()
target_link_libraries(cocos2d xxhash ${PLATFORM_SPECIFIC_LIBS})
target_link_libraries(cocos2d ${PLATFORM_SPECIFIC_LIBS})
if(USE_WEBP)
add_definitions(-DCC_USE_WEBP=1)

View File

@ -1,9 +1,5 @@
set(cocos_root ${Cocos2d-X_SOURCE_DIR})
if(WINDOWS)
add_definitions(-DLUASOCKET_INET_ATON -DLUASOCKET_INET_PTON)
endif()
include_directories(
${cocos_root}/external/lua/tolua
${cocos_root}/external/lua/lua
@ -53,6 +49,10 @@ list(APPEND lua_cocos2d_source_files
)
if(WINDOWS)
if(MINGW)
add_definitions(-DLUASOCKET_INET_ATON -DLUASOCKET_INET_PTON)
endif()
add_definitions(-DWIN32 -D_WINDOWS)
list(APPEND lua_cocos2d_source_files
${cocos_root}/external/lua/luasocket/wsocket.c
)

View File

@ -1,5 +1,8 @@
set(APP_NAME cpp-tests)
# Use same method as in cocos library
cocos_find_package(CURL CURL REQUIRED)
if(WIN32)
set(PLATFORM_SRC proj.win32/main.cpp)
set(RES_PREFIX "")
@ -252,6 +255,8 @@ target_link_libraries(${APP_NAME}
cocos2d
)
cocos_use_pkg(${APP_NAME} CURL)
if(MACOSX OR APPLE)
set_target_properties(${APP_NAME} PROPERTIES
MACOSX_BUNDLE 1