From c2b97a3b1352d7ba42205983b4883a610a7defe2 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Fri, 7 Nov 2014 09:13:59 +0800 Subject: [PATCH 01/67] fix sprite frame cache, and remove unnecessary headers dependencies. we should add private headers for ccs, do not expose privae headers to users. --- .../cocostudio/CCArmatureDataManager.cpp | 2 +- .../cocostudio/CCDisplayFactory.cpp | 1 - cocos/editor-support/cocostudio/CCSkin.cpp | 3 +- .../cocostudio/CCSpriteFrameCacheHelper.cpp | 47 ++++++++++++++++++- .../cocostudio/CCSpriteFrameCacheHelper.h | 10 ++++ cocos/editor-support/cocostudio/CocoStudio.h | 1 - 6 files changed, 58 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 8b1a492f29..9f798ba84d 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -111,7 +111,7 @@ void ArmatureDataManager::removeArmatureFileInfo(const std::string& configFilePa for (std::string str : data->plistFiles) { - SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(str.c_str()); + SpriteFrameCacheHelper::getInstance()->removeSpriteFrameFromFile(str); } _relativeDatas.erase(configFilePath); diff --git a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp index d995d55c1b..43c483c919 100644 --- a/cocos/editor-support/cocostudio/CCDisplayFactory.cpp +++ b/cocos/editor-support/cocostudio/CCDisplayFactory.cpp @@ -26,7 +26,6 @@ THE SOFTWARE. #include "cocostudio/CCBone.h" #include "cocostudio/CCArmature.h" #include "cocostudio/CCSkin.h" -#include "cocostudio/CCSpriteFrameCacheHelper.h" #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCTransformHelp.h" diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index f83cdc0296..392d4e5f4c 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -29,7 +29,6 @@ THE SOFTWARE. #include "cocostudio/CCSkin.h" #include "cocostudio/CCTransformHelp.h" -#include "cocostudio/CCSpriteFrameCacheHelper.h" #include "cocostudio/CCArmature.h" @@ -222,7 +221,7 @@ Mat4 Skin::getNodeToWorldTransformAR() const void Skin::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { - auto mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + Mat4 mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); //TODO: implement z order _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, mv); diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp index 3b7ec3f0e7..dd594da776 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp @@ -23,7 +23,8 @@ THE SOFTWARE. ****************************************************************************/ #include "cocostudio/CCSpriteFrameCacheHelper.h" - +#include "platform/CCFileUtils.h" +#include "2d/CCSpriteFrame.h" #include "2d/CCSpriteFrameCache.h" using namespace cocos2d; @@ -49,9 +50,53 @@ void SpriteFrameCacheHelper::purge() _spriteFrameCacheHelper = nullptr; } +void SpriteFrameCacheHelper::_retainSpriteFrames(const std::string &plistPath) +{ + auto it = _usingSpriteFrames.find(plistPath); + if(it != _usingSpriteFrames.end()) return; + + std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plistPath); + ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath); + auto spriteFramesCache = SpriteFrameCache::getInstance(); + ValueMap& framesDict = dict["frames"].asValueMap(); + + std::vector vec; + for (auto iter = framesDict.begin(); iter != framesDict.end(); ++iter) + { + auto& spriteFrameName = iter->first; + SpriteFrame* spriteFrame = spriteFramesCache->getSpriteFrameByName(spriteFrameName); + vec.push_back(spriteFrame); + CC_SAFE_RETAIN(spriteFrame); + } + _usingSpriteFrames[plistPath] = vec; +} + +void SpriteFrameCacheHelper::_releaseSpriteFrames(const std::string &plistPath) +{ + auto it = _usingSpriteFrames.find(plistPath); + if(it == _usingSpriteFrames.end()) return; + + auto& vec = it->second; + auto itFrame = vec.begin(); + while (itFrame != vec.end()) + { + CC_SAFE_RELEASE(*itFrame); + ++itFrame; + } + vec.clear(); + _usingSpriteFrames.erase(it); +} + +void SpriteFrameCacheHelper::removeSpriteFrameFromFile(const std::string &plistPath) +{ + SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(plistPath); + _releaseSpriteFrames(plistPath); +} + void SpriteFrameCacheHelper::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); + _retainSpriteFrames(plistPath); } SpriteFrameCacheHelper::SpriteFrameCacheHelper() diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h index 20db0f5aba..e9dae4e434 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h @@ -28,6 +28,11 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CocosStudioExport.h" #include +#include + +namespace cocos2d { + class SpriteFrame; +} namespace cocostudio { @@ -50,11 +55,16 @@ public: * @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name */ void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath); + void removeSpriteFrameFromFile(const std::string& plistPath); private: + void _retainSpriteFrames(const std::string& plistPath); + void _releaseSpriteFrames(const std::string& plistPath); + SpriteFrameCacheHelper(); ~SpriteFrameCacheHelper(); + std::map > _usingSpriteFrames; static SpriteFrameCacheHelper *_spriteFrameCacheHelper; }; diff --git a/cocos/editor-support/cocostudio/CocoStudio.h b/cocos/editor-support/cocostudio/CocoStudio.h index ba61c83d17..8a17a193eb 100644 --- a/cocos/editor-support/cocostudio/CocoStudio.h +++ b/cocos/editor-support/cocostudio/CocoStudio.h @@ -45,7 +45,6 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDataManager.h" #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CCDataReaderHelper.h" -#include "cocostudio/CCSpriteFrameCacheHelper.h" #include "cocostudio/CCTransformHelp.h" #include "cocostudio/CCUtilMath.h" #include "cocostudio/CCComBase.h" From b682438b68d6c32546de8cacd09a5c4c17e9a2dc Mon Sep 17 00:00:00 2001 From: joewanchen Date: Fri, 7 Nov 2014 09:17:32 +0800 Subject: [PATCH 02/67] revert some modifications. --- cocos/editor-support/cocostudio/CCSkin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index 392d4e5f4c..8c355bda3c 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -221,7 +221,7 @@ Mat4 Skin::getNodeToWorldTransformAR() const void Skin::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { - Mat4 mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + auto mv = Director::getInstance()->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); //TODO: implement z order _quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, mv); From b05f558214ed87941e2ce52d1ffff129c4ce65e6 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Fri, 7 Nov 2014 10:14:07 +0800 Subject: [PATCH 03/67] fix compile error. --- cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h index e9dae4e434..005192e5d9 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h @@ -28,6 +28,7 @@ THE SOFTWARE. #include "cocostudio/CCArmatureDefine.h" #include "cocostudio/CocosStudioExport.h" #include +#include #include namespace cocos2d { From c4b1aeb0ec32cf8337dd0399a260a92217a77436 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Fri, 7 Nov 2014 11:43:55 +0800 Subject: [PATCH 04/67] fix momery leak (partly fix, memory leak still exist). --- cocos/editor-support/cocostudio/CCArmatureDataManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp index 9f798ba84d..d0d7639a6e 100644 --- a/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp +++ b/cocos/editor-support/cocostudio/CCArmatureDataManager.cpp @@ -210,7 +210,7 @@ void ArmatureDataManager::addArmatureFileInfo(const std::string& imagePath, cons _autoLoadSpriteFile = false; DataReaderHelper::getInstance()->addDataFromFile(configFilePath); - addSpriteFrameFromFile(plistPath, imagePath); + addSpriteFrameFromFile(plistPath, imagePath, configFilePath); } void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, Ref *target, SEL_SCHEDULE selector) @@ -219,7 +219,7 @@ void ArmatureDataManager::addArmatureFileInfoAsync(const std::string& imagePath, _autoLoadSpriteFile = false; DataReaderHelper::getInstance()->addDataFromFileAsync(imagePath, plistPath, configFilePath, target, selector); - addSpriteFrameFromFile(plistPath, imagePath); + addSpriteFrameFromFile(plistPath, imagePath, configFilePath); } void ArmatureDataManager::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath) From 7c355a087b3802f2acc66d527d0b0565bd28634b Mon Sep 17 00:00:00 2001 From: teivaz Date: Tue, 11 Nov 2014 21:09:58 +0200 Subject: [PATCH 05/67] - Optimization in CCClippingNode. Disable visiting when no objects has to be drawn under stencil. --- cocos/2d/CCClippingNode.cpp | 7 ++++++- cocos/2d/CCClippingNode.h | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index 17aea6026d..d72ffa6c74 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -231,7 +231,7 @@ void ClippingNode::drawFullScreenQuadClearStencil() void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { - if(!_visible) + if (!_visible || !hasContent()) return; uint32_t flags = processParentFlags(parentTransform, parentFlags); @@ -327,6 +327,11 @@ void ClippingNode::setStencil(Node *stencil) _stencil = stencil; } +bool ClippingNode::hasContent() +{ + return _children.size() > 0; +} + GLfloat ClippingNode::getAlphaThreshold() const { return _alphaThreshold; diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index ba9301e590..ad098465f5 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -58,7 +58,14 @@ public: */ Node* getStencil() const; void setStencil(Node *stencil); - + + /** If stencil has no childre it will not be drawn. + If you have custom stencil-based node with stencil drawing mechanics other then children-based, + then this method should return true every time you wish stencil to be visited. + By default returns true if has any children attached. + */ + virtual bool hasContent(); + /** The alpha threshold. The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold. Should be a float between 0 and 1. From e8d24cb49b84a370e856789d30b84a06c832f218 Mon Sep 17 00:00:00 2001 From: wangqm0513 Date: Wed, 12 Nov 2014 14:15:29 +0800 Subject: [PATCH 06/67] Update MathUtilNeon64.inl add arm64bit neon support --- cocos/math/MathUtilNeon64.inl | 298 +++++++++++++++++++--------------- 1 file changed, 167 insertions(+), 131 deletions(-) diff --git a/cocos/math/MathUtilNeon64.inl b/cocos/math/MathUtilNeon64.inl index 8e868798ef..c6fdd70b24 100644 --- a/cocos/math/MathUtilNeon64.inl +++ b/cocos/math/MathUtilNeon64.inl @@ -46,173 +46,209 @@ public: inline void MathUtilNeon64::addMatrix(const float* m, float scalar, float* dst) { - dst[0] = m[0] + scalar; - dst[1] = m[1] + scalar; - dst[2] = m[2] + scalar; - dst[3] = m[3] + scalar; - dst[4] = m[4] + scalar; - dst[5] = m[5] + scalar; - dst[6] = m[6] + scalar; - dst[7] = m[7] + scalar; - dst[8] = m[8] + scalar; - dst[9] = m[9] + scalar; - dst[10] = m[10] + scalar; - dst[11] = m[11] + scalar; - dst[12] = m[12] + scalar; - dst[13] = m[13] + scalar; - dst[14] = m[14] + scalar; - dst[15] = m[15] + scalar; + asm volatile( + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1] \n\t" // M[m0-m7] M[m8-m15] + "ld1r {v4.4s}, [%2] \n\t" //ssss + + "fadd v8.4s, v0.4s, v4.4s \n\t" // DST->M[m0-m3] = M[m0-m3] + s + "fadd v9.4s, v1.4s, v4.4s \n\t" // DST->M[m4-m7] = M[m4-m7] + s + "fadd v10.4s, v2.4s, v4.4s \n\t" // DST->M[m8-m11] = M[m8-m11] + s + "fadd v11.4s, v3.4s, v4.4s \n\t" // DST->M[m12-m15] = M[m12-m15] + s + + "st4 {v8.4s, v9.4s, v10.4s, v11.4s}, [%0] \n\t" // Result in V9 + : + : "r"(dst), "r"(m), "r"(&scalar) + : "v0", "v1", "v2", "v3", "v4", "v8", "v9", "v10", "v11", "memory" + ); } inline void MathUtilNeon64::addMatrix(const float* m1, const float* m2, float* dst) { - dst[0] = m1[0] + m2[0]; - dst[1] = m1[1] + m2[1]; - dst[2] = m1[2] + m2[2]; - dst[3] = m1[3] + m2[3]; - dst[4] = m1[4] + m2[4]; - dst[5] = m1[5] + m2[5]; - dst[6] = m1[6] + m2[6]; - dst[7] = m1[7] + m2[7]; - dst[8] = m1[8] + m2[8]; - dst[9] = m1[9] + m2[9]; - dst[10] = m1[10] + m2[10]; - dst[11] = m1[11] + m2[11]; - dst[12] = m1[12] + m2[12]; - dst[13] = m1[13] + m2[13]; - dst[14] = m1[14] + m2[14]; - dst[15] = m1[15] + m2[15]; + asm volatile( + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1] \n\t" // M1[m0-m7] M1[m8-m15] + "ld4 {v8.4s, v9.4s, v10.4s, v11.4s}, [%2] \n\t" // M2[m0-m7] M2[m8-m15] + + "fadd v12.4s, v0.4s, v8.4s \n\t" // DST->M[m0-m3] = M1[m0-m3] + M2[m0-m3] + "fadd v13.4s, v1.4s, v9.4s \n\t" // DST->M[m4-m7] = M1[m4-m7] + M2[m4-m7] + "fadd v14.4s, v2.4s, v10.4s \n\t" // DST->M[m8-m11] = M1[m8-m11] + M2[m8-m11] + "fadd v15.4s, v3.4s, v11.4s \n\t" // DST->M[m12-m15] = M1[m12-m15] + M2[m12-m15] + + "st4 {v12.4s, v13.4s, v14.4s, v15.4s}, [%0] \n\t" // DST->M[m0-m7] DST->M[m8-m15] + : + : "r"(dst), "r"(m1), "r"(m2) + : "v0", "v1", "v2", "v3", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "memory" + ); } inline void MathUtilNeon64::subtractMatrix(const float* m1, const float* m2, float* dst) { - dst[0] = m1[0] - m2[0]; - dst[1] = m1[1] - m2[1]; - dst[2] = m1[2] - m2[2]; - dst[3] = m1[3] - m2[3]; - dst[4] = m1[4] - m2[4]; - dst[5] = m1[5] - m2[5]; - dst[6] = m1[6] - m2[6]; - dst[7] = m1[7] - m2[7]; - dst[8] = m1[8] - m2[8]; - dst[9] = m1[9] - m2[9]; - dst[10] = m1[10] - m2[10]; - dst[11] = m1[11] - m2[11]; - dst[12] = m1[12] - m2[12]; - dst[13] = m1[13] - m2[13]; - dst[14] = m1[14] - m2[14]; - dst[15] = m1[15] - m2[15]; + asm volatile( + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1] \n\t" // M1[m0-m7] M1[m8-m15] + "ld4 {v8.4s, v9.4s, v10.4s, v11.4s}, [%2] \n\t" // M2[m0-m7] M2[m8-m15] + + "fsub v12.4s, v0.4s, v8.4s \n\t" // DST->M[m0-m3] = M1[m0-m3] - M2[m0-m3] + "fsub v13.4s, v1.4s, v9.4s \n\t" // DST->M[m4-m7] = M1[m4-m7] - M2[m4-m7] + "fsub v14.4s, v2.4s, v10.4s \n\t" // DST->M[m8-m11] = M1[m8-m11] - M2[m8-m11] + "fsub v15.4s, v3.4s, v11.4s \n\t" // DST->M[m12-m15] = M1[m12-m15] - M2[m12-m15] + + "st4 {v12.4s, v13.4s, v14.4s, v15.4s}, [%0] \n\t" // DST->M[m0-m7] DST->M[m8-m15] + : + : "r"(dst), "r"(m1), "r"(m2) + : "v0", "v1", "v2", "v3", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "memory" + ); } inline void MathUtilNeon64::multiplyMatrix(const float* m, float scalar, float* dst) { - dst[0] = m[0] * scalar; - dst[1] = m[1] * scalar; - dst[2] = m[2] * scalar; - dst[3] = m[3] * scalar; - dst[4] = m[4] * scalar; - dst[5] = m[5] * scalar; - dst[6] = m[6] * scalar; - dst[7] = m[7] * scalar; - dst[8] = m[8] * scalar; - dst[9] = m[9] * scalar; - dst[10] = m[10] * scalar; - dst[11] = m[11] * scalar; - dst[12] = m[12] * scalar; - dst[13] = m[13] * scalar; - dst[14] = m[14] * scalar; - dst[15] = m[15] * scalar; + asm volatile( + "ld1 {v0.s}[0], [%2] \n\t" //s + "ld4 {v4.4s, v5.4s, v6.4s, v7.4s}, [%1] \n\t" //M[m0-m7] M[m8-m15] + + "fmul v8.4s, v4.4s, v0.s[0] \n\t" // DST->M[m0-m3] = M[m0-m3] * s + "fmul v9.4s, v5.4s, v0.s[0] \n\t" // DST->M[m4-m7] = M[m4-m7] * s + "fmul v10.4s, v6.4s, v0.s[0] \n\t" // DST->M[m8-m11] = M[m8-m11] * s + "fmul v11.4s, v7.4s, v0.s[0] \n\t" // DST->M[m12-m15] = M[m12-m15] * s + + "st4 {v8.4s, v9.4s, v10.4s, v11.4s}, [%0] \n\t" // DST->M[m0-m7] DST->M[m8-m15] + : + : "r"(dst), "r"(m), "r"(&scalar) + : "v0", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "memory" + ); } inline void MathUtilNeon64::multiplyMatrix(const float* m1, const float* m2, float* dst) { - // Support the case where m1 or m2 is the same array as dst. - float product[16]; - - product[0] = m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]; - product[1] = m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]; - product[2] = m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]; - product[3] = m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]; - - product[4] = m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]; - product[5] = m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]; - product[6] = m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]; - product[7] = m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]; - - product[8] = m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]; - product[9] = m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]; - product[10] = m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]; - product[11] = m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]; - - product[12] = m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]; - product[13] = m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]; - product[14] = m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]; - product[15] = m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]; - - memcpy(dst, product, MATRIX_SIZE); + asm volatile( + "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%1] \n\t" // M1[m0-m7] M1[m8-m15] M2[m0-m7] M2[m8-m15] + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%2] \n\t" // M2[m0-m15] + + + "fmul v12.4s, v8.4s, v0.s[0] \n\t" // DST->M[m0-m3] = M1[m0-m3] * M2[m0] + "fmul v13.4s, v8.4s, v0.s[1] \n\t" // DST->M[m4-m7] = M1[m4-m7] * M2[m4] + "fmul v14.4s, v8.4s, v0.s[2] \n\t" // DST->M[m8-m11] = M1[m8-m11] * M2[m8] + "fmul v15.4s, v8.4s, v0.s[3] \n\t" // DST->M[m12-m15] = M1[m12-m15] * M2[m12] + + "fmla v12.4s, v9.4s, v1.s[0] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m1] + "fmla v13.4s, v9.4s, v1.s[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m5] + "fmla v14.4s, v9.4s, v1.s[2] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m9] + "fmla v15.4s, v9.4s, v1.s[3] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m13] + + "fmla v12.4s, v10.4s, v2.s[0] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m2] + "fmla v13.4s, v10.4s, v2.s[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m6] + "fmla v14.4s, v10.4s, v2.s[2] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m10] + "fmla v15.4s, v10.4s, v2.s[3] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m14] + + "fmla v12.4s, v11.4s, v3.s[0] \n\t" // DST->M[m0-m3] += M1[m0-m3] * M2[m3] + "fmla v13.4s, v11.4s, v3.s[1] \n\t" // DST->M[m4-m7] += M1[m4-m7] * M2[m7] + "fmla v14.4s, v11.4s, v3.s[2] \n\t" // DST->M[m8-m11] += M1[m8-m11] * M2[m11] + "fmla v15.4s, v11.4s, v3.s[3] \n\t" // DST->M[m12-m15] += M1[m12-m15] * M2[m15] + + "st1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%0] \n\t" // DST->M[m0-m7]// DST->M[m8-m15] + + : // output + : "r"(dst), "r"(m1), "r"(m2) // input - note *value* of pointer doesn't change. + : "memory", "v0", "v1", "v2", "v3", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15" + ); } inline void MathUtilNeon64::negateMatrix(const float* m, float* dst) { - dst[0] = -m[0]; - dst[1] = -m[1]; - dst[2] = -m[2]; - dst[3] = -m[3]; - dst[4] = -m[4]; - dst[5] = -m[5]; - dst[6] = -m[6]; - dst[7] = -m[7]; - dst[8] = -m[8]; - dst[9] = -m[9]; - dst[10] = -m[10]; - dst[11] = -m[11]; - dst[12] = -m[12]; - dst[13] = -m[13]; - dst[14] = -m[14]; - dst[15] = -m[15]; + asm volatile( + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1] \n\t" // load m0-m7 load m8-m15 + + "fneg v4.4s, v0.4s \n\t" // negate m0-m3 + "fneg v5.4s, v1.4s \n\t" // negate m4-m7 + "fneg v6.4s, v2.4s \n\t" // negate m8-m15 + "fneg v7.4s, v3.4s \n\t" // negate m8-m15 + + "st4 {v4.4s, v5.4s, v6.4s, v7.4s}, [%0] \n\t" // store m0-m7 store m8-m15 + : + : "r"(dst), "r"(m) + : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "memory" + ); } inline void MathUtilNeon64::transposeMatrix(const float* m, float* dst) { - float t[16] = { - m[0], m[4], m[8], m[12], - m[1], m[5], m[9], m[13], - m[2], m[6], m[10], m[14], - m[3], m[7], m[11], m[15] - }; - memcpy(dst, t, MATRIX_SIZE); + asm volatile( + "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1] \n\t" // DST->M[m0, m4, m8, m12] = M[m0-m3] + //DST->M[m1, m5, m9, m12] = M[m4-m7] + "st1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0] \n\t" + : + : "r"(dst), "r"(m) + : "v0", "v1", "v2", "v3", "memory" + ); } inline void MathUtilNeon64::transformVec4(const float* m, float x, float y, float z, float w, float* dst) { - dst[0] = x * m[0] + y * m[4] + z * m[8] + w * m[12]; - dst[1] = x * m[1] + y * m[5] + z * m[9] + w * m[13]; - dst[2] = x * m[2] + y * m[6] + z * m[10] + w * m[14]; + asm volatile( + "ld1 {v0.s}[0], [%1] \n\t" // V[x] + "ld1 {v0.s}[1], [%2] \n\t" // V[y] + "ld1 {v0.s}[2], [%3] \n\t" // V[z] + "ld1 {v0.s}[3], [%4] \n\t" // V[w] + "ld1 {v9.4s, v10.4s, v11.4s, v12.4s}, [%5] \n\t" // M[m0-m7] M[m8-m15] + + + "fmul v13.4s, v9.4s, v0.s[0] \n\t" // DST->V = M[m0-m3] * V[x] + "fmla v13.4s, v10.4s, v0.s[1] \n\t" // DST->V += M[m4-m7] * V[y] + "fmla v13.4s, v11.4s, v0.s[2] \n\t" // DST->V += M[m8-m11] * V[z] + "fmla v13.4s, v12.4s, v0.s[3] \n\t" // DST->V += M[m12-m15] * V[w] + + //"st1 {v13.4s}, [%0] \n\t" // DST->V[x, y] // DST->V[z] + "st1 {v13.2s}, [%0], 8 \n\t" + "st1 {v13.s}[2], [%0] \n\t" + : + : "r"(dst), "r"(&x), "r"(&y), "r"(&z), "r"(&w), "r"(m) + : "v0", "v9", "v10","v11", "v12", "v13", "memory" + ); } inline void MathUtilNeon64::transformVec4(const float* m, const float* v, float* dst) { - // Handle case where v == dst. - float x = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12]; - float y = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13]; - float z = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14]; - float w = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15]; - - dst[0] = x; - dst[1] = y; - dst[2] = z; - dst[3] = w; + asm volatile + ( + "ld1 {v0.4s}, [%1] \n\t" // V[x, y, z, w] + "ld1 {v9.4s, v10.4s, v11.4s, v12.4s}, [%2] \n\t" // M[m0-m7] M[m8-m15] + + "fmul v13.4s, v9.4s, v0.s[0] \n\t" // DST->V = M[m0-m3] * V[x] + "fmla v13.4s, v10.4s, v0.s[1] \n\t" // DST->V = M[m4-m7] * V[y] + "fmla v13.4s, v11.4s, v0.s[2] \n\t" // DST->V = M[m8-m11] * V[z] + "fmla v13.4s, v12.4s, v0.s[3] \n\t" // DST->V = M[m12-m15] * V[w] + + "st1 {v13.4s}, [%0] \n\t" // DST->V + : + : "r"(dst), "r"(v), "r"(m) + : "v0", "v9", "v10","v11", "v12", "v13", "memory" + ); } inline void MathUtilNeon64::crossVec3(const float* v1, const float* v2, float* dst) { - float x = (v1[1] * v2[2]) - (v1[2] * v2[1]); - float y = (v1[2] * v2[0]) - (v1[0] * v2[2]); - float z = (v1[0] * v2[1]) - (v1[1] * v2[0]); - - dst[0] = x; - dst[1] = y; - dst[2] = z; + asm volatile( + "ld1 {v0.2s}, [%2] \n\t" // + "ld1 {v0.s}[3], [%1] \n\t" // + "mov v0.s[2], v0.s[1] \n\t" // q0 = (v1y, v1z, v1z, v1x) + + "ld1 {v1.s}[1], [%3] \n\t" // + "ld1 {v1.s}[2], [%4], 4 \n\t" // + "ld1 {v1.s}[3], [%4] \n\t" // + "mov v1.s[0], v1.s[3] \n\t" // q1 = (v2z, v2x, v2y, v2z) + + "fmul v2.4s, v0.4s, v1.4s \n\t" // x = v1y * v2z, y = v1z * v2x + "fsub s8, s8, s10 \n\t" + "fsub s9, s9, s11 \n\t" // x -= v1z * v2y, y-= v1x - v2z + + "fmul s10, s3, s6 \n\t" // z = v1x * v2y + "fmul s11, s0, s5 \n\t" // z-= v1y * vx + "fsub s10, s10, s11 \n\t" + + "st1 {v2.2s}, [%0], 8 \n\t" // V[x, y] + "st1 {v2.s}[2], [%0] \n\t" // V[z] + : + : "r"(dst), "r"(v1), "r"((v1+1)), "r"(v2), "r"((v2+1)) + : "v0", "v1", "v2", "memory" + ); } NS_CC_MATH_END From 2d75ceafb7533e543e09d35bac9c80bdc5efc7db Mon Sep 17 00:00:00 2001 From: teivaz Date: Thu, 13 Nov 2014 12:43:05 +0200 Subject: [PATCH 07/67] - set const modifier to ClippingNode::hasContent() --- cocos/2d/CCClippingNode.cpp | 2 +- cocos/2d/CCClippingNode.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCClippingNode.cpp b/cocos/2d/CCClippingNode.cpp index d72ffa6c74..4cb2180915 100644 --- a/cocos/2d/CCClippingNode.cpp +++ b/cocos/2d/CCClippingNode.cpp @@ -327,7 +327,7 @@ void ClippingNode::setStencil(Node *stencil) _stencil = stencil; } -bool ClippingNode::hasContent() +bool ClippingNode::hasContent() const { return _children.size() > 0; } diff --git a/cocos/2d/CCClippingNode.h b/cocos/2d/CCClippingNode.h index ad098465f5..9700681638 100644 --- a/cocos/2d/CCClippingNode.h +++ b/cocos/2d/CCClippingNode.h @@ -64,7 +64,7 @@ public: then this method should return true every time you wish stencil to be visited. By default returns true if has any children attached. */ - virtual bool hasContent(); + virtual bool hasContent() const; /** The alpha threshold. The content is drawn only where the stencil have pixel with alpha greater than the alphaThreshold. From ac0fb689896e1f114918208e1f3b9604b5604536 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Fri, 14 Nov 2014 15:04:32 +0800 Subject: [PATCH 08/67] fix compiling error caused by disable CC_ENABLE_SCRIPT_BINDING --- cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp | 10 ++++++---- cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp | 4 ++-- cocos/ui/UIEditBox/UIEditBoxImpl-wp8.cpp | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp index 2c60aa56cc..b1faaae802 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-win32.cpp @@ -690,14 +690,16 @@ void EditBoxImplWin::openKeyboard() { _delegate->editBoxEditingDidBegin(_editBox); } - - EditBox* pEditBox = this->getEditBox(); - if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) + +#if CC_ENABLE_SCRIPT_BINDING + auto editBox = this->getEditBox(); + if (editBox && editBox->getScriptEditBoxHandler()) { - CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox); + CommonScriptData data(editBox->getScriptEditBoxHandler(), "began",editBox); ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } +#endif std::string placeHolder = _labelPlaceHolder->getString(); if (placeHolder.length() == 0) diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp index 0086e7eab0..d30bb3c5a5 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-winrt.cpp @@ -330,7 +330,7 @@ void UIEditBoxImplWinrt::openKeyboard() { _delegate->editBoxEditingDidBegin(_editBox); } - +#if CC_ENABLE_SCRIPT_BINDING EditBox* pEditBox = this->getEditBox(); if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { @@ -338,7 +338,7 @@ void UIEditBoxImplWinrt::openKeyboard() ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } - +#endif std::string placeHolder = m_pLabelPlaceHolder->getString(); if (placeHolder.length() == 0) placeHolder = "Enter value"; diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-wp8.cpp b/cocos/ui/UIEditBox/UIEditBoxImpl-wp8.cpp index 892e53daf6..ceb918f2e0 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-wp8.cpp +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-wp8.cpp @@ -66,7 +66,7 @@ void UIEditBoxImplWp8::openKeyboard() { _delegate->editBoxEditingDidBegin(_editBox); } - +#if CC_ENABLE_SCRIPT_BINDING EditBox* pEditBox = this->getEditBox(); if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler()) { @@ -74,7 +74,7 @@ void UIEditBoxImplWp8::openKeyboard() ScriptEvent event(kCommonEvent,(void*)&data); ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event); } - +#endif std::string placeHolder = m_pLabelPlaceHolder->getString(); if (placeHolder.length() == 0) placeHolder = "Enter value"; From ddce662ec3866377f8cd9d7ef35f867bb697dc3a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 02:58:16 +0300 Subject: [PATCH 09/67] Unify usage of prebuilt libraries in cmake builds. * introduce config variable USE_PREBUILT_LIBS (default: ON). When OFF, cmake will not use prebuilt libs, only try find system installed libraries. * FindGLFW3.cmake now search our prebuilt library (if USE_PREBULT_LIBS) * FindFreetype.cmake also This and next changes should simplify our CMakeLists.txt files and USE_PREBUILT_LIBS config allow external package developers to integrate cocos to their packaging system. --- CMakeLists.txt | 16 ++- cmake/Modules/FindFreetype.cmake | 172 +++++++++++++++++++++++++++++++ cmake/Modules/FindGLFW3.cmake | 20 ++++ cocos/CMakeLists.txt | 33 ++---- 4 files changed, 205 insertions(+), 36 deletions(-) create mode 100644 cmake/Modules/FindFreetype.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 212ba9f946..5348423839 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,8 @@ 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(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON) + if(DEBUG_MODE) set(CMAKE_BUILD_TYPE DEBUG) else(DEBUG_MODE) @@ -160,15 +162,17 @@ include_directories( # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - list(APPEND CMAKE_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER}) - list(APPEND CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER_ARCH}) find_package(GLFW3 REQUIRED) - message( STATUS "GLFW3 dirs: ${GLFW3_INCLUDE_DIRS}") + message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) endif(LINUX OR MACOSX OR WINDOWS) +# Freetype required on all platforms +find_package(Freetype REQUIRED) +message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") +include_directories(${FREETYPE_INCLUDE_DIRS}) if(NOT MINGW) @@ -181,16 +185,11 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 ) -#todo: fix location of freetype includes for linux android on cocos prebuilt repo -#i.e we should not need to include an extra dir of /freetype2 - link_directories( ${PLATFORM_LINK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} @@ -198,7 +197,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake new file mode 100644 index 0000000000..1bf1dc8830 --- /dev/null +++ b/cmake/Modules/FindFreetype.cmake @@ -0,0 +1,172 @@ +#.rst: +# FindFreetype +# ------------ +# +# Locate FreeType library +# +# This module defines +# +# :: +# +# FREETYPE_LIBRARIES, the library to link against +# FREETYPE_FOUND, if false, do not try to link to FREETYPE +# FREETYPE_INCLUDE_DIRS, where to find headers. +# FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8) +# This is the concatenation of the paths: +# FREETYPE_INCLUDE_DIR_ft2build +# FREETYPE_INCLUDE_DIR_freetype2 +# +# +# +# $FREETYPE_DIR is an environment variable that would correspond to the +# ./configure --prefix=$FREETYPE_DIR used in building FREETYPE. + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Created by Eric Wing. +# Modifications by Alexander Neundorf. +# This file has been renamed to "FindFreetype.cmake" instead of the correct +# "FindFreeType.cmake" in order to be compatible with the one from KDE4, Alex. + +# Try find freetype for our arch in external folder +#todo: fix location of freetype includes for linux android on cocos prebuilt repo +#i.e we should not need to include an extra dir of /freetype2 + +if(USE_PREBUILT_LIBS) + find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 + NO_DEFAULT_PATH + ) + find_library(FREETYPE_LIBRARY + NAMES freetype libfreetype freetype219 freetype250 + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT FREETYPE_INCLUDE_DIR_ft2build OR NOT FREETYPE_INCLUDE_DIR_freetype2 OR NOT FREETYPE_LIBRARY) + unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) + unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) + unset(FREETYPE_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +# Ugh, FreeType seems to use some #include trickery which +# makes this harder than it should be. It looks like they +# put ft2build.h in a common/easier-to-find location which +# then contains a #include to a more specific header in a +# more specific location (#include ). +# Then from there, they need to set a bunch of #define's +# so you can do something like: +# #include FT_FREETYPE_H +# Unfortunately, using CMake's mechanisms like include_directories() +# wants explicit full paths and this trickery doesn't work too well. +# I'm going to attempt to cut out the middleman and hope +# everything still works. +find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h + HINTS + ENV FREETYPE_DIR + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + PATH_SUFFIXES include/freetype2 include +) + +find_path(FREETYPE_INCLUDE_DIR_freetype2 + NAMES + freetype/config/ftheader.h + config/ftheader.h + HINTS + ENV FREETYPE_DIR + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] + PATH_SUFFIXES include/freetype2 include +) + +find_library(FREETYPE_LIBRARY + NAMES freetype libfreetype freetype219 + HINTS + ENV FREETYPE_DIR + PATH_SUFFIXES lib + PATHS + /usr/X11R6 + /usr/local/X11R6 + /usr/local/X11 + /usr/freeware + ENV GTKMM_BASEPATH + [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\gtkmm\\2.4;Path] +) + +# set the user variables +if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) + set(FREETYPE_INCLUDE_DIRS "${FREETYPE_INCLUDE_DIR_ft2build};${FREETYPE_INCLUDE_DIR_freetype2}") + list(REMOVE_DUPLICATES FREETYPE_INCLUDE_DIRS) +endif() +set(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}") + +if(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") +elseif(EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") + set(FREETYPE_H "${FREETYPE_INCLUDE_DIR_freetype2}/freetype.h") +endif() + +if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) + file(STRINGS "${FREETYPE_H}" freetype_version_str + REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$") + + unset(FREETYPE_VERSION_STRING) + foreach(VPART MAJOR MINOR PATCH) + foreach(VLINE ${freetype_version_str}) + if(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}") + string(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1" + FREETYPE_VERSION_PART "${VLINE}") + if(FREETYPE_VERSION_STRING) + set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}") + else() + set(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}") + endif() + unset(FREETYPE_VERSION_PART) + endif() + endforeach() + endforeach() +endif() + + +# handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype + REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS + VERSION_VAR FREETYPE_VERSION_STRING) + +mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) diff --git a/cmake/Modules/FindGLFW3.cmake b/cmake/Modules/FindGLFW3.cmake index 07799b25cc..654b4eb9e7 100644 --- a/cmake/Modules/FindGLFW3.cmake +++ b/cmake/Modules/FindGLFW3.cmake @@ -27,6 +27,26 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +# Try find glfw for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(GLFW3_INCLUDE_DIR glfw3.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_library(GLFW3_LIBRARY + NAMES glfw3 libglfw3 lgfw + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT GLFW3_INCLUDE_DIR OR NOT GLFW3_LIBRARY) + unset(GLFW3_INCLUDE_DIR CACHE) + unset(GLFW3_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(GLFW3_INCLUDE_DIR glfw3.h HINTS ENV GLFW3_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 16aad5f9ed..f5e7104603 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,27 +81,7 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(MACOSX OR APPLE) - include(FindFreetype REQUIRED) - - if(NOT FREETYPE_FOUND) - if(IOS) - FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype PATHS "../external/freetype2/prebuilt/ios" DOC "Freetype includes") - find_path(FREETYPE_INCLUDE_DIRS ft2build.h "../external/freetype2/include/ios" "../external/freetype2/include/ios/freetype" DOC "Freetype includes") - - elseif() - FIND_LIBRARY(FREETYPE_LIBRARIES NAMES libfreetype PATHS "../external/freetype2/prebuilt/mac" DOC "Freetype includes") - find_path(FREETYPE_INCLUDE_DIRS ft2build.h "../external/freetype2/include/mac" "../external/freetype2/include/mac/freetype" DOC "Freetype includes") - endif(IOS) - endif(NOT FREETYPE_FOUND) - - find_package(Freetype REQUIRED) - include_directories(${FREETYPE_INCLUDE_DIRS}) - -endif() - if(MINGW) - find_package(Freetype REQUIRED) find_package(WebP REQUIRED) find_package(Protobuf REQUIRED) #find_package(MiniZip REQUIRED) @@ -113,11 +93,10 @@ if(MINGW) message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") message( STATUS "WEBP dirs: ${WEBP_INCLUDE_DIRS}") - message( STATUS "FREETYPE dirs: ${FREETYPE_INCLUDE_DIRS}") message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${FREETYPE_INCLUDE_DIRS} ${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -145,11 +124,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv freetype bz2) + set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets freetype250 glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff freetype curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -164,7 +143,7 @@ elseif(MACOSX OR APPLE) set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl - websockets freetype + websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -186,7 +165,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) set_target_properties(cocos2d PROPERTIES From 53d23ce5f3bb3ec6310e6225b48c0e5ed7f6d461 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 03:11:46 +0300 Subject: [PATCH 10/67] Unify WebP usage. --- CMakeLists.txt | 7 +++++-- cmake/Modules/FindWebP.cmake | 20 ++++++++++++++++++++ cocos/CMakeLists.txt | 14 ++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5348423839..0c65a2f757 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,6 +174,11 @@ find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") include_directories(${FREETYPE_INCLUDE_DIRS}) +# WebP required on all platforms +find_package(WebP REQUIRED) +message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") +include_directories(${WEBP_INCLUDE_DIRS}) + if(NOT MINGW) include_directories( @@ -184,7 +189,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src @@ -195,7 +199,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index 4b716f55b8..e885ffeb6d 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -27,6 +27,26 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +# Try find WebP for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(WEBP_INCLUDE_DIR decode.h + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + find_library(WEBP_LIBRARY + NAMES webp libwebp + PATHS + ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER} + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT WEBP_INCLUDE_DIR OR NOT WEBP_LIBRARY) + unset(WEBP_INCLUDE_DIR CACHE) + unset(WEBP_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(WEBP_INCLUDE_DIR decode.h HINTS ENV WEBP_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index f5e7104603..d332b45471 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -82,7 +82,6 @@ set(COCOS_SRC cocos2d.cpp ) if(MINGW) - find_package(WebP REQUIRED) find_package(Protobuf REQUIRED) #find_package(MiniZip REQUIRED) #${MINIZIP_INCLUDE_DIR} @@ -92,11 +91,10 @@ if(MINGW) find_package(Chipmunk REQUIRED) message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "WEBP dirs: ${WEBP_INCLUDE_DIRS}") message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${WEBP_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -124,11 +122,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png webp tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS z jpeg png tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libwebp libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg webp tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS jpeg tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -142,7 +140,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z jpeg png webp tiff curl + z jpeg png tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -165,7 +163,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${WEBP_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) set_target_properties(cocos2d PROPERTIES From aaff42d6a9bb96bedbeacf14b605f723256397ef Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 11:31:10 +0300 Subject: [PATCH 11/67] Fix WebP usage. * Introduce config variable USE_WEBP (ON by default, but disabled for unsupported archs WINRT and WP8) * Set CC_USE_WEBP define according to USE_WEBP variable * add WebP include directories to search patch only for libcocos compilation (it not used in public headers) --- CMakeLists.txt | 11 +++++++++-- cocos/CMakeLists.txt | 10 +++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c65a2f757..552ecf35ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,8 +34,14 @@ include(CocosBuildHelpers) message(${BUILDING_STRING}) +set(USE_WEBP_DEFAULT ON) +if(WINRT OR WP8) + set(USE_WEBP_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}) option(BUILD_STATIC "Build static libraries" ON) option(DEBUG_MODE "Debug or release?" ON) option(BUILD_EXTENSIONS "Build extension library" ON) @@ -174,10 +180,11 @@ find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") include_directories(${FREETYPE_INCLUDE_DIRS}) -# WebP required on all platforms +# WebP required if used +if(USE_WEBP) find_package(WebP REQUIRED) message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") -include_directories(${WEBP_INCLUDE_DIRS}) +endif() if(NOT MINGW) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index d332b45471..b4a597bc4f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -163,7 +163,15 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${WEBP_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) + +if(USE_WEBP) + add_definitions(-DCC_USE_WEBP=1) + include_directories(${WEBP_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${WEBP_LIBRARIES}) +else() + add_definitions(-DCC_USE_WEBP=0) +endif() set_target_properties(cocos2d PROPERTIES From eb0159b2b752e9b79362ed62e0d8c6169d3c3e89 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 13:17:23 +0300 Subject: [PATCH 12/67] Unify usage of chipmunk library * cmake/Modules/FindChipmunk.cmake now can find prebuilt chipmunk libs * follow USE_CHIPMUNK variable (although at the moment cocos can't build without chipmunk) * come cleanups and formatting --- CMakeLists.txt | 16 +++++++++------- cmake/Modules/FindChipmunk.cmake | 23 +++++++++++++++++++++++ cocos/CMakeLists.txt | 12 +++++++----- extensions/CMakeLists.txt | 13 ------------- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 552ecf35ec..bdbff7c1af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,11 +168,9 @@ include_directories( # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - find_package(GLFW3 REQUIRED) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) - endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms @@ -182,16 +180,21 @@ include_directories(${FREETYPE_INCLUDE_DIRS}) # WebP required if used if(USE_WEBP) -find_package(WebP REQUIRED) -message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") -endif() + find_package(WebP REQUIRED) + message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") +endif(USE_WEBP) + +if(USE_CHIPMUNK) + find_package(Chipmunk REQUIRED) + message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") + add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +endif(USE_CHIPMUNK) if(NOT MINGW) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 - ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/include/chipmunk ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} @@ -208,7 +211,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index 31fc02f489..b194f7ed7f 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -27,6 +27,29 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +if(USE_PREBUILT_LIBS) + find_path(CHIPMUNK_INCLUDE_DIR chipmunk.h + PATH_SUFFIXES + include/chipmunk + include + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + NO_DEFAULT_PATH + ) + find_library(CHIPMUNK_LIBRARY + NAMES chipmunk libchipmunk + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT CHIPMUNK_INCLUDE_DIR OR NOT CHIPMUNK_LIBRARY) + unset(CHIPMUNK_INCLUDE_DIR CACHE) + unset(CHIPMUNK_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + FIND_PATH(CHIPMUNK_INCLUDE_DIR chipmunk.h HINTS ENV CHIPMUNK_DIR diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index b4a597bc4f..0a31f3552c 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -88,13 +88,10 @@ if(MINGW) find_package(ZLIB REQUIRED) - find_package(Chipmunk REQUIRED) - message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "Chipmunk dirs: ${CHIPMUNK_INCLUDE_DIRS}") message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - include_directories(${ZLIB_INCLUDE_DIRS} ${CHIPMUNK_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) + include_directories(${ZLIB_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) else() @@ -163,7 +160,7 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d chipmunk box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) @@ -173,6 +170,11 @@ else() add_definitions(-DCC_USE_WEBP=0) endif() +if(USE_CHIPMUNK) + include_directories(${CHIPMUNK_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) +endif() + set_target_properties(cocos2d PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index fd212cba4e..5a2ef4f2a9 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -2,19 +2,6 @@ if(WINDOWS AND NOT BUILD_STATIC) ADD_DEFINITIONS (-D_USREXDLL) endif() -if(WINDOWS) - -# set(PLATFORM_EXTENSIONS_SRC -# ../extensions/proj.win32/Win32InputBox.cpp -# ) - -elseif(MACOSX) - -else() -# set(PLATFORM_EXTENSIONS_SRC -# ../../extensions/GUI/CCEditBox/CCEditBoxImplNone.cpp) -endif() - include_directories( ../../extensions ) From b6dc5244b81d5c74d14041c9c7e67cf3ba53da62 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 13:38:10 +0300 Subject: [PATCH 13/67] Try to fix building without chipmunk, by define CC_USE_PHYSICS=0, but lua bindings still fail. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdbff7c1af..aa39a4fbc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,8 @@ if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") add_definitions(-DCC_ENABLE_CHIPMUNK_INTEGRATION=1) +else(USE_CHIPMUNK) + add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) if(NOT MINGW) From 60e5803698c0c2343d60c7bfb5640e5bb2b1b151 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 14:41:19 +0300 Subject: [PATCH 14/67] Improve FindFreetype.cmake for Mac --- cmake/Modules/FindFreetype.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 1bf1dc8830..43188c1562 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -85,6 +85,10 @@ find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h HINTS ENV FREETYPE_DIR PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 @@ -102,6 +106,10 @@ find_path(FREETYPE_INCLUDE_DIR_freetype2 HINTS ENV FREETYPE_DIR PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 @@ -118,6 +126,10 @@ find_library(FREETYPE_LIBRARY ENV FREETYPE_DIR PATH_SUFFIXES lib PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr /usr/X11R6 /usr/local/X11R6 /usr/local/X11 From 27ef26270cf1570324346cf3a3b828807def66cc Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 14:43:50 +0300 Subject: [PATCH 15/67] Unify TinyXML2 usage. * should be included as simple "tinyxml2.h", but on some files was "tinyxml2/tinyxml2.h", replace this. * Add cmake/Modules/FindTinyXML2.cmake * As tinyxml2 for now has not prebuilt, instead sources included, add their as subdirectory if USE_PREBUILT_LIBS --- CMakeLists.txt | 15 +++- cmake/Modules/FindTinyXML2.cmake | 75 +++++++++++++++++++ cocos/CMakeLists.txt | 3 +- cocos/base/CCUserDefault-android.cpp | 2 +- .../ActionTimeline/CCActionTimelineCache.cpp | 2 +- .../cocostudio/ActionTimeline/CSLoader.cpp | 2 +- .../cocostudio/CCSGUIReader.cpp | 2 +- .../ButtonReader/ButtonReader.cpp | 2 +- .../CheckBoxReader/CheckBoxReader.cpp | 2 +- .../ImageViewReader/ImageViewReader.cpp | 2 +- .../LayoutReader/LayoutReader.cpp | 2 +- .../ListViewReader/ListViewReader.cpp | 2 +- .../LoadingBarReader/LoadingBarReader.cpp | 2 +- .../PageViewReader/PageViewReader.cpp | 2 +- .../ScrollViewReader/ScrollViewReader.cpp | 2 +- .../SliderReader/SliderReader.cpp | 2 +- .../TextAtlasReader/TextAtlasReader.cpp | 2 +- .../TextBMFontReader/TextBMFontReader.cpp | 2 +- .../TextFieldReader/TextFieldReader.cpp | 2 +- .../WidgetReader/TextReader/TextReader.cpp | 2 +- .../cocostudio/WidgetReader/WidgetReader.cpp | 2 +- 21 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 cmake/Modules/FindTinyXML2.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index aa39a4fbc5..49cad2ffd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,6 +184,7 @@ if(USE_WEBP) message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") endif(USE_WEBP) +# Chipmunk if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") @@ -192,11 +193,19 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) +# Tinyxml2 +if(USE_PREBUILT_LIBS) + add_subdirectory(external/tinyxml2) + set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) + set(TinyXML2_LIBRARIES tinyxml2) +else() + find_package(TinyXML2) +endif() +message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - - ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} @@ -208,7 +217,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} @@ -226,7 +234,6 @@ if(LINUX OR APPLE) add_subdirectory(external/Box2D) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) -add_subdirectory(external/tinyxml2) add_subdirectory(external/protobuf-lite) endif() diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake new file mode 100644 index 0000000000..694cf2bbac --- /dev/null +++ b/cmake/Modules/FindTinyXML2.cmake @@ -0,0 +1,75 @@ +#.rst: +# FindTinyXML2 +# ------------ +# +# Locate tinyxml2 library +# +# This module defines +# +# :: +# +# TINYXML2_LIBRARIES, the library to link against +# TINYXML2_FOUND, if false, do not try to link to FREETYPE +# TINYXML2_INCLUDE_DIRS, where to find headers. +# + +# Try find glfw for our arch in external folder +if(USE_PREBUILT_LIBS) + find_path(TinyXML2_INCLUDE_DIR tinyxml2.h + PATH_SUFFIXES + include/tinyxml2 + include + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + NO_DEFAULT_PATH + ) + find_library(TinyXML2_LIBRARY + NAMES tinyxml2 libtinyxml2 + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT TinyXML2_INCLUDE_DIR OR NOT TinyXML2_LIBRARY) + unset(TinyXML2_INCLUDE_DIR CACHE) + unset(TinyXML2_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +find_path(TinyXML2_INCLUDE_DIR tinyxml2.h + HINTS ENV TinyXML2_DIR + PATH_SUFFIXES include/tinyxml2 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(TinyXML2_LIBRARY + NAMES tinyxml2 libtinyxml2 + HINTS ENV TinyXML2_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt +) + +set(TinyXML2_INCLUDE_DIRS "${TinyXML2_INCLUDE_DIR}") +set(TinyXML2_LIBRARIES "${TinyXML2_LIBRARY}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TinyXML2_LIBRARIES TinyXML2_INCLUDE_DIRS) + +mark_as_advanced(TinyXML2_INCLUDE_DIRS TinyXML2_LIBRARIES TinyXML2_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 0a31f3552c..9b39181336 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -160,7 +160,8 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -target_link_libraries(cocos2d box2d protobuf tinyxml2 unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +include_directories(${TinyXML2_INCLUDE_DIRS}) +target_link_libraries(cocos2d box2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) diff --git a/cocos/base/CCUserDefault-android.cpp b/cocos/base/CCUserDefault-android.cpp index c6bc9f9a57..98035c338b 100644 --- a/cocos/base/CCUserDefault-android.cpp +++ b/cocos/base/CCUserDefault-android.cpp @@ -40,7 +40,7 @@ THE SOFTWARE. #ifdef KEEP_COMPATABILITY #include "platform/CCFileUtils.h" -#include "../tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #endif using namespace std; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index cb38bab2fd..a058cd8313 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -32,7 +32,7 @@ THE SOFTWARE. #include "2d/CCSpriteFrame.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 206847d592..8e0f9e3955 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -30,7 +30,7 @@ #include "cocostudio/CocoStudio.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include diff --git a/cocos/editor-support/cocostudio/CCSGUIReader.cpp b/cocos/editor-support/cocostudio/CCSGUIReader.cpp index 44fb5bd676..99da2e667f 100644 --- a/cocos/editor-support/cocostudio/CCSGUIReader.cpp +++ b/cocos/editor-support/cocostudio/CCSGUIReader.cpp @@ -42,7 +42,7 @@ THE SOFTWARE. #include "cocostudio/CocoLoader.h" #include "ui/CocosGUI.h" #include "CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" using namespace cocos2d; using namespace cocos2d::ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index 25e09aed32..6112a97509 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIButton.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp index 5dcf84ada5..4a510b6f19 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/CheckBoxReader/CheckBoxReader.cpp @@ -4,7 +4,7 @@ #include "ui/UICheckBox.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp index f6b00ba76c..13d50f62b1 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ImageViewReader/ImageViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIImageView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp index 12a48d6dbc..d24b9734bf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LayoutReader/LayoutReader.cpp @@ -7,7 +7,7 @@ #include "ui/UIPageView.h" #include "ui/UIListView.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp index e14384d714..38c3a5a810 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ListViewReader/ListViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIListView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp index 63455c819b..250cc41ae5 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/LoadingBarReader/LoadingBarReader.cpp @@ -4,7 +4,7 @@ #include "ui/UILoadingBar.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp index 26ed01b1f6..c2579c0580 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/PageViewReader/PageViewReader.cpp @@ -5,7 +5,7 @@ #include "ui/UILayout.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp index f6294757f1..63853255c4 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ScrollViewReader/ScrollViewReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIScrollView.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp index dba744e43f..e26eff0450 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SliderReader/SliderReader.cpp @@ -4,7 +4,7 @@ #include "ui/UISlider.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp index 3bf7b446e4..a0e4c57ccf 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextAtlasReader/TextAtlasReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextAtlas.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index 81c5a2a4f8..dba1177092 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextBMFont.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 85115bf89d..ee71cf4f6a 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -4,7 +4,7 @@ #include "ui/UITextField.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 0c08af624a..1919016c53 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -4,7 +4,7 @@ #include "ui/UIText.h" #include "cocostudio/CocoLoader.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" USING_NS_CC; using namespace ui; diff --git a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp index 757df9e31a..f3ea901303 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/WidgetReader.cpp @@ -4,7 +4,7 @@ #include "cocostudio/CocoLoader.h" #include "ui/UIButton.h" #include "cocostudio/CSParseBinary.pb.h" -#include "tinyxml2/tinyxml2.h" +#include "tinyxml2.h" #include "../ActionTimeline/CCActionTimeline.h" USING_NS_CC; From 2863b95c613ca9205f2a8b3a69688f229d5f662c Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 17:07:46 +0300 Subject: [PATCH 16/67] Make FindTinyXML2.cmake use included macroses from same directory, as other our Find*.cmake modules --- cmake/Modules/FindTinyXML2.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index 694cf2bbac..e1e8917a9a 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -69,7 +69,7 @@ find_library(TinyXML2_LIBRARY set(TinyXML2_INCLUDE_DIRS "${TinyXML2_INCLUDE_DIR}") set(TinyXML2_LIBRARIES "${TinyXML2_LIBRARY}") -include(FindPackageHandleStandardArgs) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(TinyXML2 DEFAULT_MSG TinyXML2_LIBRARIES TinyXML2_INCLUDE_DIRS) mark_as_advanced(TinyXML2_INCLUDE_DIRS TinyXML2_LIBRARIES TinyXML2_LIBRARY) From 673fdc461de95709bcc17fab67879fbb6f3a63ac Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 17:46:13 +0300 Subject: [PATCH 17/67] Unify Box2D usage and finding (not compilable, may be fix that later...) --- CMakeLists.txt | 18 +++++++++++++++--- cocos/CMakeLists.txt | 7 ++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49cad2ffd0..88854dd37a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,21 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) +# Box2d +if(USE_BOX2D) + if(USE_PREBUILT_LIBS) + add_subdirectory(external/Box2D) + set(Box2D_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include) + set(Box2D_LIBRARIES box2d) + else() + find_package(Box2D REQUIRED CONFIG) + # actually Box2D in next line is not a library, it is target exported from Box2DConfig.cmake + set(Box2D_LIBRARIES Box2D) + endif() + message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}") + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION) +endif(USE_BOX2D) + # Tinyxml2 if(USE_PREBUILT_LIBS) add_subdirectory(external/tinyxml2) @@ -206,7 +221,6 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/include ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} @@ -221,7 +235,6 @@ if(NOT MINGW) ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/box2d/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} ) @@ -231,7 +244,6 @@ endif() # build for 3rd party libraries if(LINUX OR APPLE) -add_subdirectory(external/Box2D) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) add_subdirectory(external/protobuf-lite) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 9b39181336..c251be5e8b 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -161,7 +161,7 @@ if(LINUX OR MACOSX OR WINDOWS) endif() include_directories(${TinyXML2_INCLUDE_DIRS}) -target_link_libraries(cocos2d box2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) @@ -176,6 +176,11 @@ if(USE_CHIPMUNK) target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) endif() +if(USE_BOX2D) + include_directories(${Box2D_INCLUDE_DIRS}) + target_link_libraries(cocos2d ${Box2D_LIBRARIES}) +endif() + set_target_properties(cocos2d PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" From a3b414f0d5116d7232b6146934013fe6c5bdeea4 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:13:25 +0300 Subject: [PATCH 18/67] Use COCOS_EXTERNAL_DIR in Find*.cmake modules --- CMakeLists.txt | 2 ++ cmake/Modules/FindChipmunk.cmake | 7 +++---- cmake/Modules/FindFreetype.cmake | 13 ++++++------- cmake/Modules/FindGLFW3.cmake | 9 ++++----- cmake/Modules/FindTinyXML2.cmake | 7 +++---- cmake/Modules/FindWebP.cmake | 13 +++++++------ 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88854dd37a..af2395f8db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,8 @@ else() set (BUILD_TYPE SHARED) endif() +set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external) + # Some macro definitions if(WINDOWS) diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index b194f7ed7f..b94834c338 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -32,15 +32,14 @@ if(USE_PREBUILT_LIBS) PATH_SUFFIXES include/chipmunk include - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + PATHS ${COCOS_EXTERNAL_DIR}/chipmunk NO_DEFAULT_PATH ) - find_library(CHIPMUNK_LIBRARY - NAMES chipmunk libchipmunk + find_library(CHIPMUNK_LIBRARY NAMES chipmunk libchipmunk PATH_SUFFIXES prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} prebuilt/${PLATFORM_FOLDER} - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/chipmunk + PATHS ${COCOS_EXTERNAL_DIR}/chipmunk NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 43188c1562..e4cee08134 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -45,20 +45,19 @@ if(USE_PREBUILT_LIBS) find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/include/${PLATFORM_FOLDER}/freetype2 + ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER}/freetype2 NO_DEFAULT_PATH ) - find_library(FREETYPE_LIBRARY - NAMES freetype libfreetype freetype219 freetype250 + find_library(FREETYPE_LIBRARY NAMES freetype libfreetype freetype219 freetype250 PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/freetype2/prebuilt/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindGLFW3.cmake b/cmake/Modules/FindGLFW3.cmake index 654b4eb9e7..5080a71857 100644 --- a/cmake/Modules/FindGLFW3.cmake +++ b/cmake/Modules/FindGLFW3.cmake @@ -30,14 +30,13 @@ # Try find glfw for our arch in external folder if(USE_PREBUILT_LIBS) find_path(GLFW3_INCLUDE_DIR glfw3.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/include/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/glfw3/include/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) - find_library(GLFW3_LIBRARY - NAMES glfw3 libglfw3 lgfw + find_library(GLFW3_LIBRARY NAMES glfw3 libglfw3 lgfw PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw3/prebuilt/${PLATFORM_FOLDER} + ${COCOS_EXTERNAL_DIR}/glfw3/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + ${COCOS_EXTERNAL_DIR}/glfw3/prebuilt/${PLATFORM_FOLDER} NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index e1e8917a9a..484c66535e 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -19,15 +19,14 @@ if(USE_PREBUILT_LIBS) PATH_SUFFIXES include/tinyxml2 include - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + PATHS ${COCOS_EXTERNAL_DIR}/tinyxml2 NO_DEFAULT_PATH ) - find_library(TinyXML2_LIBRARY - NAMES tinyxml2 libtinyxml2 + find_library(TinyXML2_LIBRARY NAMES tinyxml2 libtinyxml2 PATH_SUFFIXES prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} prebuilt/${PLATFORM_FOLDER} - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2 + PATHS ${COCOS_EXTERNAL_DIR}/tinyxml2 NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index e885ffeb6d..8d93dec9f4 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -30,14 +30,15 @@ # Try find WebP for our arch in external folder if(USE_PREBUILT_LIBS) find_path(WEBP_INCLUDE_DIR decode.h - PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/include/${PLATFORM_FOLDER} + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/webp NO_DEFAULT_PATH ) - find_library(WEBP_LIBRARY - NAMES webp libwebp - PATHS - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/webp/prebuilt/${PLATFORM_FOLDER} + find_library(WEBP_LIBRARY NAMES webp libwebp + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/webp NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) From 210d8ec985414b9f82ed539897278a611b233972 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:16:01 +0300 Subject: [PATCH 19/67] Compile Box2D tests only if library used in cocos. --- CMakeLists.txt | 4 +++- tests/cpp-tests/CMakeLists.txt | 20 ++++++++++++++------ tests/cpp-tests/Classes/controller.cpp | 2 ++ tests/cpp-tests/Classes/tests.h | 2 ++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af2395f8db..9627e55ce5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,7 +207,9 @@ if(USE_BOX2D) set(Box2D_LIBRARIES Box2D) endif() message(STATUS "Box2D include dirs: ${Box2D_INCLUDE_DIRS}") - add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION) + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=1) +else() + add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0) endif(USE_BOX2D) # Tinyxml2 diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index dac761970a..b470f4f2d6 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -27,11 +27,6 @@ set(TESTS_SRC Classes/ActionsProgressTest/ActionsProgressTest.cpp Classes/ActionsTest/ActionsTest.cpp Classes/BillBoardTest/BillBoardTest.cpp - Classes/Box2DTest/Box2dTest.cpp - Classes/Box2DTestBed/Box2dView.cpp - Classes/Box2DTestBed/GLES-Render.cpp - Classes/Box2DTestBed/Test.cpp - Classes/Box2DTestBed/TestEntries.cpp Classes/BugsTest/Bug-1159.cpp Classes/BugsTest/Bug-1174.cpp Classes/BugsTest/Bug-350.cpp @@ -203,6 +198,20 @@ set(TESTS_SRC ${PLATFORM_SRC} ) +if(USE_CHIPMUNK) + include_directories(${CHIPMUNK_INCLUDE_DIRS}) +endif() + +if(USE_BOX2D) + list(APPEND TESTS_SRC + Classes/Box2DTest/Box2dTest.cpp + Classes/Box2DTestBed/Box2dView.cpp + Classes/Box2DTestBed/GLES-Render.cpp + Classes/Box2DTestBed/Test.cpp + Classes/Box2DTestBed/TestEntries.cpp + ) +endif() + if(LINUX) set(EXTENDED_TESTS_SRC ) @@ -229,7 +238,6 @@ endif() include_directories( Classes - ${CMAKE_SOURCE_DIR}/external/chipmunk/include/chipmunk ${CMAKE_SOURCE_DIR}/cocos/editor-support ) diff --git a/tests/cpp-tests/Classes/controller.cpp b/tests/cpp-tests/Classes/controller.cpp index c6776c7797..4748f6d2ec 100644 --- a/tests/cpp-tests/Classes/controller.cpp +++ b/tests/cpp-tests/Classes/controller.cpp @@ -42,8 +42,10 @@ Controller g_aTestNames[] = { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) { "Audio - NewAudioEngine", []() { return new AudioEngineTestScene(); } }, #endif +#if CC_ENABLE_BOX2D_INTEGRATION { "Box2d - Basic", []() { return new Box2DTestScene(); } }, { "Box2d - TestBed", []() { return new Box2dTestBedScene(); } }, +#endif { "Bugs", []() { return new BugsTestScene(); } }, { "Chipmunk", []() { return new ChipmunkAccelTouchTestScene(); } }, { "Click and Move", [](){return new ClickAndMoveTestScene(); } }, diff --git a/tests/cpp-tests/Classes/tests.h b/tests/cpp-tests/Classes/tests.h index ce6f29c882..78db79616e 100644 --- a/tests/cpp-tests/Classes/tests.h +++ b/tests/cpp-tests/Classes/tests.h @@ -30,8 +30,10 @@ #include "SpriteTest/SpriteTest.h" #include "SchedulerTest/SchedulerTest.h" #include "RenderTextureTest/RenderTextureTest.h" +#if CC_ENABLE_BOX2D_INTEGRATION #include "Box2DTest/Box2dTest.h" #include "Box2DTestBed/Box2dView.h" +#endif #include "EffectsAdvancedTest/EffectsAdvancedTest.h" #include "InputTest/MouseTest.h" #include "PerformanceTest/PerformanceTest.h" From 9334f0b5696d33e469304350178ab998601d2373 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sat, 15 Nov 2014 21:16:39 +0300 Subject: [PATCH 20/67] Add custom FindJPEG.cmake module. --- CMakeLists.txt | 6 ++-- cmake/Modules/FindJPEG.cmake | 69 ++++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 11 +++--- 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 cmake/Modules/FindJPEG.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9627e55ce5..ecedd608c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,10 +222,13 @@ else() endif() message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") +# libjpeg +find_package(JPEG REQUIRED) +message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} @@ -235,7 +238,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/jpeg/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindJPEG.cmake b/cmake/Modules/FindJPEG.cmake new file mode 100644 index 0000000000..1fbb90328e --- /dev/null +++ b/cmake/Modules/FindJPEG.cmake @@ -0,0 +1,69 @@ +#.rst: +# FindJPEG +# -------- +# +# Find JPEG +# +# Find the native JPEG includes and library This module defines +# +# :: +# +# JPEG_INCLUDE_DIRS, where to find jpeglib.h, etc. +# JPEG_LIBRARIES, the libraries needed to use JPEG. +# JPEG_FOUND, If false, do not try to use JPEG. +# +# also defined, but not for general use are +# +# :: +# +# JPEG_LIBRARY, where to find the JPEG library. + +#============================================================================= +# Copyright 2001-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(USE_PREBUILT_LIBS) + find_path(JPEG_INCLUDE_DIR jpeglib.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/jpeg + NO_DEFAULT_PATH + ) + find_library(JPEG_LIBRARY NAMES jpeg + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/jpeg + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT JPEG_INCLUDE_DIR OR NOT JPEG_LIBRARY) + unset(JPEG_INCLUDE_DIR CACHE) + unset(JPEG_LIBRARY CACHE) + endif() +endif() + +find_path(JPEG_INCLUDE_DIR jpeglib.h) + +set(JPEG_NAMES ${JPEG_NAMES} jpeg) +find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES} ) + +# handle the QUIETLY and REQUIRED arguments and set JPEG_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR) + +if(JPEG_FOUND) + set(JPEG_INCLUDE_DIRS ${JPEG_INCLUDE_DIR}) + set(JPEG_LIBRARIES ${JPEG_LIBRARY}) +endif() + +mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIRS ) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c251be5e8b..231bbd953f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z jpeg png tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS z png tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libjpeg libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS jpeg tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z jpeg png tiff curl + z png tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -163,6 +163,9 @@ endif() include_directories(${TinyXML2_INCLUDE_DIRS}) target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +include_directories(${JPEG_INCLUDE_DIRS}) +target_link_libraries(cocos2d ${JPEG_LIBRARIES}) + if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) include_directories(${WEBP_INCLUDE_DIRS}) From d9337cdbd3756c6f4128ffa3c0403c523ea3b5b5 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 00:21:11 +0300 Subject: [PATCH 21/67] Find libpng and zlib unified way. --- CMakeLists.txt | 8 +- cmake/Modules/FindPNG.cmake | 178 ++++++++++++++++++ cmake/Modules/FindZLIB.cmake | 124 ++++++++++++ .../Modules/SelectLibraryConfigurations.cmake | 81 ++++++++ cocos/CMakeLists.txt | 30 ++- 5 files changed, 410 insertions(+), 11 deletions(-) create mode 100644 cmake/Modules/FindPNG.cmake create mode 100644 cmake/Modules/FindZLIB.cmake create mode 100644 cmake/Modules/SelectLibraryConfigurations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ecedd608c4..f5bdaedc9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,10 +226,15 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") +find_package(ZLIB REQUIRED) +message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") + +find_package(PNG REQUIRED) +message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/png/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} @@ -239,7 +244,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/png/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindPNG.cmake b/cmake/Modules/FindPNG.cmake new file mode 100644 index 0000000000..53cd8385da --- /dev/null +++ b/cmake/Modules/FindPNG.cmake @@ -0,0 +1,178 @@ +#.rst: +# FindPNG +# ------- +# +# Find the native PNG includes and library +# +# +# +# This module searches libpng, the library for working with PNG images. +# +# It defines the following variables +# +# :: +# +# PNG_INCLUDE_DIRS, where to find png.h, etc. +# PNG_LIBRARIES, the libraries to link against to use PNG. +# PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files. +# PNG_FOUND, If false, do not try to use PNG. +# PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8) +# +# Also defined, but not for general use are +# +# :: +# +# PNG_LIBRARY, where to find the PNG library. +# +# For backward compatiblity the variable PNG_INCLUDE_DIR is also set. +# It has the same value as PNG_INCLUDE_DIRS. +# +# Since PNG depends on the ZLib compression library, none of the above +# will be defined unless ZLib can be found. + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(PNG_FIND_QUIETLY) + set(_FIND_ZLIB_ARG QUIET) +endif() +find_package(ZLIB ${_FIND_ZLIB_ARG}) + +if(USE_PREBUILT_LIBS) + find_path(PNG_PNG_INCLUDE_DIR png.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/png NO_DEFAULT_PATH + ) + find_library(PNG_LIBRARY NAMES png libpng + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/png NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT PNG_PNG_INCLUDE_DIR OR NOT PNG_LIBRARY) + unset(PNG_PNG_INCLUDE_DIR CACHE) + unset(PNG_LIBRARY CACHE) + endif() +endif() + +if(ZLIB_FOUND) + find_path(PNG_PNG_INCLUDE_DIR png.h + HINTS ENV PNG_DIR + PATH_SUFFIXES include/libpng include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + + list(APPEND PNG_NAMES png libpng) + unset(PNG_NAMES_DEBUG) + set(_PNG_VERSION_SUFFIXES 17 16 15 14 12) + if (PNG_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\..*)?$") + string(REGEX REPLACE + "^([0-9]+)\\.([0-9]+).*" "\\1\\2" + _PNG_VERSION_SUFFIX_MIN "${PNG_FIND_VERSION}") + if (PNG_FIND_VERSION_EXACT) + set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN}) + else () + string(REGEX REPLACE + "${_PNG_VERSION_SUFFIX_MIN}.*" "${_PNG_VERSION_SUFFIX_MIN}" + _PNG_VERSION_SUFFIXES "${_PNG_VERSION_SUFFIXES}") + endif () + unset(_PNG_VERSION_SUFFIX_MIN) + endif () + foreach(v IN LISTS _PNG_VERSION_SUFFIXES) + list(APPEND PNG_NAMES png${v} libpng${v}) + list(APPEND PNG_NAMES_DEBUG png${v}d libpng${v}d) + endforeach() + unset(_PNG_VERSION_SUFFIXES) + # For compatiblity with versions prior to this multi-config search, honor + # any PNG_LIBRARY that is already specified and skip the search. + if(NOT PNG_LIBRARY) + find_library(PNG_LIBRARY_RELEASE + NAMES ${PNG_NAMES} + HINTS ENV PNG_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + find_library(PNG_LIBRARY_DEBUG + NAMES ${PNG_NAMES_DEBUG} + HINTS ENV PNG_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + select_library_configurations(PNG) + mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG) + endif() + unset(PNG_NAMES) + unset(PNG_NAMES_DEBUG) + + # Set by select_library_configurations(), but we want the one from + # find_package_handle_standard_args() below. + unset(PNG_FOUND) + + if (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR) + # png.h includes zlib.h. Sigh. + set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) + set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS} ) # for backward compatiblity + set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY}) + + if (CYGWIN) + if(BUILD_SHARED_LIBS) + # No need to define PNG_USE_DLL here, because it's default for Cygwin. + else() + set (PNG_DEFINITIONS -DPNG_STATIC) + endif() + endif () + + endif () + + if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h") + file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"") + + string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}") + unset(png_version_str) + endif () +endif() + +# handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(PNG + REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR + VERSION_VAR PNG_VERSION_STRING) + +mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY ) diff --git a/cmake/Modules/FindZLIB.cmake b/cmake/Modules/FindZLIB.cmake new file mode 100644 index 0000000000..0e287adc96 --- /dev/null +++ b/cmake/Modules/FindZLIB.cmake @@ -0,0 +1,124 @@ +#.rst: +# FindZLIB +# -------- +# +# Find zlib +# +# Find the native ZLIB includes and library. Once done this will define +# +# :: +# +# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. +# ZLIB_LIBRARIES - List of libraries when using zlib. +# ZLIB_FOUND - True if zlib found. +# +# +# +# :: +# +# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) +# ZLIB_VERSION_MAJOR - The major version of zlib +# ZLIB_VERSION_MINOR - The minor version of zlib +# ZLIB_VERSION_PATCH - The patch version of zlib +# ZLIB_VERSION_TWEAK - The tweak version of zlib +# +# +# +# The following variable are provided for backward compatibility +# +# :: +# +# ZLIB_MAJOR_VERSION - The major version of zlib +# ZLIB_MINOR_VERSION - The minor version of zlib +# ZLIB_PATCH_VERSION - The patch version of zlib +# +# +# +# An includer may set ZLIB_ROOT to a zlib installation root to tell this +# module where to look. + +#============================================================================= +# Copyright 2001-2011 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) + +if(USE_PREBUILT_LIBS) + set(search PATHS ${COCOS_EXTERNAL_DIR}/zlib ${COCOS_EXTERNAL_DIR}/${ARCH_DIR}-specific/zlib NO_DEFAULT_PATH) + find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${search} PATH_SUFFIXES include/${PLATFORM_FOLDER} include) + find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${search} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + prebuilt + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) + unset(ZLIB_INCLUDE_DIR CACHE) + unset(ZLIB_LIBRARY CACHE) + endif() +endif() + +set(_ZLIB_SEARCHES) + +# Search ZLIB_ROOT first if it is set. +if(ZLIB_ROOT) + set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH) + list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT) +endif() + +# Normal search. +set(_ZLIB_SEARCH_NORMAL + PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" + "$ENV{PROGRAMFILES}/zlib" + ) +list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL) + +# Try each search configuration. +foreach(search ${_ZLIB_SEARCHES}) + find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include) + find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib) +endforeach() + +mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) + +if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") + file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") + + string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") + string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") + + # only append a TWEAK version if it exists: + set(ZLIB_VERSION_TWEAK "") + if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") + set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") + set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") + endif() + + set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") + set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") + set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") +endif() + +# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR + VERSION_VAR ZLIB_VERSION_STRING) + +if(ZLIB_FOUND) + set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) +endif() + diff --git a/cmake/Modules/SelectLibraryConfigurations.cmake b/cmake/Modules/SelectLibraryConfigurations.cmake new file mode 100644 index 0000000000..d7108562b1 --- /dev/null +++ b/cmake/Modules/SelectLibraryConfigurations.cmake @@ -0,0 +1,81 @@ +#.rst: +# SelectLibraryConfigurations +# --------------------------- +# +# +# +# select_library_configurations( basename ) +# +# This macro takes a library base name as an argument, and will choose +# good values for basename_LIBRARY, basename_LIBRARIES, +# basename_LIBRARY_DEBUG, and basename_LIBRARY_RELEASE depending on what +# has been found and set. If only basename_LIBRARY_RELEASE is defined, +# basename_LIBRARY will be set to the release value, and +# basename_LIBRARY_DEBUG will be set to basename_LIBRARY_DEBUG-NOTFOUND. +# If only basename_LIBRARY_DEBUG is defined, then basename_LIBRARY will +# take the debug value, and basename_LIBRARY_RELEASE will be set to +# basename_LIBRARY_RELEASE-NOTFOUND. +# +# If the generator supports configuration types, then basename_LIBRARY +# and basename_LIBRARIES will be set with debug and optimized flags +# specifying the library to be used for the given configuration. If no +# build type has been set or the generator in use does not support +# configuration types, then basename_LIBRARY and basename_LIBRARIES will +# take only the release value, or the debug value if the release one is +# not set. + +#============================================================================= +# Copyright 2009 Will Dicharry +# Copyright 2005-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro( select_library_configurations basename ) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) ) + # if the generator supports configuration types or CMAKE_BUILD_TYPE + # is set, then set optimized and debug options. + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 231bbd953f..5668d25ea0 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS z png tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libpng libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv libzlib) + set(PLATFORM_SPECIFIC_LIBS libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig png pthread GLEW GL X11 rt z ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - z png tiff curl + tiff curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -150,7 +150,7 @@ elseif(MACOSX OR APPLE) ) elseif(ANDROID) - set(PLATFORM_SPECIFIC_LIBS GLESv2 log z android) + set(PLATFORM_SPECIFIC_LIBS GLESv2 log android) else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() @@ -160,11 +160,23 @@ if(LINUX OR MACOSX OR WINDOWS) list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) endif() -include_directories(${TinyXML2_INCLUDE_DIRS}) -target_link_libraries(cocos2d protobuf ${TinyXML2_LIBRARIES} unzip xxhash ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS}) +add_definitions(${PNG_DEFINITIONS}) -include_directories(${JPEG_INCLUDE_DIRS}) -target_link_libraries(cocos2d ${JPEG_LIBRARIES}) +include_directories( + ${ZLIB_INCLUDE_DIRS} + ${JPEG_INCLUDE_DIRS} + ${PNG_INCLUDE_DIRS} + ${TinyXML2_INCLUDE_DIRS} + ) +target_link_libraries(cocos2d + protobuf unzip xxhash + ${ZLIB_LIBRARIES} + ${JPEG_LIBRARIES} + ${PNG_LIBRARIES} + ${TinyXML2_LIBRARIES} + ${FREETYPE_LIBRARIES} + ${PLATFORM_SPECIFIC_LIBS} + ) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) From 1c2fa8714e2f2c2cfd4468360b62fe53a338a2f7 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 12:19:19 +0300 Subject: [PATCH 22/67] Fix building with system installed chipmunk on Mac. We should define CP_USE_CGPOINTS=0, or chipmunk will try use apple defined geometry types that conflicts with cocos types. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5bdaedc9e..ebf9f59c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,10 @@ if(USE_CHIPMUNK) find_package(Chipmunk REQUIRED) message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") 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(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) From 1d629dfe7dd8257f0c192cc247628f0c6ceb065a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 12:47:59 +0300 Subject: [PATCH 23/67] Find libtiff --- CMakeLists.txt | 5 +- cmake/Modules/FindTIFF.cmake | 106 +++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 10 ++-- 3 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 cmake/Modules/FindTIFF.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ebf9f59c2c..3b8d9b358e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,10 +236,12 @@ message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") find_package(PNG REQUIRED) message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") +find_package(TIFF REQUIRED) +message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src @@ -247,7 +249,6 @@ if(NOT MINGW) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/tiff/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} diff --git a/cmake/Modules/FindTIFF.cmake b/cmake/Modules/FindTIFF.cmake new file mode 100644 index 0000000000..d9b5954c2e --- /dev/null +++ b/cmake/Modules/FindTIFF.cmake @@ -0,0 +1,106 @@ +#.rst: +# FindTIFF +# -------- +# +# Find TIFF library +# +# Find the native TIFF includes and library This module defines +# +# :: +# +# TIFF_INCLUDE_DIR, where to find tiff.h, etc. +# TIFF_LIBRARIES, libraries to link against to use TIFF. +# TIFF_FOUND, If false, do not try to use TIFF. +# +# also defined, but not for general use are +# +# :: +# +# TIFF_LIBRARY, where to find the TIFF library. + +#============================================================================= +# Copyright 2002-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3) + +if(USE_PREBUILT_LIBS) + find_path(TIFF_INCLUDE_DIR tiff.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/tiff NO_DEFAULT_PATH + ) + find_library(TIFF_LIBRARY NAMES ${TIFF_NAMES} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/tiff NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT TIFF_INCLUDE_DIR OR NOT TIFF_LIBRARY) + unset(TIFF_INCLUDE_DIR CACHE) + unset(TIFF_LIBRARY CACHE) + endif() +endif() + +find_path(TIFF_INCLUDE_DIR tiff.h + HINTS ENV TIFF_DIR + PATH_SUFFIXES include/libtiff include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(TIFF_LIBRARY + NAMES ${TIFF_NAMES} + HINTS ENV TIFF_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + +if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") + file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str + REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*") + + string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" + "\\1" TIFF_VERSION_STRING "${tiff_version_str}") + unset(tiff_version_str) +endif() + +set(TIFF_INCLUDE_DIRS ${TIFF_INCLUDE_DIR}) + +# handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF + REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIRS + VERSION_VAR TIFF_VERSION_STRING + ) + +if(TIFF_FOUND) + set( TIFF_LIBRARIES ${TIFF_LIBRARY} ) +endif() + +mark_as_advanced(TIFF_INCLUDE_DIRS TIFF_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 5668d25ea0..2b02f0f9d4 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS curl websockets glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libtiff libcurl_imp libwebsockets glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS libcurl_imp libwebsockets glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS tiff curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,7 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - tiff curl + curl websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} @@ -166,6 +166,7 @@ include_directories( ${ZLIB_INCLUDE_DIRS} ${JPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} + ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} ) target_link_libraries(cocos2d @@ -173,6 +174,7 @@ target_link_libraries(cocos2d ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} + ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} From 0898af21aba96e961b848b729051214a509bef91 Mon Sep 17 00:00:00 2001 From: Filipe Lemos Date: Sun, 16 Nov 2014 10:16:16 +0000 Subject: [PATCH 24/67] Fix Back Key behaviour and Director::getInstance()->end() on WP8 --- cocos/platform/wp8/CCGLViewImpl-wp8.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cocos/platform/wp8/CCGLViewImpl-wp8.cpp b/cocos/platform/wp8/CCGLViewImpl-wp8.cpp index 6c6835aecc..8c06803118 100644 --- a/cocos/platform/wp8/CCGLViewImpl-wp8.cpp +++ b/cocos/platform/wp8/CCGLViewImpl-wp8.cpp @@ -179,6 +179,11 @@ bool GLViewImpl::isOpenGLReady() void GLViewImpl::end() { m_windowClosed = true; + std::string str; + if (m_delegate) { + // Terminate app on Director::getInstance()->end(); + m_delegate->Invoke(Cocos2dEvent::TerminateApp, stringToPlatformString(str)); + } } @@ -193,11 +198,8 @@ void GLViewImpl::OnResuming(Platform::Object^ sender, Platform::Object^ args) // user pressed the Back Key on the phone void GLViewImpl::OnBackKeyPress() { - std::string str; - if(m_delegate) - { - m_delegate->Invoke(Cocos2dEvent::TerminateApp, stringToPlatformString(str)); - } + EventKeyboard event(EventKeyboard::KeyCode::KEY_ESCAPE, false); + Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } void GLViewImpl::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args) From c7bff5ea9e1efb15266fbbdbae94071db99f0769 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 13:22:54 +0300 Subject: [PATCH 25/67] Find libwebsockets in unified way --- CMakeLists.txt | 3 ++ cmake/Modules/FindWEBSOCKETS.cmake | 68 ++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 ++-- 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 cmake/Modules/FindWEBSOCKETS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b8d9b358e..0a5c3f88ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,9 @@ message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") find_package(TIFF REQUIRED) message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") +find_package(WEBSOCKETS REQUIRED) +message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( diff --git a/cmake/Modules/FindWEBSOCKETS.cmake b/cmake/Modules/FindWEBSOCKETS.cmake new file mode 100644 index 0000000000..aab748a5e0 --- /dev/null +++ b/cmake/Modules/FindWEBSOCKETS.cmake @@ -0,0 +1,68 @@ +#.rst: +# FindWEBSOCKETS +# -------- +# +# Find websockets library +# +# :: +# +# WEBSOCKETS_INCLUDE_DIRS, where to find libwebsockets.h. +# WEBSOCKETS_LIBRARIES, the libraries needed to use WEBSOCKETS. +# WEBSOCKETS_FOUND, If false, do not try to use WEBSOCKETS. +# + +if(USE_PREBUILT_LIBS) + find_path(WEBSOCKETS_INCLUDE_DIR libwebsockets.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/websockets + NO_DEFAULT_PATH + ) + find_library(WEBSOCKETS_LIBRARY NAMES websockets libwebsockets + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/websockets + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT WEBSOCKETS_INCLUDE_DIR OR NOT WEBSOCKETS_LIBRARY) + unset(WEBSOCKETS_INCLUDE_DIR CACHE) + unset(WEBSOCKETS_LIBRARY CACHE) + endif() +endif() + +find_path(WEBSOCKETS_INCLUDE_DIR libwebsockets.h + HINTS ENV WEBSOCKETS_DIR + PATH_SUFFIXES include/websockets include/libwebsockets include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(WEBSOCKETS_LIBRARY NAMES websockets libwebsockets + HINTS ENV WEBSOCKETS_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt + ) + +set(WEBSOCKETS_INCLUDE_DIRS ${WEBSOCKETS_INCLUDE_DIR}) +set(WEBSOCKETS_LIBRARIES ${WEBSOCKETS_LIBRARY}) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(WEBSOCKETS DEFAULT_MSG WEBSOCKETS_LIBRARIES WEBSOCKETS_INCLUDE_DIRS) + +mark_as_advanced(WEBSOCKETS_LIBRARIES WEBSOCKETS_INCLUDE_DIRS) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2b02f0f9d4..eb08750767 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS curl websockets glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS curl glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libcurl_imp libwebsockets glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS libcurl_imp glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS curl websockets ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS curl ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -138,7 +138,6 @@ elseif(MACOSX OR APPLE) set(PLATFORM_SPECIFIC_LIBS curl - websockets ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -168,6 +167,7 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} + ${WEBSOCKETS_INCLUDE_DIRS} ) target_link_libraries(cocos2d protobuf unzip xxhash @@ -176,6 +176,7 @@ target_link_libraries(cocos2d ${PNG_LIBRARIES} ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} + ${WEBSOCKETS_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) From 33786678eb50ccad62408c18c4dcd020762d072e Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 13:55:42 +0300 Subject: [PATCH 26/67] Add finding curl. Fix some leftovers from websockets. --- CMakeLists.txt | 8 ++- cmake/Modules/FindCURL.cmake | 98 ++++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 ++-- cocos/network/HttpClient.cpp | 4 +- 4 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 cmake/Modules/FindCURL.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a5c3f88ca..7c1b9cc4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,19 +242,17 @@ message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") find_package(WEBSOCKETS REQUIRED) message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") +find_package(CURL REQUIRED) +message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") + if(NOT MINGW) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/include/${PLATFORM_FOLDER} - ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/include/${PLATFORM_FOLDER} ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src ) link_directories( ${PLATFORM_LINK_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/external/websockets/prebuilt/${PLATFORM_FOLDER_ARCH} - ${CMAKE_CURRENT_SOURCE_DIR}/external/curl/prebuilt/${PLATFORM_FOLDER_ARCH} - ) diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake new file mode 100644 index 0000000000..543eafc2f5 --- /dev/null +++ b/cmake/Modules/FindCURL.cmake @@ -0,0 +1,98 @@ +#.rst: +# FindCURL +# -------- +# +# Find curl +# +# Find the native CURL headers and libraries. +# +# :: +# +# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc. +# CURL_LIBRARIES - List of libraries when using curl. +# CURL_FOUND - True if curl found. +# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8) + +#============================================================================= +# Copyright 2006-2009 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +set(CURL_LIBRARY_NAMES + curl +# Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static +# Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl + ) + +if(USE_PREBUILT_LIBS) + find_path(CURL_INCLUDE_DIR curl/curl.h + PATH_SUFFIXES include/${PLATFORM_FOLDER} include + PATHS ${COCOS_EXTERNAL_DIR}/curl + NO_DEFAULT_PATH + ) + find_library(CURL_LIBRARY NAMES ${CURL_LIBRARY_NAMES} + PATH_SUFFIXES + prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} + prebuilt/${PLATFORM_FOLDER} + PATHS ${COCOS_EXTERNAL_DIR}/curl + NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT CURL_INCLUDE_DIR OR NOT CURL_LIBRARY) + unset(CURL_INCLUDE_DIR CACHE) + unset(CURL_LIBRARY CACHE) + endif() +endif() + +# Look for the header file. +find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) +mark_as_advanced(CURL_INCLUDE_DIR) + +# Look for the library (sorted from most current/relevant entry to least). +find_library(CURL_LIBRARY NAMES + curl + # Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static + # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl +) +mark_as_advanced(CURL_LIBRARY) + +if(CURL_INCLUDE_DIR) + foreach(_curl_version_header curlver.h curl.h) + if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + unset(curl_version_str) + break() + endif() + endforeach() +endif() + +# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if +# all listed variables are TRUE +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) + +if(CURL_FOUND) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) +endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index eb08750767..7da332a7e2 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -119,11 +119,11 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(MINGW) - set(PLATFORM_SPECIFIC_LIBS curl glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS libcurl_imp glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS curl ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -137,7 +137,6 @@ elseif(MACOSX OR APPLE) FIND_LIBRARY(FOUNDATION_LIBRARY Foundation) set(PLATFORM_SPECIFIC_LIBS - curl ${COCOA_LIBRARY} ${OPENGL_LIBRARY} ${OPENAL_LIBRARY} @@ -167,6 +166,7 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} ${WEBSOCKETS_INCLUDE_DIRS} ) target_link_libraries(cocos2d @@ -177,6 +177,7 @@ target_link_libraries(cocos2d ${TIFF_LIBRARIES} ${TinyXML2_LIBRARIES} ${WEBSOCKETS_LIBRARIES} + ${CURL_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/cocos/network/HttpClient.cpp b/cocos/network/HttpClient.cpp index 9bcd92df1c..88e4478665 100644 --- a/cocos/network/HttpClient.cpp +++ b/cocos/network/HttpClient.cpp @@ -32,12 +32,12 @@ #include +#include + #include "base/CCVector.h" #include "base/CCDirector.h" #include "base/CCScheduler.h" -#include "curl/curl.h" - #include "platform/CCFileUtils.h" NS_CC_BEGIN From d224dc0ce75027ebef3c8e8dab8dc94d50d5b850 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 14:12:29 +0300 Subject: [PATCH 27/67] Remove incorrect includes. No sure about to remove comment, because it important, but work in this direction in progress now, so I remove it also. --- CMakeLists.txt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c1b9cc4bf..b251a90307 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,20 +154,6 @@ elseif(NOT MINGW) set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) endif() - -# NB -# we need to return these to libraries to their official state rather than -# having our custom cocos2d namespace so that we may use system versions if -# the platform provides them. It is very important that this -# is done before we make prebuilt versions of these two libs - -include_directories( - - ${CMAKE_CURRENT_SOURCE_DIR}/../external/unzip - ${CMAKE_CURRENT_SOURCE_DIR}/../external/xxhash - -) - # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(GLFW3 REQUIRED) From 039005ef131ed7d64c42c56ddd84297ba47e8af1 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 15:29:24 +0300 Subject: [PATCH 28/67] Unify protobuf finding and usage. But disable finding until bug with protobuf versions will be resolved. --- CMakeLists.txt | 32 +++++++++++++++++++++----------- cocos/CMakeLists.txt | 23 ++++++----------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b251a90307..9b8ed7bc02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,7 @@ else(USE_CHIPMUNK) add_definitions(-DCC_USE_PHYSICS=0) endif(USE_CHIPMUNK) -# Box2d +# Box2d (not prebuilded, exists as source) if(USE_BOX2D) if(USE_PREBUILT_LIBS) add_subdirectory(external/Box2D) @@ -202,7 +202,7 @@ else() add_definitions(-DCC_ENABLE_BOX2D_INTEGRATION=0) endif(USE_BOX2D) -# Tinyxml2 +# Tinyxml2 (not prebuilded, exists as source) if(USE_PREBUILT_LIBS) add_subdirectory(external/tinyxml2) set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) @@ -231,16 +231,27 @@ message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") find_package(CURL REQUIRED) message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") +# protobuf-lite (not prebuilded, exists as source) +# TODO: for now we can't use upstream protobuf because these files: +# cocos/editor-support/cocostudio/CSParseBinary.pb.h +# cocos/editor-support/cocostudio/CSParseBinary.pb.cc +# was generated by concrete version of protobuf compiler +# and source file not provided. So these files can be +# compiled only with our in-source version of protobuf-lite +## if(USE_PREBUILT_LIBS) + add_subdirectory(external/protobuf-lite) + set(PROTOBUF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) + set(PROTOBUF_LITE_LIBRARIES protobuf) +## else() +## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## endif() +message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") +message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") + + if(NOT MINGW) - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src - ) - - link_directories( - ${PLATFORM_LINK_DIR} - ) - + link_directories(${PLATFORM_LINK_DIR}) endif() @@ -248,7 +259,6 @@ endif() if(LINUX OR APPLE) add_subdirectory(external/unzip) add_subdirectory(external/xxhash) -add_subdirectory(external/protobuf-lite) endif() # libcocos2d.a diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 7da332a7e2..2ff9e03d61 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,26 +81,13 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(MINGW) - find_package(Protobuf REQUIRED) - #find_package(MiniZip REQUIRED) - #${MINIZIP_INCLUDE_DIR} - - find_package(ZLIB REQUIRED) - - message( STATUS "ZLIB dirs: ${ZLIB_INCLUDE_DIRS}") - message( STATUS "Protobuf dirs: ${PROTOBUF_INCLUDE_DIRS}") - - include_directories(${ZLIB_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIRS}) - -else() +if(NOT MINGW) #todo: provide prebuild versions of minizip for android ios mac and msvc #done: prebuilt version for mingw-w64 (linux distros should have them also) # check for opensuse the buildbot system arch and ubuntu - include_directories( - ../external/unzip) + include_directories( ../external/unzip ) endif() @@ -166,11 +153,12 @@ include_directories( ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} ${TinyXML2_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} ${WEBSOCKETS_INCLUDE_DIRS} + ${CURL_INCLUDE_DIRS} + ${PROTOBUF_INCLUDE_DIRS} ) target_link_libraries(cocos2d - protobuf unzip xxhash + unzip xxhash ${ZLIB_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} @@ -178,6 +166,7 @@ target_link_libraries(cocos2d ${TinyXML2_LIBRARIES} ${WEBSOCKETS_LIBRARIES} ${CURL_LIBRARIES} + ${PROTOBUF_LITE_LIBRARIES} ${FREETYPE_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) From f8f37b7bf504bed1693ce47a6000e21a9941561b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 19:09:59 +0300 Subject: [PATCH 29/67] Fix comments and formatting in FindTinyXML2.cmake --- cmake/Modules/FindTinyXML2.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/Modules/FindTinyXML2.cmake b/cmake/Modules/FindTinyXML2.cmake index 484c66535e..7f155bfbea 100644 --- a/cmake/Modules/FindTinyXML2.cmake +++ b/cmake/Modules/FindTinyXML2.cmake @@ -9,11 +9,11 @@ # :: # # TINYXML2_LIBRARIES, the library to link against -# TINYXML2_FOUND, if false, do not try to link to FREETYPE +# TINYXML2_FOUND, if false, do not try to link to tinyxml2 # TINYXML2_INCLUDE_DIRS, where to find headers. # -# Try find glfw for our arch in external folder +# Try find tinyxml for our arch in external folder if(USE_PREBUILT_LIBS) find_path(TinyXML2_INCLUDE_DIR tinyxml2.h PATH_SUFFIXES From e3a0e089ba2c98dfca11b27f10b31b6999a8ba1a Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 19:10:45 +0300 Subject: [PATCH 30/67] Add FindFMODEX.cmake and use it on linux to find FMOD Ex library --- CMakeLists.txt | 20 +++------- cmake/Modules/FindFMODEX.cmake | 72 ++++++++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 9 +---- 3 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 cmake/Modules/FindFMODEX.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b8ed7bc02..fe92223631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,19 +141,17 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -# Specific Link Directories if(LINUX) - set(PLATFORM_LINK_DIR - /usr/local/lib - ${CMAKE_CURRENT_SOURCE_DIR}/external/${PLATFORM_FOLDER}-specific/fmod/prebuilt/${ARCH_DIR} - ) - set(PLATFORM_FOLDER_ARCH - ${PLATFORM_FOLDER}/${ARCH_DIR} - ) + set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}/${ARCH_DIR}) elseif(NOT MINGW) set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) endif() +if(LINUX) + find_package(FMODEX REQUIRED) + message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") +endif() + # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(GLFW3 REQUIRED) @@ -249,12 +247,6 @@ message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") -if(NOT MINGW) - - link_directories(${PLATFORM_LINK_DIR}) - -endif() - # build for 3rd party libraries if(LINUX OR APPLE) add_subdirectory(external/unzip) diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake new file mode 100644 index 0000000000..7f68ce2d31 --- /dev/null +++ b/cmake/Modules/FindFMODEX.cmake @@ -0,0 +1,72 @@ +#.rst: +# FindFMODEX +# ------------ +# +# Locate FMOD Ex library +# +# This module defines +# +# :: +# +# FMODEX_LIBRARIES, the library to link against +# FMODEX_FOUND, if false, do not try to link to fmodex +# FMODEX_INCLUDE_DIRS, where to find headers. +# + +# Try find fmodex for our arch in external folder +set(_FMOD_COCOS_PATHS + ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/fmod + ${COCOS_EXTERNAL_DIR}/fmod + ) +if(USE_PREBUILT_LIBS) + find_path(FMODEX_INCLUDE_DIR fmod.h + PATH_SUFFIXES include/${ARCH_DIR} include + PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH + ) + find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 + PATH_SUFFIXES prebuilt/${ARCH_DIR} prebuilt + PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH + ) + # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) + if(NOT FMODEX_INCLUDE_DIR OR NOT FMODEX_LIBRARY) + unset(FMODEX_INCLUDE_DIR CACHE) + unset(FMODEX_LIBRARY CACHE) + endif() +endif(USE_PREBUILT_LIBS) + +find_path(FMODEX_INCLUDE_DIR fmod.h + HINTS ENV FMODEX_DIR + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 + HINTS ENV FMODEX_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +set(FMODEX_INCLUDE_DIRS "${FMODEX_INCLUDE_DIR}") +set(FMODEX_LIBRARIES "${FMODEX_LIBRARY}") + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(FMODEX DEFAULT_MSG FMODEX_LIBRARIES FMODEX_INCLUDE_DIRS) + +mark_as_advanced(FMODEX_INCLUDE_DIR FMODEX_LIBRARY FMODEX_INCLUDE_DIRS FMODEX_LIBRARIES) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2ff9e03d61..052923d5b2 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -99,18 +99,13 @@ endif() add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(FMOD_LIB "fmodex64") -elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(FMOD_LIB "fmodex") -endif() - if(MINGW) set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) elseif(WINDOWS) set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) elseif(LINUX) - set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMOD_LIB}) + include_directories(${FMODEX_INCLUDE_DIRS}) + set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From f8c56ebbf911bda89237b6ada781201c18f15456 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 20:00:51 +0300 Subject: [PATCH 31/67] Fix finding fmodex on ArchLinux --- cmake/Modules/FindFMODEX.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake index 7f68ce2d31..d1318e6c03 100644 --- a/cmake/Modules/FindFMODEX.cmake +++ b/cmake/Modules/FindFMODEX.cmake @@ -36,7 +36,7 @@ endif(USE_PREBUILT_LIBS) find_path(FMODEX_INCLUDE_DIR fmod.h HINTS ENV FMODEX_DIR - PATH_SUFFIXES include + PATH_SUFFIXES include/fmodex include PATHS ~/Library/Frameworks /Library/Frameworks From 5dabf5719c93709bb3479d99725e014183e8aead Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 20:08:54 +0300 Subject: [PATCH 32/67] Fix webp searching --- cmake/Modules/FindWebP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindWebP.cmake b/cmake/Modules/FindWebP.cmake index 8d93dec9f4..5c1d378d0b 100644 --- a/cmake/Modules/FindWebP.cmake +++ b/cmake/Modules/FindWebP.cmake @@ -64,7 +64,7 @@ FIND_PATH(WEBP_INCLUDE_DIR decode.h ) FIND_LIBRARY(WEBP_LIBRARY - NAMES WEBP libWEBP + NAMES webp libwebp HINTS ENV WEBP_DIR PATH_SUFFIXES lib From b7521dcbae10311153326b433dcc849eae36bd91 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 21:14:00 +0300 Subject: [PATCH 33/67] Remove unused variables. --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe92223631..8bc628b681 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,12 +141,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -if(LINUX) - set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}/${ARCH_DIR}) -elseif(NOT MINGW) - set(PLATFORM_FOLDER_ARCH ${PLATFORM_FOLDER}) -endif() - if(LINUX) find_package(FMODEX REQUIRED) message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") From 1e8aeb7fd2766c8a8809a7fa3ca43ca0808299ea Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Sun, 16 Nov 2014 22:41:37 +0300 Subject: [PATCH 34/67] Minizip 1. Add cmake module for finding minizip in system 2. Check that system installed minizip recent enough for us 3. As right minizip exists only for MSYS2 (mingw), use our embedded version on all other platforms 4. Correctly include minizip as if it is found from system (make it compatible to current build system, so by default all should stay same) 5. Remove one unused include of unzip.h --- CMakeLists.txt | 22 +++++++- cmake/Modules/FindMINIZIP.cmake | 51 +++++++++++++++++++ cocos/CMakeLists.txt | 14 ++--- cocos/base/ZipUtils.cpp | 7 ++- cocos/platform/CCFileUtils.cpp | 6 ++- cocos/platform/apple/CCFileUtils-apple.mm | 2 - extensions/assets-manager/AssetsManager.cpp | 4 ++ extensions/assets-manager/AssetsManagerEx.cpp | 4 ++ 8 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 cmake/Modules/FindMINIZIP.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bc628b681..8c950ec8e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,6 +211,27 @@ message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") +# 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_PREBUILT_LIBS OR NOT MINGW) + add_subdirectory(external/unzip) + set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip) + set(MINIZIP_LIBRARIES unzip) +else() + find_package(MINIZIP REQUIRED) + # double check that we have needed functions + include(CheckLibaryExists) + check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2) + if(NOT MINIZIP_HAS_GOTOFIRSTFILE2) + message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS") + endif() + add_definitions(-DMINIZIP_FROM_SYSTEM) +endif() +message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") + find_package(PNG REQUIRED) message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") @@ -243,7 +264,6 @@ message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") # build for 3rd party libraries if(LINUX OR APPLE) -add_subdirectory(external/unzip) add_subdirectory(external/xxhash) endif() diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake new file mode 100644 index 0000000000..2d4e83cda7 --- /dev/null +++ b/cmake/Modules/FindMINIZIP.cmake @@ -0,0 +1,51 @@ +#.rst: +# FindMINIZIP +# ------------ +# +# Locate minizip library (from zlib package) +# +# This module defines +# +# :: +# +# MINIZIP_LIBRARIES, the library to link against +# MINIZIP_FOUND, if false, do not try to link to fmodex +# MINIZIP_INCLUDE_DIRS, where to find headers. +# + +find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h + HINTS ENV MINIZIP_DIR + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +find_library(MINIZIP_LIBRARY NAMES miniunzip libminiunzip + HINTS ENV MINIZIP_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ) + +set(MINIZIP_INCLUDE_DIRS "${MINIZIP_INCLUDE_DIR}") +set(MINIZIP_LIBRARIES "${MINIZIP_LIBRARY}") + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(MINIZIP DEFAULT_MSG MINIZIP_LIBRARIES MINIZIP_INCLUDE_DIRS) + +mark_as_advanced(MINIZIP_INCLUDE_DIR MINIZIP_LIBRARY) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 052923d5b2..8d6489cdd9 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -81,16 +81,6 @@ set(COCOS_SRC cocos2d.cpp ${COCOS_EXTENSIONS_SRC} ) -if(NOT MINGW) - - #todo: provide prebuild versions of minizip for android ios mac and msvc - #done: prebuilt version for mingw-w64 (linux distros should have them also) - # check for opensuse the buildbot system arch and ubuntu - - include_directories( ../external/unzip ) - -endif() - #todo: provide prebuild versions of the xx libs for all platforms include_directories( ../external/xxhash @@ -144,6 +134,7 @@ add_definitions(${PNG_DEFINITIONS}) include_directories( ${ZLIB_INCLUDE_DIRS} + ${MINIZIP_INCLUDE_DIRS} ${JPEG_INCLUDE_DIRS} ${PNG_INCLUDE_DIRS} ${TIFF_INCLUDE_DIRS} @@ -153,8 +144,9 @@ include_directories( ${PROTOBUF_INCLUDE_DIRS} ) target_link_libraries(cocos2d - unzip xxhash + xxhash ${ZLIB_LIBRARIES} + ${MINIZIP_LIBRARIES} ${JPEG_LIBRARIES} ${PNG_LIBRARIES} ${TIFF_LIBRARIES} diff --git a/cocos/base/ZipUtils.cpp b/cocos/base/ZipUtils.cpp index eb2938dc22..2110643d41 100644 --- a/cocos/base/ZipUtils.cpp +++ b/cocos/base/ZipUtils.cpp @@ -24,7 +24,12 @@ ****************************************************************************/ // FIXME: hack, must be included before ziputils +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif + #include "base/ZipUtils.h" #include @@ -37,7 +42,7 @@ #include // FIXME: Other platforms should use upstream minizip like mingw-w64 -#ifdef __MINGW32__ +#ifdef MINIZIP_FROM_SYSTEM #define unzGoToFirstFile64(A,B,C,D) unzGoToFirstFile2(A,B,C,D, NULL, 0, NULL, 0) #define unzGoToNextFile64(A,B,C,D) unzGoToNextFile2(A,B,C,D, NULL, 0, NULL, 0) #endif diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 1d17d4fca8..e0243183fc 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -34,7 +34,11 @@ THE SOFTWARE. #include "base/ccUtils.h" #include "tinyxml2.h" +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif #include #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) @@ -653,7 +657,7 @@ unsigned char* FileUtils::getFileDataFromZip(const std::string& zipFilePath, con CC_BREAK_IF(!file); // FIXME: Other platforms should use upstream minizip like mingw-w64 - #ifdef __MINGW32__ + #ifdef MINIZIP_FROM_SYSTEM int ret = unzLocateFile(file, filename.c_str(), NULL); #else int ret = unzLocateFile(file, filename.c_str(), 1); diff --git a/cocos/platform/apple/CCFileUtils-apple.mm b/cocos/platform/apple/CCFileUtils-apple.mm index ae81af2b7e..5ebd81f730 100644 --- a/cocos/platform/apple/CCFileUtils-apple.mm +++ b/cocos/platform/apple/CCFileUtils-apple.mm @@ -35,8 +35,6 @@ THE SOFTWARE. #include "deprecated/CCDictionary.h" #include "platform/CCFileUtils.h" #include "platform/CCSAXParser.h" -#include "unzip.h" - NS_CC_BEGIN diff --git a/extensions/assets-manager/AssetsManager.cpp b/extensions/assets-manager/AssetsManager.cpp index d3f57bb3e4..cfdc61fae1 100644 --- a/extensions/assets-manager/AssetsManager.cpp +++ b/extensions/assets-manager/AssetsManager.cpp @@ -41,7 +41,11 @@ #include "base/CCUserDefault.h" #include "platform/CCFileUtils.h" +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif using namespace cocos2d; using namespace std; diff --git a/extensions/assets-manager/AssetsManagerEx.cpp b/extensions/assets-manager/AssetsManagerEx.cpp index c772f9eb14..95d46b029f 100644 --- a/extensions/assets-manager/AssetsManagerEx.cpp +++ b/extensions/assets-manager/AssetsManagerEx.cpp @@ -30,7 +30,11 @@ #include #include +#ifdef MINIZIP_FROM_SYSTEM +#include +#else // from our embedded sources #include "unzip.h" +#endif using namespace cocos2d; using namespace std; From b5266e95bfdab62b5bd6bdf6ef394159c3cf3bf3 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Mon, 17 Nov 2014 01:42:04 +0300 Subject: [PATCH 35/67] mingw fixes, now project builds with mingw64 and -DUSE_PREBUILT_LIBS=NO (some additional libs hardcoded still) --- CMakeLists.txt | 2 +- cmake/Modules/FindMINIZIP.cmake | 2 +- cocos/CMakeLists.txt | 4 +-- cocos/audio/CMakeLists.txt | 5 ++- cocos/scripting/lua-bindings/CMakeLists.txt | 36 ++++++++++++--------- tests/cpp-empty-test/CMakeLists.txt | 25 +++++--------- tests/cpp-tests/CMakeLists.txt | 17 ++++------ tests/lua-empty-test/project/CMakeLists.txt | 25 ++++++-------- tests/lua-tests/project/CMakeLists.txt | 23 ++++++------- 9 files changed, 62 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c950ec8e6..950500bd44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,7 +223,7 @@ if(USE_PREBUILT_LIBS OR NOT MINGW) else() find_package(MINIZIP REQUIRED) # double check that we have needed functions - include(CheckLibaryExists) + include(CheckLibraryExists) check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2) if(NOT MINIZIP_HAS_GOTOFIRSTFILE2) message(FATAL_ERROR "Minizip library on you system very old. Please use recent version from https://github.com/nmoinvaz/minizip or enable USE_PREBUILT_LIBS") diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake index 2d4e83cda7..1a00d88fdf 100644 --- a/cmake/Modules/FindMINIZIP.cmake +++ b/cmake/Modules/FindMINIZIP.cmake @@ -27,7 +27,7 @@ find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h /opt ) -find_library(MINIZIP_LIBRARY NAMES miniunzip libminiunzip +find_library(MINIZIP_LIBRARY NAMES minizip libminizip HINTS ENV MINIZIP_DIR PATH_SUFFIXES lib PATHS diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 8d6489cdd9..c8a4e3b11b 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -90,9 +90,9 @@ set(COCOS_SRC cocos2d.cpp add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) if(MINGW) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 iconv bz2) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 winmm mpg123 iconv bz2 ogg vorbis vorbisfile OpenAL32) elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libiconv) + set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libwinmm libiconv) elseif(LINUX) include_directories(${FMODEX_INCLUDE_DIRS}) set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) diff --git a/cocos/audio/CMakeLists.txt b/cocos/audio/CMakeLists.txt index c2e12f8769..38669fd30b 100644 --- a/cocos/audio/CMakeLists.txt +++ b/cocos/audio/CMakeLists.txt @@ -7,7 +7,10 @@ if(WINDOWS) set(COCOS_AUDIO_PLATFORM_SRC audio/win32/SimpleAudioEngine.cpp audio/win32/MciPlayer.cpp - audio/win32/MciPlayer.h + audio/win32/MciPlayer.h + audio/win32/AudioEngine-win32.cpp + audio/win32/AudioCache.cpp + audio/win32/AudioPlayer.cpp ) elseif(LINUX) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 3becd4f99f..61998d6c1a 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -32,25 +32,29 @@ file(GLOB lua_cocos2d_source_files "${cocos_root}/external/xxtea/xxtea.cpp" ) -# luasockets are needed in Linux too, -# but Linux have them disabled for some reason -if(MACOSX) - set(lua_cocos2d_source_files - ${lua_cocos2d_source_files} - ${cocos_root}/external/lua/luasocket/auxiliar.c - ${cocos_root}/external/lua/luasocket/buffer.c - ${cocos_root}/external/lua/luasocket/except.c - ${cocos_root}/external/lua/luasocket/inet.c - ${cocos_root}/external/lua/luasocket/io.c +list(APPEND lua_cocos2d_source_files ${cocos_root}/external/lua/luasocket/luasocket.c - ${cocos_root}/external/lua/luasocket/luasocket_scripts.c - ${cocos_root}/external/lua/luasocket/mime.c - ${cocos_root}/external/lua/luasocket/options.c - ${cocos_root}/external/lua/luasocket/select.c - ${cocos_root}/external/lua/luasocket/serial.c - ${cocos_root}/external/lua/luasocket/tcp.c ${cocos_root}/external/lua/luasocket/timeout.c + ${cocos_root}/external/lua/luasocket/buffer.c + ${cocos_root}/external/lua/luasocket/io.c + ${cocos_root}/external/lua/luasocket/auxiliar.c + ${cocos_root}/external/lua/luasocket/options.c + ${cocos_root}/external/lua/luasocket/inet.c + ${cocos_root}/external/lua/luasocket/except.c + ${cocos_root}/external/lua/luasocket/select.c + ${cocos_root}/external/lua/luasocket/tcp.c ${cocos_root}/external/lua/luasocket/udp.c + ${cocos_root}/external/lua/luasocket/mime.c + ${cocos_root}/external/lua/luasocket/luasocket_scripts.c + ) + +if(WINDOWS) + list(APPEND lua_cocos2d_source_files + ${cocos_root}/external/lua/luasocket/wsocket.c + ) +elseif(UNIX) + list(APPEND lua_cocos2d_source_files + ${cocos_root}/external/lua/luasocket/serial.c ${cocos_root}/external/lua/luasocket/unix.c ${cocos_root}/external/lua/luasocket/usocket.c ) diff --git a/tests/cpp-empty-test/CMakeLists.txt b/tests/cpp-empty-test/CMakeLists.txt index 0fde5bb6bd..fa3f9ab5c9 100644 --- a/tests/cpp-empty-test/CMakeLists.txt +++ b/tests/cpp-empty-test/CMakeLists.txt @@ -1,15 +1,11 @@ set(APP_NAME cpp-empty-test) if(ANDROID) - set(PLATFORM_SRC - proj.android/jni/hellocpp/main.cpp - ) - + set(PLATFORM_SRC proj.android/jni/hellocpp/main.cpp) + set(RES_PREFIX "/Resources") elseif(WINDOWS) - set(PLATFORM_SRC - proj.win32/main.cpp - ) - + set(PLATFORM_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(IOS) set(PLATFORM_SRC proj.ios/main.m @@ -18,19 +14,15 @@ elseif(IOS) ) elseif(MACOSX OR APPLE) - set(PLATFORM_SRC - proj.mac/main.cpp - ) + set(PLATFORM_SRC proj.mac/main.cpp) file(GLOB_RECURSE RES_FILES Resources/*) cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources) list(APPEND PLATFORM_SRC ${RES_FILES}) elseif(LINUX) - set(PLATFORM_SRC - proj.linux/main.cpp - ) - + set(PLATFORM_SRC proj.linux/main.cpp) + set(RES_PREFIX "/Resources") else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) @@ -83,8 +75,7 @@ else() set_target_properties(${APP_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${APP_BIN_DIR}") add_custom_command(TARGET ${APP_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove_directory $/Resources - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $${RES_PREFIX} ) endif() diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index b470f4f2d6..6dd51fdcd2 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -1,22 +1,18 @@ set(APP_NAME cpp-tests) if(WIN32) - set(PLATFORM_SRC - proj.win32/main.cpp - ) + set(PLATFORM_SRC proj.win32/main.cpp) + set(RES_PREFIX "") elseif(MACOSX) - set(PLATFORM_SRC - proj.mac/main.cpp - ) + set(PLATFORM_SRC proj.mac/main.cpp) file(GLOB_RECURSE RES_FILES Resources/*) cocos_mark_resources(FILES ${RES_FILES} BASEDIR Resources) list(APPEND PLATFORM_SRC ${RES_FILES}) elseif(LINUX) - set(PLATFORM_SRC - proj.linux/main.cpp - ) + set(PLATFORM_SRC proj.linux/main.cpp) + set(RES_PREFIX "/Resources") else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() @@ -263,8 +259,7 @@ else() 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}/Resources ${APP_BIN_DIR}/Resources + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}${RES_PREFIX} ) endif() diff --git a/tests/lua-empty-test/project/CMakeLists.txt b/tests/lua-empty-test/project/CMakeLists.txt index 362fe2df48..399d645dec 100644 --- a/tests/lua-empty-test/project/CMakeLists.txt +++ b/tests/lua-empty-test/project/CMakeLists.txt @@ -1,19 +1,15 @@ set(APP_NAME lua-empty-test) -set(SAMPLE_SRC - Classes/AppDelegate.cpp -) +set(SAMPLE_SRC Classes/AppDelegate.cpp) if(LINUX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.linux/main.cpp - ) + 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 "") elseif(MACOSX OR APPLE) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.mac/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.mac/main.cpp) file(GLOB_RECURSE APP_RESOURCES ../res/*) cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res) @@ -50,10 +46,9 @@ else() 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 ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos + 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 ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos ) endif() diff --git a/tests/lua-tests/project/CMakeLists.txt b/tests/lua-tests/project/CMakeLists.txt index 96fb6b6b87..75858d3c42 100644 --- a/tests/lua-tests/project/CMakeLists.txt +++ b/tests/lua-tests/project/CMakeLists.txt @@ -7,15 +7,13 @@ set(SAMPLE_SRC ) if(LINUX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.linux/main.cpp - ) + 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 "") elseif(MACOSX) - set(SAMPLE_SRC - ${SAMPLE_SRC} - proj.ios_mac/mac/main.cpp - ) + set(SAMPLE_SRC ${SAMPLE_SRC} proj.ios_mac/mac/main.cpp) file(GLOB_RECURSE APP_RESOURCES ../res/*) cocos_mark_resources(FILES ${APP_RESOURCES} BASEDIR ../res RESOURCEBASE Resources/res) @@ -55,11 +53,10 @@ else() 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 ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}/Resources/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}/../src ${APP_BIN_DIR}${RES_PREFIX}/src + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res ) endif() From 590975d08d86e89c22fef41be7dd9caf660703a4 Mon Sep 17 00:00:00 2001 From: Noel Cower Date: Mon, 17 Nov 2014 08:26:23 -0800 Subject: [PATCH 36/67] Also un-ignore libs dir under plugins. The configure script isn't smart enough to check if there are un-ignored files in a directory, so this fixes that. --- tools/travis-scripts/config.gitingore | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/travis-scripts/config.gitingore b/tools/travis-scripts/config.gitingore index a0142c9bf8..46351496cb 100644 --- a/tools/travis-scripts/config.gitingore +++ b/tools/travis-scripts/config.gitingore @@ -115,6 +115,7 @@ tags !/cocos/2d/platform/android/java/res/ # Permit plugins to ship third-party libraries. !/plugin/plugins/*/proj.android/libs/*.jar +!/plugin/plugins/*/proj.android/libs v*-deps-*.zip v*-lua-runtime-*.zip From 41027463c9b29d9a26b40f66d9259a4979218541 Mon Sep 17 00:00:00 2001 From: Noel Cower Date: Mon, 17 Nov 2014 08:38:44 -0800 Subject: [PATCH 37/67] Descend into included directories to check for file inclusion. Only applies to directories that are marked as unignored, since the travis script has the odd problem of not descending into those directories and, as a result, not recording the files in them. I'm assuming the failure to descend into included directories is unintended. --- tools/travis-scripts/generate-template-files.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/travis-scripts/generate-template-files.py b/tools/travis-scripts/generate-template-files.py index 6da3e33378..f629d71f68 100755 --- a/tools/travis-scripts/generate-template-files.py +++ b/tools/travis-scripts/generate-template-files.py @@ -97,6 +97,7 @@ class CocosFileList: self.fileList_lua.append("%s/" %relativePath) else: self.fileList_com.append("%s/" %relativePath) + self.__parseFileList(path) continue if ( self.__bExclude("/%s" %relativePath) or From 731e982b2e1054383ec25567d24352cc2a924364 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Mon, 17 Nov 2014 23:44:16 +0300 Subject: [PATCH 38/67] Find OpenGL, GLEW and winmm library, improve finding of curl (use pkg-config first, this teoretically can find also dependant libs). --- CMakeLists.txt | 18 +++++++-- cmake/Modules/FindCURL.cmake | 74 ++++++++++++++++++++---------------- cocos/CMakeLists.txt | 28 +++++++++----- 3 files changed, 74 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 950500bd44..dea1862991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,10 +112,8 @@ else() endif() if(MINGW) - add_definitions(-DGLEW_STATIC) + #add_definitions(-DGLEW_STATIC) add_definitions(-D__SSIZE_T) - set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lws2_32") - set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lws2_32") if(CLANG) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions ") @@ -148,9 +146,23 @@ endif() # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) + find_package(OpenGL REQUIRED) + set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) # fix inconsistency + message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") + + if(LINUX OR WINDOWS) + find_package(GLEW REQUIRED) + message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") + endif() + find_package(GLFW3 REQUIRED) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) + + if(WINDOWS) + find_library(WINMM_LIBRARIES winmm) + message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") + endif() endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake index 543eafc2f5..4d3068737e 100644 --- a/cmake/Modules/FindCURL.cmake +++ b/cmake/Modules/FindCURL.cmake @@ -57,42 +57,50 @@ if(USE_PREBUILT_LIBS) endif() endif() -# Look for the header file. -find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) -mark_as_advanced(CURL_INCLUDE_DIR) +find_package(PkgConfig) +if(PKG_CONFIG_FOUND) + pkg_search_module(CURL QUIET libcurl) +endif() -# Look for the library (sorted from most current/relevant entry to least). -find_library(CURL_LIBRARY NAMES - curl - # Windows MSVC prebuilts: - curllib - libcurl_imp - curllib_static - # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): - libcurl -) -mark_as_advanced(CURL_LIBRARY) +if(NOT CURL_FOUND) -if(CURL_INCLUDE_DIR) - foreach(_curl_version_header curlver.h curl.h) - if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") - file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + # Look for the header file. + find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) + mark_as_advanced(CURL_INCLUDE_DIR) - string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") - unset(curl_version_str) - break() + # Look for the library (sorted from most current/relevant entry to least). + find_library(CURL_LIBRARY NAMES + curl + # Windows MSVC prebuilts: + curllib + libcurl_imp + curllib_static + # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): + libcurl + ) + mark_as_advanced(CURL_LIBRARY) + + if(CURL_INCLUDE_DIR) + foreach(_curl_version_header curlver.h curl.h) + if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + unset(curl_version_str) + break() + endif() + endforeach() endif() - endforeach() + + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) + + if(CURL_FOUND) + set(CURL_LIBRARIES ${CURL_LIBRARY}) + set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) + endif() + endif() -# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if -# all listed variables are TRUE -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL - REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR - VERSION_VAR CURL_VERSION_STRING) - -if(CURL_FOUND) - set(CURL_LIBRARIES ${CURL_LIBRARY}) - set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) -endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c8a4e3b11b..2399bedf23 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -89,13 +89,22 @@ set(COCOS_SRC cocos2d.cpp add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) -if(MINGW) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 winmm mpg123 iconv bz2 ogg vorbis vorbisfile OpenAL32) -elseif(WINDOWS) - set(PLATFORM_SPECIFIC_LIBS glew32 opengl32 libwinmm libiconv) +set(PLATFORM_SPECIFIC_LIBS) +if(WINDOWS) + foreach(_pkg OPENGL GLEW GLFW3 WINMM) + include_directories(${${_pkg}_INCLUDE_DIRS}) + list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + endforeach() + if(MINGW) + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 mpg123 bz2 ogg vorbis vorbisfile OpenAL32) + endif() elseif(LINUX) + foreach(_pkg OPENGL GLEW GLFW3 FMODEX) + include_directories(${${_pkg}_INCLUDE_DIRS}) + list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + endforeach() include_directories(${FMODEX_INCLUDE_DIRS}) - set(PLATFORM_SPECIFIC_LIBS ssl crypto fontconfig pthread GLEW GL X11 rt ${FMODEX_LIBRARIES}) + list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) @@ -125,11 +134,6 @@ else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() -# Add GLFW3 for desktop platforms -if(LINUX OR MACOSX OR WINDOWS) - list(APPEND PLATFORM_SPECIFIC_LIBS ${GLFW3_LIBRARIES}) -endif() - add_definitions(${PNG_DEFINITIONS}) include_directories( @@ -158,6 +162,10 @@ target_link_libraries(cocos2d ${PLATFORM_SPECIFIC_LIBS} ) +if(CURL_LIBRARY_DIRS) + link_directories(${CURL_LIBRARY_DIRS}) +endif() + if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) include_directories(${WEBP_INCLUDE_DIRS}) From 95e005d785bc96162b233dc0243c2c354c62709b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 01:46:41 +0300 Subject: [PATCH 39/67] Find vorbis, mpg123 and OpenAL libs in unified way. Test another way to customize our prebuilt paths... Cleanups. --- CMakeLists.txt | 25 +++++++++++++++++++++++++ cmake/Modules/FindMPG123.cmake | 17 +++++++++++++++++ cmake/Modules/FindOgg.cmake | 20 ++++++++++++++++++++ cmake/Modules/FindVorbis.cmake | 29 +++++++++++++++++++++++++++++ cocos/CMakeLists.txt | 7 ++----- 5 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 cmake/Modules/FindMPG123.cmake create mode 100644 cmake/Modules/FindOgg.cmake create mode 100644 cmake/Modules/FindVorbis.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dea1862991..8b6b1ea23a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,6 +162,31 @@ if(LINUX OR MACOSX OR WINDOWS) if(WINDOWS) find_library(WINMM_LIBRARIES winmm) message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") + + if(USE_PREBUILT_LIBS) + set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) + list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) + list(APPEND CMAKE_LIBRARY_PATH ${VORBIS_PREBUILT_ROOT}/prebuilt) + endif() + find_package(Vorbis REQUIRED) + message(STATUS "Vorbis include dirs: ${VORBIS_INCLUDE_DIRS}") + + if(USE_PREBUILT_LIBS) + list(APPEND CMAKE_INCLUDE_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/include) + list(APPEND CMAKE_LIBRARY_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt) + endif() + find_package(MPG123 REQUIRED) + message(STATUS "MPG123 include dirs: ${MPG123_INCLUDE_DIRS}") + + if(USE_PREBUILT_LIBS) + set(OPENAL_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OpenalSoft) + list(APPEND CMAKE_INCLUDE_PATH ${OPENAL_PREBUILT_ROOT}) + list(APPEND CMAKE_LIBRARY_PATH ${OPENAL_PREBUILT_ROOT}/prebuilt) + endif() + find_package(OpenAL REQUIRED) + set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) + set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) diff --git a/cmake/Modules/FindMPG123.cmake b/cmake/Modules/FindMPG123.cmake new file mode 100644 index 0000000000..61e450a2c2 --- /dev/null +++ b/cmake/Modules/FindMPG123.cmake @@ -0,0 +1,17 @@ +# - Find mpg123 +# Find the native mpg123 includes and libraries +# +# MPG123_INCLUDE_DIRS - where to find mpg123.h, etc. +# MPG123_LIBRARIES - List of libraries when using mpg123. +# MPG123_FOUND - True if mpg123 found. + +find_path(MPG123_INCLUDE_DIR mpg123.h) +find_library(MPG123_LIBRARY NAMES mpg123 libmpg123) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MPG123 DEFAULT_MSG MPG123_INCLUDE_DIR MPG123_LIBRARY) + +set(MPG123_INCLUDE_DIRS ${MPG123_INCLUDE_DIR}) +set(MPG123_LIBRARIES ${MPG123_LIBRARY}) + +mark_as_advanced(MPG123_INCLUDE_DIR MPG123_LIBRARY) diff --git a/cmake/Modules/FindOgg.cmake b/cmake/Modules/FindOgg.cmake new file mode 100644 index 0000000000..a3c06d2546 --- /dev/null +++ b/cmake/Modules/FindOgg.cmake @@ -0,0 +1,20 @@ +# - Find ogg +# Find the native ogg includes and libraries +# +# OGG_INCLUDE_DIRS - where to find ogg.h, etc. +# OGG_LIBRARIES - List of libraries when using ogg. +# OGG_FOUND - True if ogg found. + +find_path(OGG_INCLUDE_DIR ogg/ogg.h) +# MSVC built ogg may be named ogg_static. +# The provided project files name the library with the lib prefix. +find_library(OGG_LIBRARY NAMES ogg ogg_static libogg libogg_static) +# Handle the QUIETLY and REQUIRED arguments and set OGG_FOUND +# to TRUE if all listed variables are TRUE. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(OGG DEFAULT_MSG OGG_INCLUDE_DIR OGG_LIBRARY) + +set(OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR}) +set(OGG_LIBRARIES ${OGG_LIBRARY}) + +mark_as_advanced(OGG_INCLUDE_DIR OGG_LIBRARY) diff --git a/cmake/Modules/FindVorbis.cmake b/cmake/Modules/FindVorbis.cmake new file mode 100644 index 0000000000..163dda6fa6 --- /dev/null +++ b/cmake/Modules/FindVorbis.cmake @@ -0,0 +1,29 @@ +# - Find vorbis +# Find the native vorbis includes and libraries +# +# VORBIS_INCLUDE_DIRS - where to find vorbis.h, etc. +# VORBIS_LIBRARIES - List of libraries when using vorbis(file). +# VORBIS_FOUND - True if vorbis found. + +find_package(Ogg) +if(OGG_FOUND) + find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h) + # MSVC built vorbis may be named vorbis_static + # The provided project files name the library with the lib prefix. + find_library(VORBIS_LIBRARY NAMES vorbis vorbis_static libvorbis libvorbis_static) + find_library(VORBISFILE_LIBRARY NAMES vorbisfile vorbisfile_static libvorbisfile libvorbisfile_static) + # Handle the QUIETLY and REQUIRED arguments and set VORBIS_FOUND + # to TRUE if all listed variables are TRUE. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(VORBIS DEFAULT_MSG VORBIS_INCLUDE_DIR VORBIS_LIBRARY VORBISFILE_LIBRARY) +endif(OGG_FOUND) + +if(VORBIS_FOUND) + set(VORBIS_INCLUDE_DIRS ${VORBIS_INCLUDE_DIR}) + set(VORBIS_LIBRARIES ${VORBISFILE_LIBRARY} ${VORBIS_LIBRARY} ${OGG_LIBRARY}) +else(VORBIS_FOUND) + set(VORBIS_INCLUDE_DIRS) + set(VORBIS_LIBRARIES) +endif(VORBIS_FOUND) + +mark_as_advanced(VORBIS_INCLUDE_DIR VORBIS_LIBRARY VORBISFILE_LIBRARY) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 2399bedf23..1c956c18a0 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -91,19 +91,16 @@ add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) - foreach(_pkg OPENGL GLEW GLFW3 WINMM) + foreach(_pkg OPENGL GLEW GLFW3 WINMM VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - if(MINGW) - list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 mpg123 bz2 ogg vorbis vorbisfile OpenAL32) - endif() + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 bz2) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - include_directories(${FMODEX_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From 28d7279cb03671ce51de6a0e373efedfa511115b Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 10:06:45 +0300 Subject: [PATCH 40/67] remove unnneded includes and declarations --- cocos/audio/CMakeLists.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/cocos/audio/CMakeLists.txt b/cocos/audio/CMakeLists.txt index 38669fd30b..27437db0d4 100644 --- a/cocos/audio/CMakeLists.txt +++ b/cocos/audio/CMakeLists.txt @@ -21,8 +21,6 @@ elseif(LINUX) audio/linux/AudioPlayer.h ) - include_directories( ../external/linux-specific/fmod/include/${ARCH_DIR} ) - elseif(MACOSX) # split it in _C and non C # because C files needs to be compiled with C compiler and not C++ @@ -48,16 +46,3 @@ elseif(MACOSX) endif() list(APPEND COCOS_AUDIO_SRC ${COCOS_AUDIO_PLATFORM_SRC}) - -if(LINUX) - if ( CMAKE_SIZEOF_VOID_P EQUAL 8 ) - set(FMOD_LIB "fmodex64") - else() - set(FMOD_LIB "fmodex") - endif() - set(AUDIO_LIB ${FMOD_LIB}) -elseif(WINDOWS) - set(AUDIO_LIB Winmm) -endif() - -include_directories( audio/include ) From d200bdcca082713359543697194ba2432c62c7da Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 10:07:11 +0300 Subject: [PATCH 41/67] fix Winmm linking --- CMakeLists.txt | 3 --- cocos/CMakeLists.txt | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6b1ea23a..5c69f902eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,9 +160,6 @@ if(LINUX OR MACOSX OR WINDOWS) include_directories(${GLFW3_INCLUDE_DIRS}) if(WINDOWS) - find_library(WINMM_LIBRARIES winmm) - message(STATUS "Winmm lib: ${WINMM_LIBRARIES}") - if(USE_PREBUILT_LIBS) set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 1c956c18a0..e186bbb441 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -46,6 +46,7 @@ include(deprecated/CMakeLists.txt) include(ui/CMakeLists.txt) include(network/CMakeLists.txt) include(audio/CMakeLists.txt) +include_directories(audio/include) include(storage/CMakeLists.txt) if(BUILD_EDITOR_COCOSBUILDER) @@ -91,11 +92,11 @@ add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) - foreach(_pkg OPENGL GLEW GLFW3 WINMM VORBIS MPG123 OPENAL) + foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) endforeach() - list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 bz2) + list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) include_directories(${${_pkg}_INCLUDE_DIRS}) From 36e44dbaf962a2fcd13d4a2fa3bb3225b2e0c2bf Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Tue, 18 Nov 2014 22:05:56 +0800 Subject: [PATCH 42/67] set default priority to avoid warning when call 'scheduleUpdate' and 'unscheuleUpdate' several times in one frame, it will get warning "warning: you CANNOT change update priority in scheduled function" --- cocos/base/CCScheduler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/base/CCScheduler.cpp b/cocos/base/CCScheduler.cpp index 18575ac12b..1fb32a1379 100644 --- a/cocos/base/CCScheduler.cpp +++ b/cocos/base/CCScheduler.cpp @@ -447,6 +447,7 @@ void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, voi listElement->callback = callback; listElement->target = target; listElement->paused = paused; + listElement->priority = 0; listElement->markedForDeletion = false; DL_APPEND(*list, listElement); From ba2f74e76c48eb9e0b9e0d81822dbe46aa4eb4c5 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 17:27:43 +0300 Subject: [PATCH 43/67] Fix OpenAL include paths, cmake search include paths for case, when openal includes as "#include " --- CMakeLists.txt | 2 ++ cocos/CMakeLists.txt | 3 +++ cocos/audio/openal/OpenALDecoder.h | 4 ++++ cocos/audio/openal/SimpleAudioEngineOpenAL.cpp | 6 ++++++ cocos/audio/win32/AudioCache.h | 6 +++++- cocos/audio/win32/AudioPlayer.h | 6 +++++- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c69f902eb..6187200ad6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,8 @@ if(LINUX OR MACOSX OR WINDOWS) find_package(OpenAL REQUIRED) set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + # because FindOpenAL.cmake set include dir for '#include ' for portability (not for '#include ' + set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES") message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index e186bbb441..cc8755988d 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -95,6 +95,9 @@ if(WINDOWS) foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) include_directories(${${_pkg}_INCLUDE_DIRS}) list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + if(${_pkg}_DEFINITIONS) + add_definitions(${${_pkg}_DEFINITIONS}) + endif() endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) diff --git a/cocos/audio/openal/OpenALDecoder.h b/cocos/audio/openal/OpenALDecoder.h index aa4d00499b..b97a96be55 100644 --- a/cocos/audio/openal/OpenALDecoder.h +++ b/cocos/audio/openal/OpenALDecoder.h @@ -4,7 +4,11 @@ #include #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else #include +#endif #include "cocos2d.h" #if CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN diff --git a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp index 31872e5ec7..16d95c1412 100644 --- a/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp +++ b/cocos/audio/openal/SimpleAudioEngineOpenAL.cpp @@ -30,9 +30,15 @@ THE SOFTWARE. #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#include +#include +#else #include #include #include +#endif #include "OpenALDecoder.h" #ifdef ENABLE_MPG123 diff --git a/cocos/audio/win32/AudioCache.h b/cocos/audio/win32/AudioCache.h index 6f7c8bb984..9d27d7abd8 100644 --- a/cocos/audio/win32/AudioCache.h +++ b/cocos/audio/win32/AudioCache.h @@ -31,8 +31,12 @@ #include #include #include +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else +#include +#endif #include "CCPlatformMacros.h" -#include "AL/al.h" #define QUEUEBUFFER_NUM 3 #define QUEUEBUFFER_TIME_STEP 0.1f diff --git a/cocos/audio/win32/AudioPlayer.h b/cocos/audio/win32/AudioPlayer.h index 8ae2019e6a..7c20ff3701 100644 --- a/cocos/audio/win32/AudioPlayer.h +++ b/cocos/audio/win32/AudioPlayer.h @@ -31,7 +31,11 @@ #include #include #include -#include "AL/al.h" +#ifdef OPENAL_PLAIN_INCLUDES +#include +#else +#include +#endif #include "CCPlatformMacros.h" NS_CC_BEGIN From b0a6cf1182075ae5b5733a7899cd77bbe90ffb4f Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Tue, 18 Nov 2014 17:48:54 +0300 Subject: [PATCH 44/67] Use standard cmake control variable to control static or dynamic build BUILD_SHARED_LIBS --- CMakeLists.txt | 14 ++++---------- cocos/3d/CMakeLists.txt | 2 +- cocos/CMakeLists.txt | 6 +----- cocos/editor-support/cocostudio/CMakeLists.txt | 2 +- cocos/ui/CMakeLists.txt | 2 +- extensions/CMakeLists.txt | 2 +- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6187200ad6..48c23796f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ 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}) -option(BUILD_STATIC "Build static libraries" ON) +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(DEBUG_MODE "Debug or release?" ON) option(BUILD_EXTENSIONS "Build extension library" ON) option(BUILD_EDITOR_SPINE "Build editor support for spine" ON) @@ -78,21 +78,15 @@ else() endif() endif(MSVC) -if(BUILD_STATIC) - set (BUILD_TYPE STATIC) -else() - set (BUILD_TYPE SHARED) -endif() - set(COCOS_EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external) # Some macro definitions if(WINDOWS) - if(BUILD_STATIC) - ADD_DEFINITIONS (-DCC_STATIC) - else() + if(BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USRDLL -D_EXPORT_DLL_ -D_USEGUIDLL -D_USREXDLL -D_USRSTUDIODLL) + else() + ADD_DEFINITIONS (-DCC_STATIC) endif() ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32) diff --git a/cocos/3d/CMakeLists.txt b/cocos/3d/CMakeLists.txt index ce58d57fbb..0e35a5a63e 100644 --- a/cocos/3d/CMakeLists.txt +++ b/cocos/3d/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USE3DDLL) endif() diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index cc8755988d..edd6ea4c6f 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -31,10 +31,6 @@ if(WINDOWS) ADD_DEFINITIONS(-DUNICODE -D_UNICODE) endif() -if(WINDOWS AND NOT BUILD_STATIC) - ADD_DEFINITIONS (-D_USRDLL) -endif() - include(2d/CMakeLists.txt) include(3d/CMakeLists.txt) include(platform/CMakeLists.txt) @@ -88,7 +84,7 @@ set(COCOS_SRC cocos2d.cpp ../external/xxtea) -add_library(cocos2d ${BUILD_TYPE} ${COCOS_SRC}) +add_library(cocos2d ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) diff --git a/cocos/editor-support/cocostudio/CMakeLists.txt b/cocos/editor-support/cocostudio/CMakeLists.txt index 6dd775e1fd..51a34f89a6 100644 --- a/cocos/editor-support/cocostudio/CMakeLists.txt +++ b/cocos/editor-support/cocostudio/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USRSTUDIODLL) endif() diff --git a/cocos/ui/CMakeLists.txt b/cocos/ui/CMakeLists.txt index 696a83295a..42f2cde9a8 100644 --- a/cocos/ui/CMakeLists.txt +++ b/cocos/ui/CMakeLists.txt @@ -1,5 +1,5 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USEGUIDLL) endif() diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 5a2ef4f2a9..17f7b95a95 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WINDOWS AND NOT BUILD_STATIC) +if(WINDOWS AND BUILD_SHARED_LIBS) ADD_DEFINITIONS (-D_USREXDLL) endif() From fe25c860cb240c3d353de7b9005b97e0fee3a0a2 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 00:27:25 +0300 Subject: [PATCH 45/67] Fixes for freetype, protobuf and more unifications. Also it case of static library in some find* modules we try to use pkg-config first, it is chance to get dependency info --- CMakeLists.txt | 6 +-- cmake/Modules/CocosBuildHelpers.cmake | 68 +++++++++++++++++++++++++++ cmake/Modules/FindFreetype.cmake | 10 +++- cmake/Modules/FindMINIZIP.cmake | 9 ++++ cocos/CMakeLists.txt | 52 ++++---------------- 5 files changed, 98 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48c23796f5..5960f16f94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,6 @@ endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms find_package(Freetype REQUIRED) message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") -include_directories(${FREETYPE_INCLUDE_DIRS}) # WebP required if used if(USE_WEBP) @@ -283,13 +282,14 @@ message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") # compiled only with our in-source version of protobuf-lite ## if(USE_PREBUILT_LIBS) add_subdirectory(external/protobuf-lite) - set(PROTOBUF_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) + set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) set(PROTOBUF_LITE_LIBRARIES protobuf) ## else() ## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) ## endif() message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") -message(STATUS "Protobuf include dirs: ${PROTOBUF_INCLUDE_DIRS}") +message(STATUS "Protobuf include dirs: ${PROTOBUF_LITE_INCLUDE_DIRS}") # build for 3rd party libraries diff --git a/cmake/Modules/CocosBuildHelpers.cmake b/cmake/Modules/CocosBuildHelpers.cmake index c90ed82c08..2cd2aea9d1 100644 --- a/cmake/Modules/CocosBuildHelpers.cmake +++ b/cmake/Modules/CocosBuildHelpers.cmake @@ -36,6 +36,74 @@ function(cocos_mark_resources) endforeach() endfunction() +# cocos_use_pkg(pkg) function. +# This function applies standard package variables (after find_package(pkg) call) to current scope +# Recognized variables: _INCLUDE_DIRS, _LIBRARIES, _LIBRARY_DIRS +# Also if BUILD_SHARED_LIBS variable off, it is try to use _STATIC_* vars before +function(cocos_use_pkg target pkg) + set(prefix ${pkg}) + if(NOT BUILD_SHARED_LIBS) + set(prefix_static ${pkg}_STATIC) + else() + set(prefix_static) + endif() + + set(_include_dirs) + if(prefix_static AND ${prefix_static}_INCLUDE_DIRS) + set(_include_dirs ${${prefix_static}_INCLUDE_DIRS}) + endif() + if(NOT _include_dirs) + set(_include_dirs ${${prefix}_INCLUDE_DIRS}) + endif() + if(NOT _include_dirs) + # backward compat with old package-find scripts + set(_include_dirs ${${prefix}_INCLUDE_DIR}) + endif() + if(_include_dirs) + include_directories(${_include_dirs}) + message(STATUS "${pkg} add to include_dirs: ${_include_dirs}") + endif() + + set(_library_dirs) + if(prefix_static AND ${prefix_static}_LIBRARY_DIRS) + set(_library_dirs ${${prefix_static}_LIBRARY_DIRS}) + endif() + if(NOT _library_dirs) + set(_library_dirs ${${prefix}_LIBRARY_DIRS}) + endif() + if(_library_dirs) + link_directories(${_library_dirs}) + message(STATUS "${pkg} add to link_dirs: ${_library_dirs}") + endif() + + set(_libs) + if(prefix_static AND ${prefix_static}_LIBRARIES) + set(_libs ${${prefix_static}_LIBRARIES}) + endif() + if(NOT _libs) + set(_libs ${${prefix}_LIBRARIES}) + endif() + if(NOT _libs) + set(_libs ${${prefix}_LIBRARY}) + endif() + if(_libs) + target_link_libraries(${target} ${_libs}) + message(STATUS "${pkg} libs added to '${target}': ${_libs}") + endif() + + set(_defs) + if(prefix_static AND ${prefix_static}_CFLAGS_OTHER) + set(_defs ${${prefix_static}_CFLAGS_OTHER}) + endif() + if(NOT _defs) + set(_defs ${${prefix}_DEFINITIONS}) + endif() + if(_defs) + add_definitions(${_defs}) + message(STATUS "${pkg} add definitions: ${_defs}") + endif() +endfunction() + #cmake has some strange defaults, this should help us a lot #Please use them everywhere diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index e4cee08134..e6ef8874f5 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -68,6 +68,11 @@ if(USE_PREBUILT_LIBS) endif() endif(USE_PREBUILT_LIBS) +# Try pkg-config first (because it provided deps info) +find_package(PkgConfig) +pkg_search_module(FREETYPE freetype2) +if(NOT FREETYPE_FOUND) + # Ugh, FreeType seems to use some #include trickery which # makes this harder than it should be. It looks like they # put ft2build.h in a common/easier-to-find location which @@ -172,12 +177,15 @@ if(FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_H) endforeach() endif() +set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype - REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS + REQUIRED_VARS FREETYPE_LIBRARIES FREETYPE_INCLUDE_DIRS VERSION_VAR FREETYPE_VERSION_STRING) +endif(NOT FREETYPE_FOUND) + mark_as_advanced(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) diff --git a/cmake/Modules/FindMINIZIP.cmake b/cmake/Modules/FindMINIZIP.cmake index 1a00d88fdf..93efa3595d 100644 --- a/cmake/Modules/FindMINIZIP.cmake +++ b/cmake/Modules/FindMINIZIP.cmake @@ -13,6 +13,15 @@ # MINIZIP_INCLUDE_DIRS, where to find headers. # +# Try pkg-config first +if(NOT MINIZIP_LIBRARY AND NOT MINIZIP_INCLUDE_DIR) + find_package(PkgConfig) + pkg_search_module(MINIZIP minizip) + if(MINIZIP_FOUND) + return() + endif() +endif() + find_path(MINIZIP_INCLUDE_DIR minizip/unzip.h HINTS ENV MINIZIP_DIR PATH_SUFFIXES include diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index edd6ea4c6f..9a358459f1 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -89,17 +89,12 @@ add_library(cocos2d ${COCOS_SRC}) set(PLATFORM_SPECIFIC_LIBS) if(WINDOWS) foreach(_pkg OPENGL GLEW GLFW3 VORBIS MPG123 OPENAL) - include_directories(${${_pkg}_INCLUDE_DIRS}) - list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) - if(${_pkg}_DEFINITIONS) - add_definitions(${${_pkg}_DEFINITIONS}) - endif() + cocos_use_pkg(cocos2d ${_pkg}) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) foreach(_pkg OPENGL GLEW GLFW3 FMODEX) - include_directories(${${_pkg}_INCLUDE_DIRS}) - list(APPEND PLATFORM_SPECIFIC_LIBS ${${_pkg}_LIBRARIES}) + cocos_use_pkg(cocos2d ${_pkg}) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) @@ -131,54 +126,25 @@ else() message( FATAL_ERROR "Unsupported platform, CMake will exit" ) endif() -add_definitions(${PNG_DEFINITIONS}) +foreach(pkg ZLIB MINIZIP JPEG PNG TIFF TinyXML2 FREETYPE WEBSOCKETS CURL PROTOBUF_LITE) + cocos_use_pkg(cocos2d ${pkg}) +endforeach() -include_directories( - ${ZLIB_INCLUDE_DIRS} - ${MINIZIP_INCLUDE_DIRS} - ${JPEG_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${TIFF_INCLUDE_DIRS} - ${TinyXML2_INCLUDE_DIRS} - ${WEBSOCKETS_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} - ${PROTOBUF_INCLUDE_DIRS} - ) -target_link_libraries(cocos2d - xxhash - ${ZLIB_LIBRARIES} - ${MINIZIP_LIBRARIES} - ${JPEG_LIBRARIES} - ${PNG_LIBRARIES} - ${TIFF_LIBRARIES} - ${TinyXML2_LIBRARIES} - ${WEBSOCKETS_LIBRARIES} - ${CURL_LIBRARIES} - ${PROTOBUF_LITE_LIBRARIES} - ${FREETYPE_LIBRARIES} - ${PLATFORM_SPECIFIC_LIBS} - ) - -if(CURL_LIBRARY_DIRS) - link_directories(${CURL_LIBRARY_DIRS}) -endif() +target_link_libraries(cocos2d xxhash ${PLATFORM_SPECIFIC_LIBS}) if(USE_WEBP) add_definitions(-DCC_USE_WEBP=1) - include_directories(${WEBP_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${WEBP_LIBRARIES}) + cocos_use_pkg(cocos2d WEBP) else() add_definitions(-DCC_USE_WEBP=0) endif() if(USE_CHIPMUNK) - include_directories(${CHIPMUNK_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${CHIPMUNK_LIBRARIES}) + cocos_use_pkg(cocos2d CHIPMUNK) endif() if(USE_BOX2D) - include_directories(${Box2D_INCLUDE_DIRS}) - target_link_libraries(cocos2d ${Box2D_LIBRARIES}) + cocos_use_pkg(cocos2d Box2D) endif() set_target_properties(cocos2d From 2bf77c10e8782baac0282b1f521242a43df42585 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 03:28:41 +0300 Subject: [PATCH 46/67] Fix build on mingw again, disable USE_PREBUILT_LIBS with mingw (mingw can not link this libs). Eliminate some Find* modules, we can tune prebuilts without modify their code. --- CMakeLists.txt | 25 +++- cmake/Modules/FindFreetype.cmake | 12 +- cmake/Modules/FindZLIB.cmake | 124 -------------------- cocos/scripting/lua-bindings/CMakeLists.txt | 21 ++-- tests/lua-tests/project/CMakeLists.txt | 4 +- 5 files changed, 45 insertions(+), 141 deletions(-) delete mode 100644 cmake/Modules/FindZLIB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5960f16f94..eac42e7063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,12 @@ message(${BUILDING_STRING}) set(USE_WEBP_DEFAULT ON) if(WINRT OR WP8) - set(USE_WEBP_DEFAULT OFF) + set(USE_WEBP_DEFAULT OFF) +endif() + +set(USE_PREBUILT_LIBS_DEFAULT ON) +if(MINGW) + set(USE_PREBUILT_LIBS_DEFAULT OFF) endif() option(USE_CHIPMUNK "Use chipmunk for physics library" ON) @@ -51,8 +56,11 @@ 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(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ${USE_PREBUILT_LIBS_DEFAULT}) -option(USE_PREBUILT_LIBS "Use prebuilt libraries in external directory" ON) +if(USE_PREBUILT_LIBS AND MINGW) + message(FATAL_ERROR "Prebuilt windows libs can't be used with mingw, please use packages.") +endif() if(DEBUG_MODE) set(CMAKE_BUILD_TYPE DEBUG) @@ -89,7 +97,7 @@ if(WINDOWS) ADD_DEFINITIONS (-DCC_STATIC) endif() - ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32) + ADD_DEFINITIONS (-DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32 -D_WIN32) set(PLATFORM_FOLDER win32) elseif(MACOSX OR APPLE) ADD_DEFINITIONS (-DCC_TARGET_OS_MAC) @@ -145,6 +153,10 @@ if(LINUX OR MACOSX OR WINDOWS) message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") if(LINUX OR WINDOWS) + if(USE_PREBUILT_LIBS AND WINDOWS) + set(GLEW_INCLUDE_DIR ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/include/OGLES) + set(GLEW_LIBRARY ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.lib) + endif() find_package(GLEW REQUIRED) message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") endif() @@ -237,6 +249,13 @@ message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") +if(USE_PREBUILT_LIBS) + set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) + #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) + #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) + set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) + set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) +endif() find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index e6ef8874f5..0fe3f3f5b2 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -61,7 +61,11 @@ if(USE_PREBUILT_LIBS) NO_DEFAULT_PATH ) # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT FREETYPE_INCLUDE_DIR_ft2build OR NOT FREETYPE_INCLUDE_DIR_freetype2 OR NOT FREETYPE_LIBRARY) + if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_LIBRARY) + set(FREETYPE_FOUND 1) + set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}) + set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) + else() unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) unset(FREETYPE_LIBRARY CACHE) @@ -69,8 +73,10 @@ if(USE_PREBUILT_LIBS) endif(USE_PREBUILT_LIBS) # Try pkg-config first (because it provided deps info) -find_package(PkgConfig) -pkg_search_module(FREETYPE freetype2) +if(NOT FREETYPE_FOUND) + find_package(PkgConfig) + pkg_search_module(FREETYPE freetype2) +endif() if(NOT FREETYPE_FOUND) # Ugh, FreeType seems to use some #include trickery which diff --git a/cmake/Modules/FindZLIB.cmake b/cmake/Modules/FindZLIB.cmake deleted file mode 100644 index 0e287adc96..0000000000 --- a/cmake/Modules/FindZLIB.cmake +++ /dev/null @@ -1,124 +0,0 @@ -#.rst: -# FindZLIB -# -------- -# -# Find zlib -# -# Find the native ZLIB includes and library. Once done this will define -# -# :: -# -# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc. -# ZLIB_LIBRARIES - List of libraries when using zlib. -# ZLIB_FOUND - True if zlib found. -# -# -# -# :: -# -# ZLIB_VERSION_STRING - The version of zlib found (x.y.z) -# ZLIB_VERSION_MAJOR - The major version of zlib -# ZLIB_VERSION_MINOR - The minor version of zlib -# ZLIB_VERSION_PATCH - The patch version of zlib -# ZLIB_VERSION_TWEAK - The tweak version of zlib -# -# -# -# The following variable are provided for backward compatibility -# -# :: -# -# ZLIB_MAJOR_VERSION - The major version of zlib -# ZLIB_MINOR_VERSION - The minor version of zlib -# ZLIB_PATCH_VERSION - The patch version of zlib -# -# -# -# An includer may set ZLIB_ROOT to a zlib installation root to tell this -# module where to look. - -#============================================================================= -# Copyright 2001-2011 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -set(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1) - -if(USE_PREBUILT_LIBS) - set(search PATHS ${COCOS_EXTERNAL_DIR}/zlib ${COCOS_EXTERNAL_DIR}/${ARCH_DIR}-specific/zlib NO_DEFAULT_PATH) - find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${search} PATH_SUFFIXES include/${PLATFORM_FOLDER} include) - find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${search} - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - prebuilt - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY) - unset(ZLIB_INCLUDE_DIR CACHE) - unset(ZLIB_LIBRARY CACHE) - endif() -endif() - -set(_ZLIB_SEARCHES) - -# Search ZLIB_ROOT first if it is set. -if(ZLIB_ROOT) - set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH) - list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT) -endif() - -# Normal search. -set(_ZLIB_SEARCH_NORMAL - PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" - "$ENV{PROGRAMFILES}/zlib" - ) -list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL) - -# Try each search configuration. -foreach(search ${_ZLIB_SEARCHES}) - find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include) - find_library(ZLIB_LIBRARY NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib) -endforeach() - -mark_as_advanced(ZLIB_LIBRARY ZLIB_INCLUDE_DIR) - -if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h") - file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") - - string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") - string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") - string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") - set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") - - # only append a TWEAK version if it exists: - set(ZLIB_VERSION_TWEAK "") - if( "${ZLIB_H}" MATCHES "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$") - set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") - set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}") - endif() - - set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}") - set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}") - set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}") -endif() - -# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if -# all listed variables are TRUE -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR - VERSION_VAR ZLIB_VERSION_STRING) - -if(ZLIB_FOUND) - set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) - set(ZLIB_LIBRARIES ${ZLIB_LIBRARY}) -endif() - diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 61998d6c1a..0b1cf50ca8 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -1,4 +1,8 @@ -set(cocos_root ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +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 @@ -17,13 +21,12 @@ include_directories( ${cocos_root}/cocos/editor-support ${cocos_root}/cocos/platform ${cocos_root}/cocos/audio/include - ${CMAKE_CURRENT_SOURCE_DIR}/manual - ${CMAKE_CURRENT_SOURCE_DIR}/manual/extension - ${CMAKE_CURRENT_SOURCE_DIR}/manual/cocostudio - ${CMAKE_CURRENT_SOURCE_DIR}/manual/ui - ${CMAKE_CURRENT_SOURCE_DIR}/ui - ${CMAKE_CURRENT_SOURCE_DIR}/manual/cocos2d - ${CMAKE_CURRENT_SOURCE_DIR}/auto + manual + manual/extension + manual/cocostudio + manual/ui + manual/cocos2d + auto ) file(GLOB lua_cocos2d_source_files @@ -120,7 +123,7 @@ endif() set(lua_bindings_files ${lua_cocos2d_source_files} ${lua_bindings_manual_files} ${lua_bindings_auto_files}) -add_library(luacocos2d STATIC ${lua_bindings_files}) +add_library(luacocos2d ${lua_bindings_files}) target_link_libraries(luacocos2d cocos2d) set_target_properties(luacocos2d PROPERTIES diff --git a/tests/lua-tests/project/CMakeLists.txt b/tests/lua-tests/project/CMakeLists.txt index 75858d3c42..404e5d2ea9 100644 --- a/tests/lua-tests/project/CMakeLists.txt +++ b/tests/lua-tests/project/CMakeLists.txt @@ -54,8 +54,8 @@ else() 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 ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}${RES_PREFIX}/src/cocos + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../src ${APP_BIN_DIR}${RES_PREFIX}/Resources/src + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/cocos/scripting/lua-bindings/script/ ${APP_BIN_DIR}/Resources/src/cocos COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests/cpp-tests/Resources ${APP_BIN_DIR}${RES_PREFIX}/res ) From 7c4355c60d66894f0e70d1c97ed0827e0e22a4a4 Mon Sep 17 00:00:00 2001 From: joewanchen Date: Wed, 19 Nov 2014 15:27:55 +0800 Subject: [PATCH 47/67] rename functions. --- .../cocostudio/CCSpriteFrameCacheHelper.cpp | 8 ++++---- .../editor-support/cocostudio/CCSpriteFrameCacheHelper.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp index dd594da776..0112d0df2c 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.cpp @@ -50,7 +50,7 @@ void SpriteFrameCacheHelper::purge() _spriteFrameCacheHelper = nullptr; } -void SpriteFrameCacheHelper::_retainSpriteFrames(const std::string &plistPath) +void SpriteFrameCacheHelper::retainSpriteFrames(const std::string &plistPath) { auto it = _usingSpriteFrames.find(plistPath); if(it != _usingSpriteFrames.end()) return; @@ -71,7 +71,7 @@ void SpriteFrameCacheHelper::_retainSpriteFrames(const std::string &plistPath) _usingSpriteFrames[plistPath] = vec; } -void SpriteFrameCacheHelper::_releaseSpriteFrames(const std::string &plistPath) +void SpriteFrameCacheHelper::releaseSpriteFrames(const std::string &plistPath) { auto it = _usingSpriteFrames.find(plistPath); if(it == _usingSpriteFrames.end()) return; @@ -90,13 +90,13 @@ void SpriteFrameCacheHelper::_releaseSpriteFrames(const std::string &plistPath) void SpriteFrameCacheHelper::removeSpriteFrameFromFile(const std::string &plistPath) { SpriteFrameCache::getInstance()->removeSpriteFramesFromFile(plistPath); - _releaseSpriteFrames(plistPath); + releaseSpriteFrames(plistPath); } void SpriteFrameCacheHelper::addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath) { SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath, imagePath); - _retainSpriteFrames(plistPath); + retainSpriteFrames(plistPath); } SpriteFrameCacheHelper::SpriteFrameCacheHelper() diff --git a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h index 005192e5d9..43cf661dc8 100644 --- a/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h +++ b/cocos/editor-support/cocostudio/CCSpriteFrameCacheHelper.h @@ -59,8 +59,8 @@ public: void removeSpriteFrameFromFile(const std::string& plistPath); private: - void _retainSpriteFrames(const std::string& plistPath); - void _releaseSpriteFrames(const std::string& plistPath); + void retainSpriteFrames(const std::string& plistPath); + void releaseSpriteFrames(const std::string& plistPath); SpriteFrameCacheHelper(); ~SpriteFrameCacheHelper(); From 98db27e9293c89c1a810c2d987cc1317a8b69e7f Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Wed, 19 Nov 2014 10:57:18 +0300 Subject: [PATCH 48/67] cmake linux fixes: FindFontconfig, find appropriate threads libs --- CMakeLists.txt | 29 +++++++++++++++++++---------- cmake/Modules/FindFontconfig.cmake | 17 +++++++++++++++++ cocos/CMakeLists.txt | 3 +-- 3 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 cmake/Modules/FindFontconfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index eac42e7063..9ac85ce73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,11 +141,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) -if(LINUX) - find_package(FMODEX REQUIRED) - message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") -endif() - # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) find_package(OpenGL REQUIRED) @@ -165,6 +160,18 @@ if(LINUX OR MACOSX OR WINDOWS) message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") include_directories(${GLFW3_INCLUDE_DIRS}) + if(LINUX) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + find_package(Threads REQUIRED) + set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + + find_package(FMODEX REQUIRED) + message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") + + find_package(Fontconfig REQUIRED) + message(STATUS "Fontconfig include dirs: ${FONTCONFIG_INCLUDE_DIRS}") + endif() + if(WINDOWS) if(USE_PREBUILT_LIBS) set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) @@ -250,11 +257,13 @@ find_package(JPEG REQUIRED) message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") if(USE_PREBUILT_LIBS) - set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) - #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) - #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) - set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) - set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) + if(WINDOWS) + set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) + #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) + #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) + set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) + set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) + endif() endif() find_package(ZLIB REQUIRED) message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") diff --git a/cmake/Modules/FindFontconfig.cmake b/cmake/Modules/FindFontconfig.cmake new file mode 100644 index 0000000000..d5da113c49 --- /dev/null +++ b/cmake/Modules/FindFontconfig.cmake @@ -0,0 +1,17 @@ +# FindFontconfig +# -------------- +# +# Locate Fontconfig library +# + +if(NOT FONTCONFIG_FOUND) + find_package(PkgConfig) + pkg_search_module(FONTCONFIG fontconfig) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Fontconfig + REQUIRED_VARS FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIRS + VERSION_VAR FONTCONFIG_VERSION + ) + diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index 9a358459f1..c200fbe710 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -93,10 +93,9 @@ if(WINDOWS) endforeach() list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 winmm) elseif(LINUX) - foreach(_pkg OPENGL GLEW GLFW3 FMODEX) + foreach(_pkg OPENGL GLEW GLFW3 FMODEX FONTCONFIG THREADS) cocos_use_pkg(cocos2d ${_pkg}) endforeach() - list(APPEND PLATFORM_SPECIFIC_LIBS fontconfig pthread rt) elseif(MACOSX OR APPLE) INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) From 04510c39fa785304fd9fc172cd9e55c74cd407d7 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 19 Nov 2014 12:25:50 -0800 Subject: [PATCH 49/67] Uses new version of cocos2d-console --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 40e5835664..f1a8f35036 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 40e583566474a9e1e0ed1c7ab7a746f4fa354fa0 +Subproject commit f1a8f35036b9cc85061d91447bce8e35439b43a1 From 5d2857b3c470cb9b24c1d59568a2dcbcf78bb780 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Wed, 19 Nov 2014 15:55:18 -0800 Subject: [PATCH 50/67] updated angle to commit 4a980d2612 --- cocos/platform/win8.1-universal/OpenGLES.cpp | 114 ++++++++++++++---- cocos/platform/win8.1-universal/OpenGLES.h | 1 - .../App.Shared/OpenGLES.cpp | 114 ++++++++++++++---- .../App.Shared/OpenGLES.h | 1 - 4 files changed, 178 insertions(+), 52 deletions(-) diff --git a/cocos/platform/win8.1-universal/OpenGLES.cpp b/cocos/platform/win8.1-universal/OpenGLES.cpp index 943b0856fc..3f696abba7 100644 --- a/cocos/platform/win8.1-universal/OpenGLES.cpp +++ b/cocos/platform/win8.1-universal/OpenGLES.cpp @@ -48,51 +48,107 @@ void OpenGLES::Initialize() EGL_NONE }; - const EGLint displayAttributes[] = - { - // This can be used to configure D3D11. For example, EGL_PLATFORM_ANGLE_TYPE_D3D11_FL9_3_ANGLE could be used. - // This would ask the graphics card to use D3D11 Feature Level 9_3 instead of Feature Level 11_0+. - // On Windows Phone, this would allow the Phone Emulator to act more like the GPUs that are available on real Phone devices. -#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) - EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_FL9_3_ANGLE, - EGL_NONE, -#else - EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - EGL_NONE, -#endif - }; - const EGLint contextAttributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; - // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in 'displayAttributes' to configure D3D11. + const EGLint defaultDisplayAttributes[] = + { + // These are the default display attributes, used to request ANGLE's D3D11 renderer. + // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + + // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. + // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint fl9_3DisplayAttributes[] = + { + // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3. + // These attributes are used if the call to eglInitialize fails with the default display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, + EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint warpDisplayAttributes[] = + { + // These attributes can be used to request D3D11 WARP. + // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_USE_WARP_ANGLE, EGL_TRUE, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + EGLConfig config = NULL; + + // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in display attributes, used to configure D3D11. PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT")); if (!eglGetPlatformDisplayEXT) { throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT"); } - mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes); + // + // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying + // parameters passed to eglGetPlatformDisplayEXT: + // 1) The first calls uses "defaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+. + // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again + // using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3. + // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again + // using "warpDisplayAttributes". This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer. + // + // Note: On Windows Phone, we #ifdef out the first set of calls to eglPlatformDisplayEXT and eglInitialize. + // Windows Phones devices only support D3D11 Feature Level 9_3, but the Windows Phone emulator supports 11_0+. + // We use this #ifdef to limit the Phone emulator to Feature Level 9_3, making it behave more like + // real Windows Phone devices. + // If you wish to test Feature Level 10_0+ in the Windows Phone emulator then you should remove this #ifdef. + // + +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) + // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details. + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, defaultDisplayAttributes); if (mEglDisplay == EGL_NO_DISPLAY) { - throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display"); + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); } if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) +#endif { - throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on Windows Phone, or certain Windows tablets). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU (e.g. on Surface RT). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, warpDisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred. + throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + } + } } EGLint numConfigs = 0; - if (eglGetConfigs(mEglDisplay, NULL, 0, &numConfigs) == EGL_FALSE) - { - throw Exception::CreateException(E_FAIL, L"Failed to get EGLConfig count"); - } - - if (eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE) + if ((eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0)) { throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig"); } @@ -134,6 +190,14 @@ EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurf EGLSurface surface = EGL_NO_SURFACE; + const EGLint surfaceAttributes[] = + { + // EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above). + // If you have compilation issues with it then please update your Visual Studio templates. + EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE + }; + // Create a PropertySet and initialize with the EGLNativeWindowType. PropertySet^ surfaceCreationProperties = ref new PropertySet(); surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), panel); @@ -144,7 +208,7 @@ EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurf surfaceCreationProperties->Insert(ref new String(EGLRenderSurfaceSizeProperty), PropertyValue::CreateSize(*renderSurfaceSize)); } - surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast(surfaceCreationProperties), NULL); + surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast(surfaceCreationProperties), surfaceAttributes); if (surface == EGL_NO_SURFACE) { throw Exception::CreateException(E_FAIL, L"Failed to create EGL surface"); diff --git a/cocos/platform/win8.1-universal/OpenGLES.h b/cocos/platform/win8.1-universal/OpenGLES.h index ce9f2a9cdf..1a57b68739 100644 --- a/cocos/platform/win8.1-universal/OpenGLES.h +++ b/cocos/platform/win8.1-universal/OpenGLES.h @@ -28,7 +28,6 @@ #include #include - class OpenGLES { public: diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp index 943b0856fc..3f696abba7 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.cpp @@ -48,51 +48,107 @@ void OpenGLES::Initialize() EGL_NONE }; - const EGLint displayAttributes[] = - { - // This can be used to configure D3D11. For example, EGL_PLATFORM_ANGLE_TYPE_D3D11_FL9_3_ANGLE could be used. - // This would ask the graphics card to use D3D11 Feature Level 9_3 instead of Feature Level 11_0+. - // On Windows Phone, this would allow the Phone Emulator to act more like the GPUs that are available on real Phone devices. -#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) - EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_FL9_3_ANGLE, - EGL_NONE, -#else - EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - EGL_NONE, -#endif - }; - const EGLint contextAttributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; - // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in 'displayAttributes' to configure D3D11. + const EGLint defaultDisplayAttributes[] = + { + // These are the default display attributes, used to request ANGLE's D3D11 renderer. + // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + + // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. + // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint fl9_3DisplayAttributes[] = + { + // These can be used to request ANGLE's D3D11 renderer, with D3D11 Feature Level 9_3. + // These attributes are used if the call to eglInitialize fails with the default display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, + EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + const EGLint warpDisplayAttributes[] = + { + // These attributes can be used to request D3D11 WARP. + // They are used if eglInitialize fails with both the default display attributes and the 9_3 display attributes. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_USE_WARP_ANGLE, EGL_TRUE, + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE, + }; + + EGLConfig config = NULL; + + // eglGetPlatformDisplayEXT is an alternative to eglGetDisplay. It allows us to pass in display attributes, used to configure D3D11. PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT")); if (!eglGetPlatformDisplayEXT) { throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT"); } - mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes); + // + // To initialize the display, we make three sets of calls to eglGetPlatformDisplayEXT and eglInitialize, with varying + // parameters passed to eglGetPlatformDisplayEXT: + // 1) The first calls uses "defaultDisplayAttributes" as a parameter. This corresponds to D3D11 Feature Level 10_0+. + // 2) If eglInitialize fails for step 1 (e.g. because 10_0+ isn't supported by the default GPU), then we try again + // using "fl9_3DisplayAttributes". This corresponds to D3D11 Feature Level 9_3. + // 3) If eglInitialize fails for step 2 (e.g. because 9_3+ isn't supported by the default GPU), then we try again + // using "warpDisplayAttributes". This corresponds to D3D11 Feature Level 11_0 on WARP, a D3D11 software rasterizer. + // + // Note: On Windows Phone, we #ifdef out the first set of calls to eglPlatformDisplayEXT and eglInitialize. + // Windows Phones devices only support D3D11 Feature Level 9_3, but the Windows Phone emulator supports 11_0+. + // We use this #ifdef to limit the Phone emulator to Feature Level 9_3, making it behave more like + // real Windows Phone devices. + // If you wish to test Feature Level 10_0+ in the Windows Phone emulator then you should remove this #ifdef. + // + +#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) + // This tries to initialize EGL to D3D11 Feature Level 10_0+. See above comment for details. + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, defaultDisplayAttributes); if (mEglDisplay == EGL_NO_DISPLAY) { - throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display"); + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); } if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) +#endif { - throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + // This tries to initialize EGL to D3D11 Feature Level 9_3, if 10_0+ is unavailable (e.g. on Windows Phone, or certain Windows tablets). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, fl9_3DisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // This initializes EGL to D3D11 Feature Level 11_0 on WARP, if 9_3+ is unavailable on the default GPU (e.g. on Surface RT). + mEglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, warpDisplayAttributes); + if (mEglDisplay == EGL_NO_DISPLAY) + { + throw Exception::CreateException(E_FAIL, L"Failed to get EGL display"); + } + + if (eglInitialize(mEglDisplay, NULL, NULL) == EGL_FALSE) + { + // If all of the calls to eglInitialize returned EGL_FALSE then an error has occurred. + throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + } + } } EGLint numConfigs = 0; - if (eglGetConfigs(mEglDisplay, NULL, 0, &numConfigs) == EGL_FALSE) - { - throw Exception::CreateException(E_FAIL, L"Failed to get EGLConfig count"); - } - - if (eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE) + if ((eglChooseConfig(mEglDisplay, configAttributes, &mEglConfig, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0)) { throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig"); } @@ -134,6 +190,14 @@ EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurf EGLSurface surface = EGL_NO_SURFACE; + const EGLint surfaceAttributes[] = + { + // EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER is part of the same optimization as EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER (see above). + // If you have compilation issues with it then please update your Visual Studio templates. + EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER, EGL_TRUE, + EGL_NONE + }; + // Create a PropertySet and initialize with the EGLNativeWindowType. PropertySet^ surfaceCreationProperties = ref new PropertySet(); surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), panel); @@ -144,7 +208,7 @@ EGLSurface OpenGLES::CreateSurface(SwapChainPanel^ panel, const Size* renderSurf surfaceCreationProperties->Insert(ref new String(EGLRenderSurfaceSizeProperty), PropertyValue::CreateSize(*renderSurfaceSize)); } - surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast(surfaceCreationProperties), NULL); + surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, reinterpret_cast(surfaceCreationProperties), surfaceAttributes); if (surface == EGL_NO_SURFACE) { throw Exception::CreateException(E_FAIL, L"Failed to create EGL surface"); diff --git a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h index ce9f2a9cdf..1a57b68739 100644 --- a/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h +++ b/templates/cpp-template-default/proj.win8.1-universal/App.Shared/OpenGLES.h @@ -28,7 +28,6 @@ #include #include - class OpenGLES { public: From 97a3e912a3e53fe0878ab0c585fffda96d4125b8 Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 20 Nov 2014 10:49:07 +0800 Subject: [PATCH 51/67] [ci skip] Update CHANGELOG --- CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8ab6765be2..e43346f357 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ -cocos2d-x-3.3 ?? +cocos2d-x-3.3-rc1 ?? [NEW] Vec2: added greater than operator + [NEW] WP8: Win8.1 universal app support [FIX] Audio: `SimpleAudioEngine::sharedEngine()->playBackgroundMusic()` crashed freezen on Lollipop(Android5.0) [FIX] Button: when the dimension of button title is larger than the button, button will scale to fit the dimension of the button title From 48c67899bb887ad4102843113a5ed37615e4413c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 20 Nov 2014 11:15:25 +0800 Subject: [PATCH 52/67] [ci skip] Update CHANGELOG --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e43346f357..6ad5b15483 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,7 +18,7 @@ cocos2d-x-3.3-rc1 ?? [FIX] Scale9Sprite: if scale and flip property are set at the same time, the result would be wrong [FIX] Scene: setScale() doesn't work as expected [FIX] Sprite3D: did not create attached sprite from cache - [FIX] WP/WinRT: Windows 8.1 universal app support; `UIEditBox` support + [FIX] WP: back key behaviour and Director::getInstance()->end() works not correctly cocos2d-x-3.3-rc0 Oct.21 2014 [NEW] 3d: added light support: direction light, point light, spot light and ambient light From e52ee603ac56236874aa339603bb854d15c4cdda Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Thu, 20 Nov 2014 03:41:28 +0000 Subject: [PATCH 53/67] [AUTO]: updating luabinding automatically --- .../lua-bindings/auto/api/ClippingNode.lua | 17 ++++-- .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 57 +++++++++++++++++-- .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 1 + 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/cocos/scripting/lua-bindings/auto/api/ClippingNode.lua b/cocos/scripting/lua-bindings/auto/api/ClippingNode.lua index 6f7f27e934..443df5e28b 100644 --- a/cocos/scripting/lua-bindings/auto/api/ClippingNode.lua +++ b/cocos/scripting/lua-bindings/auto/api/ClippingNode.lua @@ -5,10 +5,11 @@ -- @parent_module cc -------------------------------- --- Inverted. If this is set to true,
--- the stencil is inverted, so the content is drawn where the stencil is NOT drawn.
--- This default to false. --- @function [parent=#ClippingNode] isInverted +-- If stencil has no childre it will not be drawn.
+-- If you have custom stencil-based node with stencil drawing mechanics other then children-based,
+-- then this method should return true every time you wish stencil to be visited.
+-- By default returns true if has any children attached. +-- @function [parent=#ClippingNode] hasContent -- @param self -- @return bool#bool ret (return value: bool) @@ -47,6 +48,14 @@ -- @param self -- @param #float alphaThreshold +-------------------------------- +-- Inverted. If this is set to true,
+-- the stencil is inverted, so the content is drawn where the stencil is NOT drawn.
+-- This default to false. +-- @function [parent=#ClippingNode] isInverted +-- @param self +-- @return bool#bool ret (return value: bool) + -------------------------------- -- @overload self, cc.Node -- @overload self diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index d795a814d0..365625d98d 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -44340,7 +44340,7 @@ int lua_register_cocos2dx_Menu(lua_State* tolua_S) return 1; } -int lua_cocos2dx_ClippingNode_isInverted(lua_State* tolua_S) +int lua_cocos2dx_ClippingNode_hasContent(lua_State* tolua_S) { int argc = 0; cocos2d::ClippingNode* cobj = nullptr; @@ -44360,7 +44360,7 @@ int lua_cocos2dx_ClippingNode_isInverted(lua_State* tolua_S) #if COCOS2D_DEBUG >= 1 if (!cobj) { - tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ClippingNode_isInverted'", nullptr); + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ClippingNode_hasContent'", nullptr); return 0; } #endif @@ -44370,16 +44370,16 @@ int lua_cocos2dx_ClippingNode_isInverted(lua_State* tolua_S) { if(!ok) return 0; - bool ret = cobj->isInverted(); + bool ret = cobj->hasContent(); tolua_pushboolean(tolua_S,(bool)ret); return 1; } - CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ClippingNode:isInverted",argc, 0); + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ClippingNode:hasContent",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: - tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ClippingNode_isInverted'.",&tolua_err); + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ClippingNode_hasContent'.",&tolua_err); #endif return 0; @@ -44610,6 +44610,50 @@ int lua_cocos2dx_ClippingNode_setAlphaThreshold(lua_State* tolua_S) return 0; } +int lua_cocos2dx_ClippingNode_isInverted(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::ClippingNode* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.ClippingNode",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::ClippingNode*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ClippingNode_isInverted'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + return 0; + bool ret = cobj->isInverted(); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.ClippingNode:isInverted",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ClippingNode_isInverted'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_ClippingNode_create(lua_State* tolua_S) { int argc = 0; @@ -44667,12 +44711,13 @@ int lua_register_cocos2dx_ClippingNode(lua_State* tolua_S) tolua_cclass(tolua_S,"ClippingNode","cc.ClippingNode","cc.Node",nullptr); tolua_beginmodule(tolua_S,"ClippingNode"); - tolua_function(tolua_S,"isInverted",lua_cocos2dx_ClippingNode_isInverted); + tolua_function(tolua_S,"hasContent",lua_cocos2dx_ClippingNode_hasContent); tolua_function(tolua_S,"setInverted",lua_cocos2dx_ClippingNode_setInverted); tolua_function(tolua_S,"setStencil",lua_cocos2dx_ClippingNode_setStencil); tolua_function(tolua_S,"getAlphaThreshold",lua_cocos2dx_ClippingNode_getAlphaThreshold); tolua_function(tolua_S,"getStencil",lua_cocos2dx_ClippingNode_getStencil); tolua_function(tolua_S,"setAlphaThreshold",lua_cocos2dx_ClippingNode_setAlphaThreshold); + tolua_function(tolua_S,"isInverted",lua_cocos2dx_ClippingNode_isInverted); tolua_function(tolua_S,"create", lua_cocos2dx_ClippingNode_create); tolua_endmodule(tolua_S); std::string typeName = typeid(cocos2d::ClippingNode).name(); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index f266a640b9..f8080968eb 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -1643,6 +1643,7 @@ int register_all_cocos2dx(lua_State* tolua_S); + #endif // __cocos2dx_h__ From 499c670a9b5560832ffdfbac2100c39881fd024c Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 12:05:15 +0300 Subject: [PATCH 54/67] Move prebuilt libraries config to distinct file. Now build system looks more maintanable. I test with mac, going to test with other platforms. * All prebuilt libs config moved to cmake/Modules/CocosUsePrebuiltLibs.cmake * Wrap plain find_package to our cocos_find_package. It will not try to call find_package if USE_PREBUILT_LIBS and _FOUND set to true. * Other small fixes. --- CMakeLists.txt | 100 ++++---------- cmake/Modules/CocosBuildHelpers.cmake | 17 +++ cmake/Modules/CocosUsePrebuiltLibs.cmake | 167 +++++++++++++++++++++++ cmake/Modules/FindCURL.cmake | 20 --- cmake/Modules/FindChipmunk.cmake | 22 --- cmake/Modules/FindFMODEX.cmake | 21 --- cmake/Modules/FindFreetype.cmake | 29 ---- cocos/CMakeLists.txt | 2 + 8 files changed, 211 insertions(+), 167 deletions(-) create mode 100644 cmake/Modules/CocosUsePrebuiltLibs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ac85ce73f..7160321934 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,23 +141,19 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/external ) +if(USE_PREBUILT_LIBS) + include(CocosUsePrebuiltLibs) +endif() + # GLFW3 used on Mac, Windows and Linux desktop platforms if(LINUX OR MACOSX OR WINDOWS) - find_package(OpenGL REQUIRED) - set(OPENGL_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) # fix inconsistency - message(STATUS "OpenGL include dirs: ${OPENGL_INCLUDE_DIRS}") + cocos_find_package(OpenGL OPENGL REQUIRED) if(LINUX OR WINDOWS) - if(USE_PREBUILT_LIBS AND WINDOWS) - set(GLEW_INCLUDE_DIR ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/include/OGLES) - set(GLEW_LIBRARY ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/gles/prebuilt/glew32.lib) - endif() - find_package(GLEW REQUIRED) - message(STATUS "GLEW libs: ${GLEW_LIBRARIES}") + cocos_find_package(GLEW GLEW REQUIRED) endif() - find_package(GLFW3 REQUIRED) - message(STATUS "GLFW3 include dirs: ${GLFW3_INCLUDE_DIRS}") + cocos_find_package(GLFW3 GLFW3 REQUIRED) include_directories(${GLFW3_INCLUDE_DIRS}) if(LINUX) @@ -165,57 +161,30 @@ if(LINUX OR MACOSX OR WINDOWS) find_package(Threads REQUIRED) set(THREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) - find_package(FMODEX REQUIRED) - message(STATUS "FMOD Ex include dirs: ${FMODEX_INCLUDE_DIRS}") - - find_package(Fontconfig REQUIRED) - message(STATUS "Fontconfig include dirs: ${FONTCONFIG_INCLUDE_DIRS}") + cocos_find_package(FMODEX FMODEX REQUIRED) + cocos_find_package(Fontconfig FONTCONFIG REQUIRED) endif() if(WINDOWS) - if(USE_PREBUILT_LIBS) - set(VORBIS_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OggDecoder) - list(APPEND CMAKE_INCLUDE_PATH ${VORBIS_PREBUILT_ROOT}/include) - list(APPEND CMAKE_LIBRARY_PATH ${VORBIS_PREBUILT_ROOT}/prebuilt) - endif() - find_package(Vorbis REQUIRED) - message(STATUS "Vorbis include dirs: ${VORBIS_INCLUDE_DIRS}") - - if(USE_PREBUILT_LIBS) - list(APPEND CMAKE_INCLUDE_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/include) - list(APPEND CMAKE_LIBRARY_PATH ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/MP3Decoder/prebuilt) - endif() - find_package(MPG123 REQUIRED) - message(STATUS "MPG123 include dirs: ${MPG123_INCLUDE_DIRS}") - - if(USE_PREBUILT_LIBS) - set(OPENAL_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/OpenalSoft) - list(APPEND CMAKE_INCLUDE_PATH ${OPENAL_PREBUILT_ROOT}) - list(APPEND CMAKE_LIBRARY_PATH ${OPENAL_PREBUILT_ROOT}/prebuilt) - endif() - find_package(OpenAL REQUIRED) - set(OPENAL_INCLUDE_DIRS ${OPENAL_INCLUDE_DIR}) - set(OPENAL_LIBRARIES ${OPENAL_LIBRARY}) + 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 ' for portability (not for '#include ' set(OPENAL_DEFINITIONS "-DOPENAL_PLAIN_INCLUDES") - message(STATUS "OpenAL include dirs: ${OPENAL_INCLUDE_DIRS}") endif() endif(LINUX OR MACOSX OR WINDOWS) # Freetype required on all platforms -find_package(Freetype REQUIRED) -message(STATUS "FreeType include dirs: ${FREETYPE_INCLUDE_DIRS}") +cocos_find_package(Freetype FREETYPE REQUIRED) # WebP required if used if(USE_WEBP) - find_package(WebP REQUIRED) - message(STATUS "WebP include dirs: ${WEBP_INCLUDE_DIRS}") + cocos_find_package(WebP WEBP REQUIRED) endif(USE_WEBP) # Chipmunk if(USE_CHIPMUNK) - find_package(Chipmunk REQUIRED) - message(STATUS "Chipmunk include dirs: ${CHIPMUNK_INCLUDE_DIRS}") + cocos_find_package(Chipmunk CHIPMUNK REQUIRED) 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 @@ -248,25 +217,13 @@ if(USE_PREBUILT_LIBS) set(TinyXML2_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/tinyxml2) set(TinyXML2_LIBRARIES tinyxml2) else() - find_package(TinyXML2) + cocos_find_package(TinyXML2 TinyXML2 REQUIRED) endif() message(STATUS "TinyXML2 include dirs: ${TinyXML2_INCLUDE_DIRS}") # libjpeg -find_package(JPEG REQUIRED) -message(STATUS "JPEG include dirs: ${JPEG_INCLUDE_DIRS}") - -if(USE_PREBUILT_LIBS) - if(WINDOWS) - set(ZLIB_PREBUILT_ROOT ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/zlib) - #set(CMAKE_INCLUDE_PATH ${ZLIB_PREBUILT_ROOT} ${CMAKE_INCLUDE_PATH}) - #set(CMAKE_LIBRARY_PATH ${ZLIB_PREBUILT_ROOT}/prebuilt ${CMAKE_LIBRARY_PATH}) - set(ZLIB_INCLUDE_DIR ${ZLIB_PREBUILT_ROOT}/include) - set(ZLIB_LIBRARY ${ZLIB_PREBUILT_ROOT}/prebuilt/libzlib.lib) - endif() -endif() -find_package(ZLIB REQUIRED) -message(STATUS "ZLIB include dirs: ${ZLIB_INCLUDE_DIRS}") +cocos_find_package(JPEG JPEG REQUIRED) +cocos_find_package(ZLIB ZLIB REQUIRED) # minizip (we try to migrate to minizip from https://github.com/nmoinvaz/minizip) # only msys2 currently provides package for this variant, all other @@ -277,8 +234,9 @@ if(USE_PREBUILT_LIBS OR NOT MINGW) add_subdirectory(external/unzip) set(MINIZIP_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/unzip) set(MINIZIP_LIBRARIES unzip) + message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") else() - find_package(MINIZIP REQUIRED) + cocos_find_package(MINIZIP MINIZIP REQUIRED) # double check that we have needed functions include(CheckLibraryExists) check_library_exists(${MINIZIP_LIBRARIES} "unzGoToFirstFile2" "" MINIZIP_HAS_GOTOFIRSTFILE2) @@ -287,19 +245,11 @@ else() endif() add_definitions(-DMINIZIP_FROM_SYSTEM) endif() -message(STATUS "MINIZIP include dirs: ${MINIZIP_INCLUDE_DIRS}") -find_package(PNG REQUIRED) -message(STATUS "PNG include dirs: ${PNG_INCLUDE_DIRS}") - -find_package(TIFF REQUIRED) -message(STATUS "TIFF include dirs: ${TIFF_INCLUDE_DIRS}") - -find_package(WEBSOCKETS REQUIRED) -message(STATUS "WEBSOCKETS include dirs: ${WEBSOCKETS_INCLUDE_DIRS}") - -find_package(CURL REQUIRED) -message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") +cocos_find_package(PNG PNG REQUIRED) +cocos_find_package(TIFF TIFF REQUIRED) +cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED) +cocos_find_package(CURL CURL REQUIRED) # protobuf-lite (not prebuilded, exists as source) # TODO: for now we can't use upstream protobuf because these files: @@ -313,7 +263,7 @@ message(STATUS "CURL include dirs: ${CURL_INCLUDE_DIRS}") set(PROTOBUF_LITE_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/protobuf-lite/src) set(PROTOBUF_LITE_LIBRARIES protobuf) ## else() -## find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) +## cocos_find_package(Protobuf REQUIRED PROTOBUF_LITE_LIBRARIES) ## set(PROTOBUF_LITE_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS}) ## endif() message(STATUS "Protobuf lite libs: ${PROTOBUF_LITE_LIBRARIES}") diff --git a/cmake/Modules/CocosBuildHelpers.cmake b/cmake/Modules/CocosBuildHelpers.cmake index 2cd2aea9d1..07a8e79f1b 100644 --- a/cmake/Modules/CocosBuildHelpers.cmake +++ b/cmake/Modules/CocosBuildHelpers.cmake @@ -36,6 +36,23 @@ function(cocos_mark_resources) endforeach() endfunction() +# cocos_find_package(pkg args...) +# works same as find_package, but do additional care to properly find +# prebuilt libs for cocos +macro(cocos_find_package pkg_name pkg_prefix) + if(NOT USE_PREBUILT_LIBS OR NOT ${pkg_prefix}_FOUND) + find_package(${pkg_name} ${ARGN}) + endif() + if(NOT ${pkg_prefix}_INCLUDE_DIRS AND ${pkg_prefix}_INCLUDE_DIR) + set(${pkg_prefix}_INCLUDE_DIRS ${${pkg_prefix}_INCLUDE_DIR}) + endif() + if(NOT ${pkg_prefix}_LIBRARIES AND ${pkg_prefix}_LIBRARY) + set(${pkg_prefix}_LIBRARIES ${${pkg_prefix}_LIBRARY}) + endif() + + message(STATUS "${pkg_name} include dirs: ${${pkg_prefix}_INCLUDE_DIRS}") +endmacro() + # cocos_use_pkg(pkg) function. # This function applies standard package variables (after find_package(pkg) call) to current scope # Recognized variables: _INCLUDE_DIRS, _LIBRARIES, _LIBRARY_DIRS diff --git a/cmake/Modules/CocosUsePrebuiltLibs.cmake b/cmake/Modules/CocosUsePrebuiltLibs.cmake new file mode 100644 index 0000000000..1ad3b93899 --- /dev/null +++ b/cmake/Modules/CocosUsePrebuiltLibs.cmake @@ -0,0 +1,167 @@ +# CocosUsePrebuiltLibs - sets external libs variables to link with + +# START CONFIG + +set(_chipmunk_inc chipmunk.h) +set(_chipmunk_inc_paths chipmunk) +set(_chipmunk_libs chipmunk libchipmunk) + +set(_curl_inc curl/curl.h) +set(_curl_libs crypto ssl libeay32 ssleay32 curl libcurl_imp libcurl) + +set(_freetype2_prefix FREETYPE) +set(_freetype2_inc ft2build.h freetype/freetype.h) +set(_freetype2_inc_paths freetype2) +set(_freetype2_libs freetype freetype250) + +set(_jpeg_inc jpeglib.h) +set(_jpeg_libs jpeg libjpeg) + +set(_png_inc png.h) +set(_png_libs png libpng) + +set(_tiff_inc tiff.h) +set(_tiff_libs tiff libtiff) + +set(_webp_inc decode.h) +set(_webp_libs webp libwebp) + +set(_websockets_inc libwebsockets.h) +set(_websockets_libs websockets libwebsockets) + +set(_glfw3_inc glfw3.h) +set(_glfw3_libs glfw3 libglfw3) + +set(_sqlite3_inc sqlite3.h) +set(_sqlite3_libs sqlite3) + +set(_gles_prefix GLEW) +set(_gles_inc glew.h) +set(_gles_inc_paths OGLES) +set(_gles_libs glew32) + +set(_icon_prefix ICONV) +set(_icon_inc iconv.h) +set(_icon_libs libiconv) + +set(_MP3Decoder_prefix MPG123) +set(_MP3Decoder_inc mpg123.h) +set(_MP3Decoder_libs libmpg123) + +set(_OggDecoder_prefix VORBIS) +set(_OggDecoder_inc ogg/ogg.h) +set(_OggDecoder_libs libogg libvorbis libvorbisfile) + +set(_OpenalSoft_prefix OPENAL) +set(_OpenalSoft_inc al.h) +set(_OpenalSoft_inc_paths AL) +set(_OpenalSoft_libs OpenAL32) + +set(_zlib_inc zlib.h) +set(_zlib_libs libzlib) + +set(_fmod_inc fmod.h) +set(_fmod_libs fmodex fmodexL) + +set(all_prebuilt_libs + chipmunk + curl + freetype2 + jpeg + png + tiff + webp + websockets +) + + +if(MACOSX) + list(APPEND all_prebuilt_libs glfw3) +endif() + +# We use MSVC instead of WINDOWS because it can be mingw that can't use our prebuilt libs +if(MSVC) + list(APPEND all_prebuilt_libs glfw3 sqlite3 gles icon MP3Decoder OggDecoder OpenalSoft zlib) +endif() + +if(LINUX) + list(APPEND all_prebuilt_libs fmod) +endif() + +# END CONFIG + +foreach(_lib ${all_prebuilt_libs}) + if(_${_lib}_prefix) + set(_prefix ${_${_lib}_prefix}) + else() + # auto-prefix is uppercased name + string(TOUPPER ${_lib} _prefix) + endif() + + set(roots + ${COCOS_EXTERNAL_DIR}/${_lib} + ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/${_lib} + ) + foreach(_root ${roots}) + if(EXISTS ${_root}) + set(include_dir_candidates + ${_root}/include + ${_root}/include/${ARCH_DIR} + ${_root}/include/${PLATFORM_FOLDER} + ${_root}/include/${PLATFORM_FOLDER}/${ARCH_DIR} + ) + set(include_dirs) + foreach(_dir ${include_dir_candidates}) + if(EXISTS ${_dir}) + # find all include paths + if(_${_lib}_inc_paths) + set(_suffixes ${_${_lib}_inc_paths}) + else() + set(_suffixes include) + endif() + foreach(_inc_name ${_${_lib}_inc}) + unset(_inc_tmp CACHE) + find_path(_inc_tmp ${_inc_name} PATH_SUFFIXES ${_suffixes} PATHS ${_dir} NO_DEFAULT_PATH) + if(_inc_tmp) + list(APPEND include_dirs ${_inc_tmp}) + endif() + endforeach() + endif(EXISTS ${_dir}) + 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}") + + set(lib_dir_candidates + ${_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) + 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) + endif() + + if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS) + set(${_prefix}_FOUND YES) + endif() + + endif(EXISTS ${_root}) + endforeach() +endforeach() diff --git a/cmake/Modules/FindCURL.cmake b/cmake/Modules/FindCURL.cmake index 4d3068737e..e286d78712 100644 --- a/cmake/Modules/FindCURL.cmake +++ b/cmake/Modules/FindCURL.cmake @@ -37,26 +37,6 @@ set(CURL_LIBRARY_NAMES libcurl ) -if(USE_PREBUILT_LIBS) - find_path(CURL_INCLUDE_DIR curl/curl.h - PATH_SUFFIXES include/${PLATFORM_FOLDER} include - PATHS ${COCOS_EXTERNAL_DIR}/curl - NO_DEFAULT_PATH - ) - find_library(CURL_LIBRARY NAMES ${CURL_LIBRARY_NAMES} - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - PATHS ${COCOS_EXTERNAL_DIR}/curl - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT CURL_INCLUDE_DIR OR NOT CURL_LIBRARY) - unset(CURL_INCLUDE_DIR CACHE) - unset(CURL_LIBRARY CACHE) - endif() -endif() - find_package(PkgConfig) if(PKG_CONFIG_FOUND) pkg_search_module(CURL QUIET libcurl) diff --git a/cmake/Modules/FindChipmunk.cmake b/cmake/Modules/FindChipmunk.cmake index b94834c338..31fc02f489 100644 --- a/cmake/Modules/FindChipmunk.cmake +++ b/cmake/Modules/FindChipmunk.cmake @@ -27,28 +27,6 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -if(USE_PREBUILT_LIBS) - find_path(CHIPMUNK_INCLUDE_DIR chipmunk.h - PATH_SUFFIXES - include/chipmunk - include - PATHS ${COCOS_EXTERNAL_DIR}/chipmunk - NO_DEFAULT_PATH - ) - find_library(CHIPMUNK_LIBRARY NAMES chipmunk libchipmunk - PATH_SUFFIXES - prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - prebuilt/${PLATFORM_FOLDER} - PATHS ${COCOS_EXTERNAL_DIR}/chipmunk - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT CHIPMUNK_INCLUDE_DIR OR NOT CHIPMUNK_LIBRARY) - unset(CHIPMUNK_INCLUDE_DIR CACHE) - unset(CHIPMUNK_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - FIND_PATH(CHIPMUNK_INCLUDE_DIR chipmunk.h HINTS ENV CHIPMUNK_DIR diff --git a/cmake/Modules/FindFMODEX.cmake b/cmake/Modules/FindFMODEX.cmake index d1318e6c03..54e4d4a800 100644 --- a/cmake/Modules/FindFMODEX.cmake +++ b/cmake/Modules/FindFMODEX.cmake @@ -13,27 +13,6 @@ # FMODEX_INCLUDE_DIRS, where to find headers. # -# Try find fmodex for our arch in external folder -set(_FMOD_COCOS_PATHS - ${COCOS_EXTERNAL_DIR}/${PLATFORM_FOLDER}-specific/fmod - ${COCOS_EXTERNAL_DIR}/fmod - ) -if(USE_PREBUILT_LIBS) - find_path(FMODEX_INCLUDE_DIR fmod.h - PATH_SUFFIXES include/${ARCH_DIR} include - PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH - ) - find_library(FMODEX_LIBRARY NAMES fmodex fmodex64 - PATH_SUFFIXES prebuilt/${ARCH_DIR} prebuilt - PATHS ${_FMOD_COCOS_PATHS} NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(NOT FMODEX_INCLUDE_DIR OR NOT FMODEX_LIBRARY) - unset(FMODEX_INCLUDE_DIR CACHE) - unset(FMODEX_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - find_path(FMODEX_INCLUDE_DIR fmod.h HINTS ENV FMODEX_DIR PATH_SUFFIXES include/fmodex include diff --git a/cmake/Modules/FindFreetype.cmake b/cmake/Modules/FindFreetype.cmake index 0fe3f3f5b2..7935a93790 100644 --- a/cmake/Modules/FindFreetype.cmake +++ b/cmake/Modules/FindFreetype.cmake @@ -43,35 +43,6 @@ #todo: fix location of freetype includes for linux android on cocos prebuilt repo #i.e we should not need to include an extra dir of /freetype2 -if(USE_PREBUILT_LIBS) - find_path(FREETYPE_INCLUDE_DIR_ft2build ft2build.h - PATHS ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} - NO_DEFAULT_PATH - ) - find_path(FREETYPE_INCLUDE_DIR_freetype2 freetype/config/ftheader.h - PATHS - ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER} - ${COCOS_EXTERNAL_DIR}/freetype2/include/${PLATFORM_FOLDER}/freetype2 - NO_DEFAULT_PATH - ) - find_library(FREETYPE_LIBRARY NAMES freetype libfreetype freetype219 freetype250 - PATHS - ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER}/${ARCH_DIR} - ${COCOS_EXTERNAL_DIR}/freetype2/prebuilt/${PLATFORM_FOLDER} - NO_DEFAULT_PATH - ) - # cleanup if not found (prevent from mix prebuilt include paths and system installed libraries) - if(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2 AND FREETYPE_LIBRARY) - set(FREETYPE_FOUND 1) - set(FREETYPE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIR_ft2build} ${FREETYPE_INCLUDE_DIR_freetype2}) - set(FREETYPE_LIBRARIES ${FREETYPE_LIBRARY}) - else() - unset(FREETYPE_INCLUDE_DIR_ft2build CACHE) - unset(FREETYPE_INCLUDE_DIR_freetype2 CACHE) - unset(FREETYPE_LIBRARY CACHE) - endif() -endif(USE_PREBUILT_LIBS) - # Try pkg-config first (because it provided deps info) if(NOT FREETYPE_FOUND) find_package(PkgConfig) diff --git a/cocos/CMakeLists.txt b/cocos/CMakeLists.txt index c200fbe710..4eda8daac8 100644 --- a/cocos/CMakeLists.txt +++ b/cocos/CMakeLists.txt @@ -97,6 +97,8 @@ elseif(LINUX) cocos_use_pkg(cocos2d ${_pkg}) endforeach() elseif(MACOSX OR APPLE) + cocos_use_pkg(cocos2d GLFW3) + INCLUDE_DIRECTORIES ( /System/Library/Frameworks ) FIND_LIBRARY(COCOA_LIBRARY Cocoa) From 012a1524060ccaf86d9a888d61f0f40c293320d1 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 13:49:59 +0300 Subject: [PATCH 55/67] Fix build of luasocket on linux --- cocos/scripting/lua-bindings/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 0b1cf50ca8..5b00b863c9 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -56,6 +56,7 @@ if(WINDOWS) ${cocos_root}/external/lua/luasocket/wsocket.c ) elseif(UNIX) + add_definitions(-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE) list(APPEND lua_cocos2d_source_files ${cocos_root}/external/lua/luasocket/serial.c ${cocos_root}/external/lua/luasocket/unix.c From 8c331649dcf73aef73acac13dd5f011bff323051 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 13:50:55 +0300 Subject: [PATCH 56/67] fix finding prebuilt fmod on linux --- cmake/Modules/CocosUsePrebuiltLibs.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/CocosUsePrebuiltLibs.cmake b/cmake/Modules/CocosUsePrebuiltLibs.cmake index 1ad3b93899..15344102f3 100644 --- a/cmake/Modules/CocosUsePrebuiltLibs.cmake +++ b/cmake/Modules/CocosUsePrebuiltLibs.cmake @@ -60,8 +60,9 @@ set(_OpenalSoft_libs OpenAL32) set(_zlib_inc zlib.h) set(_zlib_libs libzlib) +set(_fmod_prefix FMODEX) set(_fmod_inc fmod.h) -set(_fmod_libs fmodex fmodexL) +set(_fmod_libs fmodex fmodex64 fmodexL fmodexL64) set(all_prebuilt_libs chipmunk @@ -157,6 +158,7 @@ foreach(_lib ${all_prebuilt_libs}) if(libs) set(${_prefix}_LIBRARIES ${libs} CACHE STRING "Libraries to link for ${_prefix}" FORCE) endif() + #message(STATUS "${_lib} ${_prefix}_LIBRARIES: ${${_prefix}_LIBRARIES}") if(${_prefix}_LIBRARIES AND ${_prefix}_INCLUDE_DIRS) set(${_prefix}_FOUND YES) From ff172e0057dfd87fc6344386757eebfc068c46f4 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Thu, 20 Nov 2014 09:00:22 -0800 Subject: [PATCH 57/67] fixed accelerometer for windows store apps device orientation --- cocos/platform/winrt/CCDevice.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cocos/platform/winrt/CCDevice.cpp b/cocos/platform/winrt/CCDevice.cpp index e3f7edbde5..71a6ff303a 100644 --- a/cocos/platform/winrt/CCDevice.cpp +++ b/cocos/platform/winrt/CCDevice.cpp @@ -100,6 +100,7 @@ void Device::setAccelerometerEnabled(bool isEnabled) auto orientation = GLViewImpl::sharedOpenGLView()->getDeviceOrientation(); +#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) switch (orientation) { case DisplayOrientations::Portrait: @@ -127,7 +128,36 @@ void Device::setAccelerometerEnabled(bool isEnabled) acc.y = reading->AccelerationY; break; } +#else // Windows Store App + // from http://msdn.microsoft.com/en-us/library/windows/apps/dn440593 + switch (orientation) + { + case DisplayOrientations::Portrait: + acc.x = reading->AccelerationY; + acc.y = -reading->AccelerationX; + break; + case DisplayOrientations::Landscape: + acc.x = reading->AccelerationX; + acc.y = reading->AccelerationY; + break; + + case DisplayOrientations::PortraitFlipped: + acc.x = -reading->AccelerationY; + acc.y = reading->AccelerationX; + break; + + case DisplayOrientations::LandscapeFlipped: + acc.x = -reading->AccelerationY; + acc.y = reading->AccelerationX; + break; + + default: + acc.x = reading->AccelerationY; + acc.y = -reading->AccelerationX; + break; + } +#endif std::shared_ptr event(new AccelerometerEvent(acc)); cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(event); }); From 76f718a90d7a3d5a40252759f7cd0f414ceda9a8 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 20 Nov 2014 11:11:12 -0800 Subject: [PATCH 58/67] Use version 22 for external dependencies --- external/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/config.json b/external/config.json index a5c4c73a5e..4bf73adedd 100644 --- a/external/config.json +++ b/external/config.json @@ -1,5 +1,5 @@ { - "version":"v3-deps-21", + "version":"v3-deps-22", "zip_file_size":"87419231", "repo_name":"cocos2d-x-3rd-party-libs-bin", "repo_parent":"https://github.com/cocos2d/", From e91140b40936070b24063c9e03f4a1214ba32d98 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 22:22:56 +0300 Subject: [PATCH 59/67] Oops, restore tools/cocos2d-console to f1a8f35036b9cc85061d91447bce8e35439b43a1 (while merging with upstream v3 I fetched some strange commit for that module) --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index 36153464b9..f1a8f35036 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 36153464b943d179a8d21ab294030c91c6e18ace +Subproject commit f1a8f35036b9cc85061d91447bce8e35439b43a1 From 9dfa26e0ecef81ffbe3c6e5edbc9e18f5cdb62e5 Mon Sep 17 00:00:00 2001 From: Vladimir Timofeev Date: Thu, 20 Nov 2014 23:20:02 +0300 Subject: [PATCH 60/67] Quick and dirty fix after my error. This defines fix build on linux with fresh gcc, but broke on mac --- cocos/scripting/lua-bindings/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cocos/scripting/lua-bindings/CMakeLists.txt b/cocos/scripting/lua-bindings/CMakeLists.txt index 5b00b863c9..22084d136f 100644 --- a/cocos/scripting/lua-bindings/CMakeLists.txt +++ b/cocos/scripting/lua-bindings/CMakeLists.txt @@ -56,7 +56,9 @@ if(WINDOWS) ${cocos_root}/external/lua/luasocket/wsocket.c ) elseif(UNIX) - add_definitions(-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE) + if(LINUX) + add_definitions(-D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE) + endif() list(APPEND lua_cocos2d_source_files ${cocos_root}/external/lua/luasocket/serial.c ${cocos_root}/external/lua/luasocket/unix.c From 15c0b183017166125680eca9a73fcdb96d0a2b51 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 20 Nov 2014 12:28:38 -0800 Subject: [PATCH 61/67] Adds gnutls-dev to linux deps --- build/install-deps-linux.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build/install-deps-linux.sh b/build/install-deps-linux.sh index 183288af5d..2732ff78f4 100755 --- a/build/install-deps-linux.sh +++ b/build/install-deps-linux.sh @@ -21,6 +21,7 @@ DEPENDS+=' libfontconfig1-dev' DEPENDS+=' libsqlite3-dev' DEPENDS+=' libglew*-dev' DEPENDS+=' libssl-dev' +DEPENDS+=' gnutls-dev' MISSING= echo "Checking for missing packages ..." From 80b99248669488e146b32d0bfb26ddf58d813ad8 Mon Sep 17 00:00:00 2001 From: Bartosz Duszel Date: Thu, 20 Nov 2014 22:13:30 +0100 Subject: [PATCH 62/67] Updated link to information about contribution. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61cb4de288..bdab36e479 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Contact us [5]: http://www.box2d.org "Box2D" [6]: http://www.chipmunk-physics.net "Chipmunk2D" [7]: http://esotericsoftware.com/ "http://esotericsoftware.com/" -[8]: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Contribution +[8]: https://github.com/cocos2d/cocos2d-x/blob/v3/docs/CONTRIBUTE.md [9]: http://forum.cocos2d-x.org "http://forum.cocos2d-x.org" [10]: http://www.twitter.com/cocos2dx "http://www.twitter.com/cocos2dx" [11]: http://t.sina.com.cn/cocos2dx "http://t.sina.com.cn/cocos2dx" From 34550422c0a1f1a5b615d72afc4c60cd68ea0069 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 21 Nov 2014 09:37:07 +0800 Subject: [PATCH 63/67] Update AUTHORS --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 0f9ee1b0bf..16bd2643fb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1053,6 +1053,9 @@ Developers: vovkasm Fix warnings for Xcode6.1 + + nilium + Unignore libs dir in plugin and fix Travis script to descend into included directories Retired Core Developers: WenSheng Yang From 59461439ad9737d74d674d67bccf8a2cd1a8e280 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Thu, 20 Nov 2014 17:55:59 -0800 Subject: [PATCH 64/67] Updates console --- tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cocos2d-console b/tools/cocos2d-console index f1a8f35036..aa82951329 160000 --- a/tools/cocos2d-console +++ b/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit f1a8f35036b9cc85061d91447bce8e35439b43a1 +Subproject commit aa829513296354961e814078e646108e9cb92a2d From 2398712b9d4df5565cee47228836bc905c2766a2 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Fri, 21 Nov 2014 01:57:39 +0000 Subject: [PATCH 65/67] [AUTO][ci skip]: updating cocos2dx_files.json --- templates/cocos2dx_files.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index 873d75d685..cfc5a0d2c2 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -52,11 +52,26 @@ "cmake/BuildHelpers.CMakeLists.txt", "cmake/Modules/CMakeParseArguments.cmake", "cmake/Modules/CocosBuildHelpers.cmake", + "cmake/Modules/CocosUsePrebuiltLibs.cmake", + "cmake/Modules/FindCURL.cmake", "cmake/Modules/FindChipmunk.cmake", + "cmake/Modules/FindFMODEX.cmake", + "cmake/Modules/FindFontconfig.cmake", + "cmake/Modules/FindFreetype.cmake", "cmake/Modules/FindGLFW3.cmake", + "cmake/Modules/FindJPEG.cmake", + "cmake/Modules/FindMINIZIP.cmake", + "cmake/Modules/FindMPG123.cmake", + "cmake/Modules/FindOgg.cmake", + "cmake/Modules/FindPNG.cmake", "cmake/Modules/FindPackageHandleStandardArgs.cmake", "cmake/Modules/FindPackageMessage.cmake", + "cmake/Modules/FindTIFF.cmake", + "cmake/Modules/FindTinyXML2.cmake", + "cmake/Modules/FindVorbis.cmake", + "cmake/Modules/FindWEBSOCKETS.cmake", "cmake/Modules/FindWebP.cmake", + "cmake/Modules/SelectLibraryConfigurations.cmake", "cmake/android.toolchain.cmake", "cmake/ios.toolchain.cmake", "cocos/2d/CCAction.cpp", From fbd27dff9c6e1d1e4bd1bce711325ad04659cfe7 Mon Sep 17 00:00:00 2001 From: Bartosz Duszel Date: Fri, 21 Nov 2014 20:12:55 +0100 Subject: [PATCH 66/67] changed few loops for C++11 range-based for loop --- cocos/platform/CCFileUtils.cpp | 40 ++++++++++++++++------------------ cocos/platform/CCFileUtils.h | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index e0243183fc..383a3ec68f 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -447,7 +447,6 @@ static tinyxml2::XMLElement* generateElementForObject(const Value& value, tinyxm return node; } - // object is Array if (value.getType() == Value::Type::VECTOR) return generateElementForArray(value.asValueVector(), doc); @@ -467,7 +466,7 @@ static tinyxml2::XMLElement* generateElementForDict(const ValueMap& dict, tinyxm { tinyxml2::XMLElement* rootNode = doc->NewElement("dict"); - for (auto iter = dict.cbegin(); iter != dict.cend(); ++iter) + for (const auto iter : dict) { tinyxml2::XMLElement* tmpNode = doc->NewElement("key"); rootNode->LinkEndChild(tmpNode); @@ -496,7 +495,6 @@ static tinyxml2::XMLElement* generateElementForArray(const ValueVector& array, t return rootNode; } - #else NS_CC_BEGIN @@ -508,10 +506,8 @@ bool FileUtils::writeToFile(ValueMap& dict, const std::string &fullPath) {return #endif /* (CC_TARGET_PLATFORM != CC_PLATFORM_IOS) && (CC_TARGET_PLATFORM != CC_PLATFORM_MAC) */ - FileUtils* FileUtils::s_sharedFileUtils = nullptr; - void FileUtils::destroyInstance() { CC_SAFE_DELETE(s_sharedFileUtils); @@ -525,7 +521,6 @@ FileUtils::~FileUtils() { } - bool FileUtils::init() { _searchPathArray.push_back(_defaultResRootPath); @@ -550,6 +545,7 @@ static Data getData(const std::string& filename, bool forString) size_t size = 0; size_t readsize; const char* mode = nullptr; + if (forString) mode = "rt"; else @@ -633,7 +629,7 @@ unsigned char* FileUtils::getFileData(const std::string& filename, const char* m fclose(fp); } while (0); - if (! buffer) + if (!buffer) { std::string msg = "Get data from file("; msg.append(filename).append(") failed!"); @@ -728,7 +724,6 @@ std::string FileUtils::getPathForFilename(const std::string& filename, const std return path; } - std::string FileUtils::fullPathForFilename(const std::string &filename) { if (filename.empty()) @@ -743,7 +738,7 @@ std::string FileUtils::fullPathForFilename(const std::string &filename) // Already Cached ? auto cacheIter = _fullPathCache.find(filename); - if( cacheIter != _fullPathCache.end() ) + if(cacheIter != _fullPathCache.end()) { return cacheIter->second; } @@ -753,11 +748,11 @@ std::string FileUtils::fullPathForFilename(const std::string &filename) std::string fullpath; - for (auto searchIt = _searchPathArray.cbegin(); searchIt != _searchPathArray.cend(); ++searchIt) + for (const auto& searchIt : _searchPathArray) { - for (auto resolutionIt = _searchResolutionsOrderArray.cbegin(); resolutionIt != _searchResolutionsOrderArray.cend(); ++resolutionIt) + for (const auto& resolutionIt : _searchResolutionsOrderArray) { - fullpath = this->getPathForFilename(newFilename, *resolutionIt, *searchIt); + fullpath = this->getPathForFilename(newFilename, resolutionIt, searchIt); if (fullpath.length() > 0) { @@ -765,6 +760,7 @@ std::string FileUtils::fullPathForFilename(const std::string &filename) _fullPathCache.insert(std::make_pair(filename, fullpath)); return fullpath; } + } } @@ -787,9 +783,9 @@ void FileUtils::setSearchResolutionsOrder(const std::vector& search bool existDefault = false; _fullPathCache.clear(); _searchResolutionsOrderArray.clear(); - for(auto iter = searchResolutionsOrder.cbegin(); iter != searchResolutionsOrder.cend(); ++iter) + for(const auto& iter : searchResolutionsOrder) { - std::string resolutionDirectory = *iter; + std::string resolutionDirectory = iter; if (!existDefault && resolutionDirectory == "") { existDefault = true; @@ -802,6 +798,7 @@ void FileUtils::setSearchResolutionsOrder(const std::vector& search _searchResolutionsOrderArray.push_back(resolutionDirectory); } + if (!existDefault) { _searchResolutionsOrderArray.push_back(""); @@ -813,6 +810,7 @@ void FileUtils::addSearchResolutionsOrder(const std::string &order,const bool fr std::string resOrder = order; if (!resOrder.empty() && resOrder[resOrder.length()-1] != '/') resOrder.append("/"); + if (front) { _searchResolutionsOrderArray.insert(_searchResolutionsOrderArray.begin(), resOrder); } else { @@ -820,7 +818,7 @@ void FileUtils::addSearchResolutionsOrder(const std::string &order,const bool fr } } -const std::vector& FileUtils::getSearchResolutionsOrder() +const std::vector& FileUtils::getSearchResolutionsOrder() const { return _searchResolutionsOrderArray; } @@ -836,16 +834,16 @@ void FileUtils::setSearchPaths(const std::vector& searchPaths) _fullPathCache.clear(); _searchPathArray.clear(); - for (auto iter = searchPaths.cbegin(); iter != searchPaths.cend(); ++iter) + for (const auto iter : searchPaths) { std::string prefix; std::string path; - if (!isAbsolutePath(*iter)) + if (!isAbsolutePath(iter)) { // Not an absolute path prefix = _defaultResRootPath; } - path = prefix + (*iter); + path = prefix + (iter); if (path.length() > 0 && path[path.length()-1] != '/') { path += "/"; @@ -1009,12 +1007,12 @@ bool FileUtils::isDirectoryExist(const std::string& dirPath) } std::string fullpath; - for (auto searchIt = _searchPathArray.cbegin(); searchIt != _searchPathArray.cend(); ++searchIt) + for (const auto& searchIt : _searchPathArray) { - for (auto resolutionIt = _searchResolutionsOrderArray.cbegin(); resolutionIt != _searchResolutionsOrderArray.cend(); ++resolutionIt) + for (const auto& resolutionIt : _searchResolutionsOrderArray) { // searchPath + file_path + resourceDirectory - fullpath = *searchIt + dirPath + *resolutionIt; + fullpath = searchIt + dirPath + resolutionIt; if (isDirectoryExistInternal(fullpath)) { const_cast(this)->_fullPathCache.insert(std::make_pair(dirPath, fullpath)); diff --git a/cocos/platform/CCFileUtils.h b/cocos/platform/CCFileUtils.h index ee097a3c53..2323d222b5 100644 --- a/cocos/platform/CCFileUtils.h +++ b/cocos/platform/CCFileUtils.h @@ -238,7 +238,7 @@ public: * @since v2.1 * @lua NA */ - virtual const std::vector& getSearchResolutionsOrder(); + virtual const std::vector& getSearchResolutionsOrder() const; /** * Sets the array of search paths. From 9fedb143549e135d062a2f505b804f94ee64dcd4 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Fri, 21 Nov 2014 14:52:13 -0800 Subject: [PATCH 67/67] Fixes for FileUtils compiles after previous patch --- cocos/platform/CCFileUtils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos/platform/CCFileUtils.cpp b/cocos/platform/CCFileUtils.cpp index 383a3ec68f..c9723d12f7 100644 --- a/cocos/platform/CCFileUtils.cpp +++ b/cocos/platform/CCFileUtils.cpp @@ -466,14 +466,14 @@ static tinyxml2::XMLElement* generateElementForDict(const ValueMap& dict, tinyxm { tinyxml2::XMLElement* rootNode = doc->NewElement("dict"); - for (const auto iter : dict) + for (const auto &iter : dict) { tinyxml2::XMLElement* tmpNode = doc->NewElement("key"); rootNode->LinkEndChild(tmpNode); - tinyxml2::XMLText* content = doc->NewText(iter->first.c_str()); + tinyxml2::XMLText* content = doc->NewText(iter.first.c_str()); tmpNode->LinkEndChild(content); - tinyxml2::XMLElement *element = generateElementForObject(iter->second, doc); + tinyxml2::XMLElement *element = generateElementForObject(iter.second, doc); if (element) rootNode->LinkEndChild(element); } @@ -834,7 +834,7 @@ void FileUtils::setSearchPaths(const std::vector& searchPaths) _fullPathCache.clear(); _searchPathArray.clear(); - for (const auto iter : searchPaths) + for (const auto& iter : searchPaths) { std::string prefix; std::string path;