forked from cocos2d/cocos2d-x
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCocosConfigDefine.cmake
135 lines (128 loc) · 4.35 KB
/
CocosConfigDefine.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#Please use them everywhere
#WINDOWS = Windows Desktop
#ANDROID = Android
#IOS = iOS
#MACOSX = MacOS X
#LINUX = Linux
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
set(PLATFORM_FOLDER win32)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
set(PLATFORM_FOLDER android)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(ANDROID)
set(PLATFORM_FOLDER android)
else()
set(LINUX TRUE)
set(PLATFORM_FOLDER linux)
endif()
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(IOS)
set(APPLE TRUE)
set(PLATFORM_FOLDER ios)
else()
set(APPLE TRUE)
set(MACOSX TRUE)
set(PLATFORM_FOLDER mac)
endif()
else()
message(FATAL_ERROR "Unsupported platform, CMake will exit")
return()
endif()
# generators that are capable of organizing into a hierarchy of folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# simplify generator condition, please use them everywhere
if(CMAKE_GENERATOR STREQUAL Xcode)
set(XCODE TRUE)
elseif(CMAKE_GENERATOR MATCHES Visual)
set(VS TRUE)
endif()
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
if(CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Reset the configurations to what we need" FORCE)
message(STATUS "CMAKE_CONFIGURATION_TYPES: ${CMAKE_CONFIGURATION_TYPES}")
else()
if(NOT CMAKE_BUILD_TYPE)
if(DEBUG_MODE) # build mode, Debug is default value
set(CMAKE_BUILD_TYPE Debug)
else()
set(CMAKE_BUILD_TYPE Release)
endif()
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()
# custom target property for lua/js link
define_property(TARGET
PROPERTY CC_JS_DEPEND
BRIEF_DOCS "cocos2d js depend libs"
FULL_DOCS "use to save depend libs of cocos2d js project"
)
define_property(TARGET
PROPERTY CC_LUA_DEPEND
BRIEF_DOCS "cocos2d lua depend libs"
FULL_DOCS "use to save depend libs of cocos2d lua project"
)
# check c++ standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# check visual studio version
if(WINDOWS)
# not support other compile tools except MSVC for now
if(MSVC)
# Visual Studio 2015, MSVC_VERSION 1900 (v140 toolset)
# Visual Studio 2017, MSVC_VERSION 1910-1919 (v141 toolset)
if(${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
message(STATUS "using Windows MSVC generate cocos2d-x project, MSVC_VERSION:${MSVC_VERSION}")
else()
message(FATAL_ERROR "using Windows MSVC generate cocos2d-x project, MSVC_VERSION:${MSVC_VERSION} lower than needed")
endif()
else()
message(FATAL_ERROR "please using Windows MSVC compile cocos2d-x project, support other compile tools not yet")
endif()
endif()
# Set macro definitions for special platforms
function(use_cocos2dx_compile_define target)
target_compile_definitions(${target} PUBLIC $<$<CONFIG:Debug>:COCOS2D_DEBUG=1>)
if(APPLE)
target_compile_definitions(${target} PUBLIC __APPLE__)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(LINUX)
target_compile_definitions(${target} PUBLIC LINUX)
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
elseif(ANDROID)
target_compile_definitions(${target} PUBLIC ANDROID)
target_compile_definitions(${target} PUBLIC USE_FILE32API)
elseif(WINDOWS)
target_compile_definitions(${target}
PUBLIC WIN32
PUBLIC _WIN32
PUBLIC _WINDOWS
PUBLIC UNICODE
PUBLIC _UNICODE
PUBLIC _CRT_SECURE_NO_WARNINGS
PUBLIC _SCL_SECURE_NO_WARNINGS
)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${target}
PUBLIC _USRDLL
PUBLIC _EXPORT_DLL_
PUBLIC _USEGUIDLL
PUBLIC _USREXDLL
PUBLIC _USRSTUDIODLL
PUBLIC _USE3DDLL
)
else()
target_compile_definitions(${target} PUBLIC CC_STATIC)
endif()
endif()
endfunction()
# Set compiler options
function(use_cocos2dx_compile_options target)
if(MSVC)
target_compile_options(${target}
PUBLIC /MP
)
endif()
endfunction()