config.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /****************************************************************************
  2. Copyright (c) 2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #pragma once
  22. #define SCRIPT_ENGINE_NONE 0
  23. //#define SCRIPT_ENGINE_SM 1
  24. #define SCRIPT_ENGINE_V8 2
  25. #define SCRIPT_ENGINE_JSC 3
  26. //#define SCRIPT_ENGINE_CHAKRACORE 4
  27. #define SCRIPT_ENGINE_V8_ON_MAC 1 // default using v8 on macOS, set 0 to disable
  28. #if defined(__APPLE__)
  29. #include <TargetConditionals.h>
  30. #if TARGET_OS_OSX
  31. #if (SCRIPT_ENGINE_V8_ON_MAC == 0)
  32. #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_JSC
  33. #else
  34. #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
  35. #endif
  36. #endif
  37. #if TARGET_OS_IOS
  38. #ifdef __arm64__
  39. #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
  40. #else
  41. #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_JSC
  42. #endif
  43. #endif
  44. //TODO how to make simulator build with v8 too? Because in release mode, it will build
  45. // which means it will build armv7, but v8 doesn't support armv7.
  46. #else
  47. #define SCRIPT_ENGINE_TYPE SCRIPT_ENGINE_V8
  48. #endif
  49. #ifndef USE_V8_DEBUGGER
  50. #if defined(COCOS2D_DEBUG) && COCOS2D_DEBUG > 0
  51. #define USE_V8_DEBUGGER 1
  52. #else
  53. #define USE_V8_DEBUGGER 0
  54. #endif
  55. #endif
  56. #define SE_LOG_TO_JS_ENV 0 // print log to JavaScript environment, for example DevTools
  57. #if !defined(ANDROID_INSTANT) && defined(USE_V8_DEBUGGER) && USE_V8_DEBUGGER > 0
  58. #define SE_ENABLE_INSPECTOR 1
  59. #define SE_DEBUG 2
  60. #define HAVE_INSPECTOR 1
  61. #else
  62. #define SE_ENABLE_INSPECTOR 0
  63. #define SE_DEBUG 0
  64. #define HAVE_INSPECTOR 0
  65. #endif
  66. #ifdef ANDROID
  67. #include <android/log.h>
  68. #define LOG_TAG "jswrapper"
  69. #define SE_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
  70. #define SE_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
  71. #elif defined(_WIN32) && defined(_WINDOWS)
  72. #ifndef QUOTEME_
  73. #define QUOTEME_(x) #x
  74. #endif
  75. #ifndef QUOTEME
  76. #define QUOTEME(x) QUOTEME_(x)
  77. #endif
  78. void seLogD(const char * format, ...);
  79. void seLogE(const char * format, ...);
  80. #define LOG_TAG "jswrapper"
  81. #define SE_LOGD(fmt, ...) seLogD("D/" LOG_TAG " (" QUOTEME(__LINE__) "): " fmt "", ##__VA_ARGS__)
  82. #define SE_LOGE(fmt, ...) seLogE("E/" LOG_TAG " (" QUOTEME(__LINE__) "): " fmt "", ##__VA_ARGS__)
  83. #else
  84. #define SE_LOGD(...) do { fprintf(stdout, __VA_ARGS__); fflush(stdout); } while (false)
  85. #define SE_LOGE(...) do { fprintf(stderr, __VA_ARGS__); fflush(stderr); } while (false)
  86. #endif
  87. #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  88. #define __POSIX__
  89. #endif
  90. #if defined(_WIN32) && defined(_WINDOWS)
  91. #include <BaseTsd.h>
  92. #ifndef __SSIZE_T
  93. #define __SSIZE_T
  94. typedef SSIZE_T ssize_t;
  95. #define _SSIZE_T_DEFINED // libuv also defines ssize_t, use the one defined here.
  96. #endif // __SSIZE_T
  97. #endif // #if defined(_WIN32) && defined(_WINDOWS)
  98. /** @def SE_DEPRECATED_ATTRIBUTE
  99. * Only certain compilers support __attribute__((deprecated)).
  100. */
  101. #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
  102. #define SE_DEPRECATED_ATTRIBUTE __attribute__((deprecated))
  103. #elif _MSC_VER >= 1400 //vs 2005 or higher
  104. #define SE_DEPRECATED_ATTRIBUTE __declspec(deprecated)
  105. #else
  106. #define SE_DEPRECATED_ATTRIBUTE
  107. #endif // SE_DEPRECATED_ATTRIBUTE