Skip to content

Commit

Permalink
🔧 build: Updated the CMake configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Sep 25, 2024
1 parent 69f6f36 commit 8406a2d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 29 deletions.
52 changes: 28 additions & 24 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
cmake_minimum_required (VERSION 3.30)

project (chili-wasm VERSION 0.4.0)
project (chili-wasm)
set (CMAKE_CXX_STANDARD 17)
set (TARGET chili-wasm)
set (CMAKE_CONFIGURATION_TYPES Debug;Release)

get_filename_component(SOURCE_ROOT_DIR ${CMAKE_SOURCE_DIR} DIRECTORY)
set(CMAKE_INSTALL_PREFIX "${SOURCE_ROOT_DIR}/packages/chili-wasm/lib")

set (OcctModules
#FoundationClasses
# FoundationClasses
TKernel TKMath
# ModelingData
TKG2d TKG3d TKGeomBase TKBRep
#ModelingAlgorithms
# ModelingAlgorithms
TKGeomAlgo TKTopAlgo TKPrim TKBO TKBool TKHLR TKFillet TKOffset TKFeat TKMesh TKShHealing
#Visualization
# Visualization
TKService TKV3d
#ApplicationFramework
# ApplicationFramework
TKCDF TKLCAF TKCAF TKStdL TKStd TKVCAF TKBin TKBinL TKBinXCAF
#DataExchange
# DataExchange
TKDE TKXSBase TKDESTEP TKDEIGES TKDESTL TKDEVRML TKDEOBJ TKDEGLTF TKDEPLY TKXCAF TKRWMesh
)

Expand All @@ -28,10 +29,10 @@ set (OcctIncludeDirs)
foreach(module ${OcctModules})
file (STRINGS build/occt/src/${module}/PACKAGES OcctPackage)
foreach(package ${OcctPackage})
if (NOT package STREQUAL "")
list (APPEND OcctSourceFolders build/occt/src/${package}/*.c*)
list (APPEND OcctIncludeDirs build/occt/src/${package})
endif()
if (NOT package STREQUAL "")
list (APPEND OcctSourceFolders build/occt/src/${package}/*.c*)
list (APPEND OcctIncludeDirs build/occt/src/${package})
endif()
endforeach()
endforeach()

Expand All @@ -49,21 +50,24 @@ source_group ("OCCT" FILES ${OcctSourceFiles})
if (${EMSCRIPTEN})
add_executable (${TARGET} ${ChiliWasmSourceFiles} ${OcctSourceFiles})

target_compile_options (${TARGET} PUBLIC -O3)
target_compile_options (${TARGET} PUBLIC -flto)
target_compile_options (${TARGET} PUBLIC -DOCCT_NO_PLUGINS)
target_compile_options (${TARGET} PUBLIC -sDISABLE_EXCEPTION_CATCHING=1)
target_compile_options (${TARGET} PUBLIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Release>:-flto>
-sDISABLE_EXCEPTION_CATCHING=1
-DOCCT_NO_PLUGINS
)

target_link_options (${TARGET} PUBLIC -flto)
target_link_options (${TARGET} PUBLIC -O3)
target_link_options (${TARGET} PUBLIC -sDISABLE_EXCEPTION_CATCHING=1)
target_link_options (${TARGET} PUBLIC -sMODULARIZE=1)
target_link_options (${TARGET} PUBLIC -sEXPORT_ES6=1)
target_link_options (${TARGET} PUBLIC -sEXPORT_NAME='ChiliWasm')
target_link_options (${TARGET} PUBLIC -sALLOW_MEMORY_GROWTH=1)
target_link_options (${TARGET} PUBLIC -sENVIRONMENT="web")
target_link_options (${TARGET} PUBLIC --bind)
target_link_options (${TARGET} PUBLIC --emit-tsd "${TARGET}.d.ts")
target_link_options (${TARGET} PUBLIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Release>:-flto>
-sDISABLE_EXCEPTION_CATCHING=1
-sMODULARIZE=1
-sEXPORT_ES6=1
-sALLOW_MEMORY_GROWTH=1
-sENVIRONMENT="web"
--bind
--emit-tsd "${TARGET}.d.ts"
)

target_include_directories (${TARGET} PUBLIC ${OcctIncludeDirs})

Expand Down
35 changes: 33 additions & 2 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,41 @@
"configurePresets": [
{
"name": "default",
"displayName": "Emscripten",
"binaryDir": "build/chili",
"generator": "Ninja",
"hidden": true,
"toolchainFile": "build/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
},
{
"name": "debug",
"inherits": "default",
"displayName": "Emscripten Debug",
"binaryDir": "build/target/debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "default",
"displayName": "Emscripten Release",
"binaryDir": "build/target/release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug",
"configuration": "Debug",
"targets": ["install"]
},
{
"name": "release",
"configurePreset": "release",
"configuration": "Release",
"targets": ["install"]
}
]
}
2 changes: 1 addition & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When compiling for the first time, or if the build directory has been deleted or
npm run setup:wasm
```

If you see **Setup complete**, it means it was successful. Otherwise, please check the logs and try running again.
If you see **Setup complete**, it means it was successful. Otherwise, please check the logs and try again.

## Compile

Expand Down
10 changes: 9 additions & 1 deletion cpp/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<script type="module">
window.onload = async () => {
let output = document.getElementById('output');
let initWasm = await import('../build/chili/chili-wasm.js');
let initWasm = await import('../build/target/debug/chili-wasm.js');
let wasm = await initWasm.default();
test("test face mesh", (expect) => {
let point1 = new wasm.gp_Pnt(0, 0, 0);
Expand Down Expand Up @@ -150,9 +150,17 @@
expect(edges.length).toBe(12);
expect(edges[0].shapeType()).toBe(wasm.TopAbs_ShapeEnum.TopAbs_EDGE);

let curve = wasm.Edge.curve(wasm.TopoDS.edge(edges[0]))
let newEdge = wasm.Edge.fromCurve(curve.get());
expect(wasm.Edge.curveLength(newEdge)).toBe(1);

let faces = wasm.Shape.findAncestor(box, edges[0], wasm.TopAbs_ShapeEnum.TopAbs_FACE);
expect(faces.length).toBe(2);
expect(faces[0].shapeType()).toBe(wasm.TopAbs_ShapeEnum.TopAbs_FACE)

let faceEdges = wasm.Shape.findSubShapes(faces[0], wasm.TopAbs_ShapeEnum.TopAbs_EDGE);
expect(faceEdges.length).toBe(4);

})

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "npx rspack dev",
"build": "npx rspack build",
"build:wasm": "cd cpp && cmake --preset default -B build/chili && cmake --build build/chili --target install",
"build:wasm": "cd cpp && cmake --preset release && cmake --build --preset release",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"testc": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"prettier": "npx prettier --write .",
Expand Down

0 comments on commit 8406a2d

Please sign in to comment.