0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / samples / webgl / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.2)
2
3 project(occt-webgl-sample)
4
5 set(CMAKE_CXX_STANDARD 11)
6 set(APP_VERSION_MAJOR 1)
7 set(APP_VERSION_MINOR 0)
8 set(APP_TARGET occt-webgl-sample)
9
10 # customize build
11 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=1")
12 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_WEBGL2=1")
13 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
14 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s SAFE_HEAP=1")
15 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1")
16 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s TOTAL_MEMORY=16MB")
17 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ABORTING_MALLOC=0")
18 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s FORCE_FILESYSTEM=1")
19 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --preload-file myFile")
20
21 INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
22 file(GLOB SOURCES
23   *.h
24   *.cpp
25 )
26 source_group ("Headers" FILES
27   WasmOcctView.h)
28 source_group ("Sources" FILES
29   WasmOcctView.cpp
30   main.cpp)
31
32 # FreeType
33 find_package(freetype REQUIRED NO_DEFAULT_PATH)
34 if(freetype_FOUND)
35   message (STATUS "Using FreeType from \"${freetype_DIR}\"" )
36 else()
37   message(WARNING "Could not find FreeType, please set freetype_DIR variable." )
38 endif()
39
40 # Open CASCADE Technology
41 find_package(OpenCASCADE REQUIRED NO_DEFAULT_PATH)
42 if(OpenCASCADE_FOUND)
43   message (STATUS "Using OpenCASCADE from \"${OpenCASCADE_DIR}\"" )
44   INCLUDE_DIRECTORIES(${OpenCASCADE_INCLUDE_DIR})
45   LINK_DIRECTORIES(${OpenCASCADE_LIBRARY_DIR})
46 else()
47   message(WARNING "Could not find OpenCASCADE, please set OpenCASCADE_DIR variable." )
48   set(OCCT_LIBRARY_DIR)
49   set(OCCT_BIN_DIR)
50 endif()
51
52 set(OpenCASCADE_LIBS TKRWMesh TKBinXCAF TKBin TKBinL TKOpenGl TKXCAF TKVCAF TKCAF TKV3d TKHLR TKMesh TKService TKShHealing TKPrim TKTopAlgo TKGeomAlgo TKBRep TKGeomBase TKG3d TKG2d TKMath TKLCAF TKCDF TKernel)
53
54 add_executable(${APP_TARGET} ${SOURCES})
55 target_link_libraries(
56   ${APP_TARGET}
57   ${OpenCASCADE_LIBS}
58   freetype
59 )
60 set_target_properties(${APP_TARGET} PROPERTIES LINK_FLAGS "-s EXPORTED_FUNCTIONS=['_main','_onFileDataRead'] -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap']")
61
62 install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}")
63 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wasm DESTINATION ${CMAKE_INSTALL_PREFIX})
64 install(FILES occt-webgl-sample.html DESTINATION ${CMAKE_INSTALL_PREFIX})
65 install(FILES ${OpenCASCADE_RESOURCE_DIR}/DrawResources/OCC_logo.png DESTINATION ${CMAKE_INSTALL_PREFIX})
66 install(FILES ${OpenCASCADE_RESOURCE_DIR}/DrawResources/lamp.ico DESTINATION ${CMAKE_INSTALL_PREFIX})