-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
274 lines (235 loc) · 11 KB
/
CMakeLists.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
PROJECT(octoon_ray)
# 项目文件路径
SET(OCTOON_PATH ${PROJECT_SOURCE_DIR} CACHE STRING "Adds a path to octoon_ray" FORCE)
SET(OCTOON_PATH_BIN ${OCTOON_PATH}/lib/ CACHE STRING "Adds a path to output dir" FORCE)
SET(OCTOON_PATH_DEPENDENCIES ${OCTOON_PATH}/contrib CACHE STRING "Adds a path to octoon_ray dependencies" FORCE)
#SET(OCTOON_PATH_SAMPLE ${OCTOON_PATH}/sample CACHE STRING "Adds a path to octoon_ray sample" FORCE)
#SET(OCTOON_PATH_TOOLS ${OCTOON_PATH}/tools CACHE STRING "Adds a path to octoon_ray tools" FORCE)
#SET(OCTOON_PATH_SAMPLES ${OCTOON_PATH}/samples CACHE STRING "Adds a path to octoon_ray samples" FORCE)
SET(OCTOON_PATH_INCLUDE ${OCTOON_PATH}/include CACHE STRING "Adds a path to octoon_ray header" FORCE)
SET(OCTOON_PATH_HEADER ${OCTOON_PATH_INCLUDE}/octoon CACHE STRING "Adds a path to octoon header" FORCE)
SET(OCTOON_PATH_SOURCE ${OCTOON_PATH}/source CACHE STRING "Adds a path to octoon_ray source" FORCE)
#SET(OCTOON_PATH_DOCUMENT ${OCTOON_PATH}/document CACHE STRING "Adds a path to octoon_ray document" FORCE)
OPTION(OCTOON_BUILD_DOCUMENT "ON to enable document generation" ON)
OPTION(OCTOON_BUILD_SSE "ON for use OFF for ignore" OFF)
OPTION(OCTOON_BUILD_DEBUG_MODE "ON for debug or OFF for release" ON)
OPTION(OCTOON_BUILD_MUTILTHREAD_DLL "ON for /MD OFF for /MT" ON)
OPTION(OCTOON_BUILD_SHARED_DLL "ON for dynamic OFF for static libraries" ON)
# 设置默认编译平台
IF(ANDROID_ABI OR CMAKE_SYSTEM_NAME MATCHES "VCMDDAndroid")
SET(PLATFORM 4)
SET(VCMDDAndroid 1)
ELSEIF(WIN32)
SET(PLATFORM 3)
ELSEIF(APPLE)
SET(PLATFORM 1)
ELSEIF(UNIX)
SET(PLATFORM 2)
ELSE()
SET(PLATFORM 3)
ENDIF()
# 设置编译平台
SET(OCTOON_BUILD_PLATFORM ${PLATFORM} CACHE STRING
"Specify the platform. Possible values:
1 - Apple
2 - Linux
3 - Windows
4 - Android
5 - Java
6 - Emscripten"
)
IF(OCTOON_BUILD_PLATFORM EQUAL 1)
SET(OCTOON_BUILD_PLATFORM_APPLE TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_APPLE)
ELSEIF(OCTOON_BUILD_PLATFORM EQUAL 2)
SET(OCTOON_BUILD_PLATFORM_LINUX TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_LINUX)
ELSEIF(OCTOON_BUILD_PLATFORM EQUAL 3)
SET(OCTOON_BUILD_PLATFORM_WINDOWS TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_WINDOWS)
ELSEIF(OCTOON_TARGET_PLATFORM EQUAL 4)
SET(OCTOON_BUILD_PLATFORM_ANDROID TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_ANDROID)
ELSEIF(OCTOON_BUILD_PLATFORM EQUAL 5)
SET(OCTOON_BUILD_PLATFORM_JAVA TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_JAVA)
ELSEIF(OCTOON_BUILD_PLATFORM EQUAL 6)
SET(OCTOON_BUILD_PLATFORM_EMSCRIPTEN TRUE)
ADD_DEFINITIONS(-DOCTOON_BUILD_PLATFORM_EMSCRIPTEN)
ELSE()
MESSAGE(FATAL_ERROR "Unsupported build platform: " ${OCTOON_BUILD_PLATFORM})
ENDIF()
IF(OCTOON_BUILD_DEBUG_MODE)
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "One of None Debug Release RelWithDebInfo MinSizeRel" FORCE)
ELSE()
SET(CMAKE_BUILD_TYPE Release CACHE STRING "One of None Debug Release RelWithDebInfo MinSizeRel" FORCE)
ENDIF()
# 设置不同平台下链接时后缀
IF(OCTOON_BUILD_PLATFORM_LINUX OR OCTOON_BUILD_PLATFORM_ANDROID)
SET(PLATFORM_NAME "linux")
ELSEIF(OCTOON_BUILD_PLATFORM_APPLE)
SET(PLATFORM_NAME "apple")
ELSEIF(OCTOON_BUILD_PLATFORM_EMSCRIPTEN)
SET(PLATFORM_NAME "web")
ELSEIF(OCTOON_BUILD_PLATFORM_WINDOWS)
SET(PLATFORM_NAME "win")
ADD_DEFINITIONS(-D_WINDOWS)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
SET(COMPILER_NAME "vc")
IF(MSVC_VERSION GREATER 1600)
SET(COMPILER_NAME "11")
ELSEIF(MSVC_VERSION GREATER 1500)
SET(COMPILER_NAME "10")
ELSEIF(MSVC_VERSION GREATER 1400)
SET(COMPILER_NAME "9")
ENDIF()
ENDIF()
IF(CMAKE_GENERATOR MATCHES "ARM")
SET(LIBRARY_OUT_NAME "ARM")
ELSEIF(CMAKE_GENERATOR MATCHES "Win64")
SET(LIBRARY_OUT_NAME "64")
SET(WIN64 TRUE)
ELSEIF(CMAKE_GENERATOR MATCHES "Visual Studio")
SET(LIBRARY_OUT_NAME "86")
SET(WIN32 TRUE)
ELSE()
SET(LIBRARY_OUT_NAME "86")
ENDIF()
# CXX 14 扩展
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
# 设置编译文件后缀
SET(CMAKE_DEBUG_POSTFIX "_d" CACHE STRING "Adds a postfix for debug-built libraries.")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Adds a postfix for release-built libraries.")
SET(CMAKE_RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo" CACHE STRING "Adds a postfix for ReleaseWithDebug-built libraries.")
SET(CMAKE_MINSIZEREL_POSTFIX "_MinsizeRel" CACHE STRING "Adds a postfix for MinsizeRelease-built libraries.")
# 指定库文件输出路径
SET(OCTOON_LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib/binaries/${PLATFORM_NAME}${LIBRARY_OUT_NAME} CACHE STRING "build path" FORCE)
SET(OCTOON_LIBRARY_OUTPUT_PATH_DEBUG ${OCTOON_LIBRARY_OUTPUT_PATH}_Debug CACHE STRING "build path" FORCE)
SET(OCTOON_LIBRARY_OUTPUT_PATH_RELEASE ${OCTOON_LIBRARY_OUTPUT_PATH}_Release CACHE STRING "build path" FORCE)
SET(OCTOON_LIBRARY_OUTPUT_PATH_RELWITHDEBINFO ${OCTOON_LIBRARY_OUTPUT_PATH}_RelWithDebugInfo CACHE STRING "build path" FORCE)
SET(OCTOON_LIBRARY_OUTPUT_PATH_MINSIZEREL ${OCTOON_LIBRARY_OUTPUT_PATH}_MinsizeRel CACHE STRING "build path" FORCE)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
MACRO(SET_TARGET_ATTRIBUTE target directory)
SET_TARGET_PROPERTIES(${target} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${OCTOON_LIBRARY_OUTPUT_PATH}
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${OCTOON_LIBRARY_OUTPUT_PATH_DEBUG}
ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${OCTOON_LIBRARY_OUTPUT_PATH_RELEASE}
ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OCTOON_LIBRARY_OUTPUT_PATH_RELWITHDEBINFO}
ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${OCTOON_LIBRARY_OUTPUT_PATH_MINSIZEREL}
LIBRARY_OUTPUT_DIRECTORY ${OCTOON_LIBRARY_OUTPUT_PATH}
LIBRARY_OUTPUT_DIRECTORY_DEBUG ${OCTOON_LIBRARY_OUTPUT_PATH_DEBUG}
LIBRARY_OUTPUT_DIRECTORY_RELEASE ${OCTOON_LIBRARY_OUTPUT_PATH_RELEASE}
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OCTOON_LIBRARY_OUTPUT_PATH_RELWITHDEBINFO}
LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${OCTOON_LIBRARY_OUTPUT_PATH_MINSIZEREL}
RUNTIME_OUTPUT_DIRECTORY ${OCTOON_LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OCTOON_LIBRARY_OUTPUT_PATH_DEBUG}
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OCTOON_LIBRARY_OUTPUT_PATH_RELEASE}
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OCTOON_LIBRARY_OUTPUT_PATH_RELWITHDEBINFO}
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${OCTOON_LIBRARY_OUTPUT_PATH_MINSIZEREL}
)
SET_TARGET_PROPERTIES(${target} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
SET_TARGET_PROPERTIES(${target} PROPERTIES PROJECT_LABEL ${target})
SET_TARGET_PROPERTIES(${target} PROPERTIES FOLDER ${directory})
IF(MINGW OR CMAKE_GENERATOR MATCHES "Unix")
STRING(REGEX REPLACE "lib" "" target_name ${target})
SET_TARGET_PROPERTIES(${target} PROPERTIES OUTPUT_NAME ${target_name})
ENDIF()
IF(CMAKE_GENERATOR MATCHES "Visual Studio")
IF(VCMDDAndroid)
SET_PROPERTY(TARGET ${LIB_NAME} PROPERTY VC_MDD_ANDROID_API_LEVEL "android-21")
ELSEIF(${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v140_clang_3_7")
SET_PROPERTY(TARGET ${LIB_NAME} PROPERTY VS_PLATFORM_TOOLSET_OVERRIDE "v140_clang_3_7")
ENDIF()
ENDIF()
ENDMACRO()
IF(CMAKE_GENERATOR MATCHES "Unix" OR CMAKE_GENERATOR MATCHES "MinGW")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wignored-qualifiers")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finput-charset=utf-8")
IF(CMAKE_GENERATOR MATCHES "MinGW")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wlogical-op-parentheses")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winconsistent-missing-override")
ENDIF()
IF(CMAKE_GENERATOR MATCHES "Unix")
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF()
IF(OCTOON_BUILD_SSE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
ENDIF()
ELSEIF(CMAKE_GENERATOR MATCHES "Xcode")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -frtti")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
ELSEIF(CMAKE_GENERATOR MATCHES "Visual Studio")
IF(${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v140_clang_3_7" OR ${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL VCMDDAndroid)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -frtti")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
ELSE()
# 运行时类型信息
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /GR")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR")
# 快速的浮点模型
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
# 多处理器编译
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /W0")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
# SEH
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /EHa")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /EHa")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /EHa")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /EHa")
IF(OCTOON_BUILD_MUTILTHREAD_DLL)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MDd")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MD")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
ELSE()
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
ENDIF()
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ot")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
IF(OCTOON_BUILD_SSE)
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /arch:SSE")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
ENDIF()
ENDIF()
# 添加依赖库
ADD_SUBDIRECTORY(contrib)
IF(CMAKE_GENERATOR MATCHES "Visual Studio")
IF(${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL "v140_clang_3_7" OR ${CMAKE_VS_PLATFORM_TOOLSET} STREQUAL VCMDDAndroid)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Wall")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wreorder") # field 'x' will be initialized after field 'y'
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wshift-negative-value")
ELSE()
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4")
# W3
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4251") # needs to have dll-interface to be used by clients of class
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4275") # 非 dll 接口 class“std::exception”用作 dll 接口 class“Exception”的基
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4611") # setjmp
# W4
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4100") # 未引用的形参
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4201") # 使用了非标准扩展: 无名称的结构/联合
ENDIF()
ENDIF()
# 添加项目
ADD_SUBDIRECTORY(source)
# 工具
#ADD_SUBDIRECTORY(tools)
# 示例
#ADD_SUBDIRECTORY(samples)