forked from QuantumCoderQC/haxerecast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
166 lines (148 loc) · 6.63 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
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
FIND_PACKAGE(Python3)
set(PYTHON ${Python3_EXECUTABLE} CACHE STRING "Python path")
set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten CACHE STRING "Emscripten path")
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake)
set(WEBIDL_BINDER_SCRIPT ${EMSCRIPTEN_ROOT}/tools/webidl_binder.py)
set(RECAST_IDL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Sources/recast/recast.idl)
set(RECASTAPI_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/src/recastjs.h)
set(RECAST_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Recast/Include/Recast.h)
set(NAVMESHQUERY_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Detour/Include/DetourNavMeshQuery.h)
set(RECAST_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/src/)
set(RECAST_ONLOAD_FILE ${CMAKE_CURRENT_SOURCE_DIR}/recastjs/onload.js)
project (recastjs)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB_RECURSE SRC_FILES
${CMAKE_SOURCE_DIR}/recastnavigation/src/*.h
${CMAKE_SOURCE_DIR}/recastnavigation/src/*.cpp
)
file(GLOB RECASTDETOUR_FILES
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourAlloc.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourAssert.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourCommon.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourNavMesh.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourNavMeshQuery.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Detour/Source/DetourNode.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourCrowd.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourLocalBoundary.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourObstacleAvoidance.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourPathCorridor.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourPathQueue.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourCrowd/Source/DetourProximityGrid.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourTileCache/Source/DetourTileCache.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/DetourTileCache/Source/DetourTileCacheBuilder.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/Recast.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastAlloc.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastArea.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastAssert.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastContour.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastFilter.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastLayers.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastMesh.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastMeshDetail.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastRasterization.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/Recast/Source/RecastRegion.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/RecastDemo/Source/ChunkyTriMesh.cpp
${CMAKE_SOURCE_DIR}/recastnavigation/RecastDemo/Contrib/fastlz/fastlz.c
)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/src
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Detour/Include
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/DetourCrowd/Include
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/DetourTileCache/Include
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Recast/Include
${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/RecastDemo/Include
)
SET(EXE_NAME "recast")
ADD_LIBRARY(${EXE_NAME} ${SRC_FILES} ${RECASTDETOUR_FILES})
# Build Release by default
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build Type")
# Default is 64*1024*1024 = 64MB
set(TOTAL_MEMORY 67108864 CACHE STRING "Total Memory")
# Enable for resizable heap, with some amount of slowness
set(ALLOW_MEMORY_GROWTH 0 CACHE STRING "Allow Memory Growth")
set(EMCC_ARGS
-flto
--post-js glue.js
--post-js ${RECAST_ONLOAD_FILE}
-O3
-s ALLOW_MEMORY_GROWTH=${ALLOW_MEMORY_GROWTH}
-s ALLOW_TABLE_GROWTH=1
-s EXPORTED_FUNCTIONS=["_malloc","_free"]
-s EXPORTED_RUNTIME_METHODS=["UTF8ToString"]
-s EXTRA_EXPORTED_RUNTIME_METHODS=["addFunction"]
-s EXPORT_NAME="Recast"
-s MODULARIZE=1
-s NO_EXIT_RUNTIME=1
-s NO_FILESYSTEM=1
-s TOTAL_MEMORY=${TOTAL_MEMORY})
if(${CLOSURE})
# Ignore closure errors about the bullet Node class
# (Node is a DOM thing too)
LIST(APPEND EMCC_ARGS
--closure 1
-s IGNORE_CLOSURE_COMPILER_ERRORS=1)
else()
LIST(APPEND EMCC_ARGS
-s NO_DYNAMIC_EXECUTION=1)
endif()
set(EMCC_JS_ARGS ${EMCC_ARGS}
-s AGGRESSIVE_VARIABLE_ELIMINATION=1
-s ELIMINATE_DUPLICATE_FUNCTIONS=1
-s LEGACY_VM_SUPPORT=1
-s SINGLE_FILE=1
-s FILESYSTEM=0
-s ENVIRONMENT='web')
set(EMCC_JS_ES6ARGS ${EMCC_ARGS}
-s EXPORT_ES6=1
-s MODULARIZE=1
-s SINGLE_FILE=1
-s FILESYSTEM=0
-s ENVIRONMENT='web')
set(EMCC_WASM_ARGS ${EMCC_ARGS}
-s BINARYEN_IGNORE_IMPLICIT_TRAPS=1
-s WASM=1)
set(EMCC_GLUE_ARGS
-c
-I${RECAST_SRC_DIR}
-I${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Detour/Include
-I${CMAKE_CURRENT_SOURCE_DIR}/recastnavigation/Recast/Include
-include${RECASTAPI_HEADER_FILE}
-include${RECAST_HEADER_FILE}
-include${NAVMESHQUERY_HEADER_FILE}
)
#######################################
add_custom_command(
OUTPUT glue.cpp glue.js
BYPRODUCTS parser.out WebIDLGrammar.pkl
COMMAND ${PYTHON} ${WEBIDL_BINDER_SCRIPT} ${RECAST_IDL_FILE} glue
DEPENDS ${RECAST_IDL_FILE}
COMMENT "Generating ${EXE_NAME} bindings"
VERBATIM)
add_custom_command(
OUTPUT glue.o
COMMAND emcc glue.cpp ${EMCC_GLUE_ARGS} -o glue.o
DEPENDS glue.cpp ${RECASTAPI_HEADER_FILE} ${RECAST_HEADER_FILE} ${NAVMESHQUERY_HEADER_FILE}
COMMENT "Building ${EXE_NAME} bindings"
VERBATIM)
add_custom_target(${EXE_NAME}-bindings ALL DEPENDS glue.js glue.o)
#######################################
# full UMD
add_custom_command(
OUTPUT ${EXE_NAME}.js
COMMAND emcc glue.o lib${EXE_NAME}.a ${EMCC_JS_ARGS} -o ${EXE_NAME}.js
DEPENDS ${EXE_NAME}-bindings ${EXE_NAME} ${RECAST_ONLOAD_FILE}
COMMENT "Building ${EXE_NAME} javascript"
VERBATIM)
add_custom_target(${EXE_NAME}-javascript ALL DEPENDS ${EXE_NAME}.js)
#######################################
add_custom_command(
OUTPUT ${EXE_NAME}.wasm.js ${EXE_NAME}.wasm.wasm
COMMAND emcc glue.o lib${EXE_NAME}.a ${EMCC_WASM_ARGS} -o ${EXE_NAME}.wasm.js
DEPENDS ${EXE_NAME}-bindings ${EXE_NAME} ${RECAST_ONLOAD_FILE}
COMMENT "Building ${EXE_NAME} webassembly"
VERBATIM)
add_custom_target(${EXE_NAME}-wasm ALL DEPENDS ${EXE_NAME}.wasm.js ${EXE_NAME}.wasm.wasm)