0032433: Visualization, TKService - introduce Wasm_Window implementing Aspect_Window...
[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 # option to enable or disable use of precompiled headers
11 if (NOT DEFINED SOURCE_MAP_BASE)
12   set (SOURCE_MAP_BASE "" CACHE STRING "Path to source map server for debugging C++ code; e.g. http://localhost:9090/")
13 endif()
14
15 # customize build
16 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=1")
17 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s MAX_WEBGL_VERSION=2")
18 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
19 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --bind")
20 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s SAFE_HEAP=1")
21 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1")
22 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s TOTAL_MEMORY=16MB")
23 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ABORTING_MALLOC=0")
24 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s FORCE_FILESYSTEM=1")
25 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --preload-file myFile")
26 if (NOT "${SOURCE_MAP_BASE}" STREQUAL "")
27   set(CMAKE_CXX_FLAGS_DEBUG "-g4 --source-map-base ${SOURCE_MAP_BASE}")
28 endif()
29 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s MODULARIZE=1")
30 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORT_NAME='createOccViewerModule'")
31 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --extern-post-js ${CMAKE_CURRENT_SOURCE_DIR}/occt-webgl-viewer.js")
32
33 INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
34 file(GLOB SOURCES
35   *.h
36   *.cpp
37 )
38 source_group ("Headers" FILES
39   WasmOcctView.h
40   WasmOcctPixMap.h)
41 source_group ("Sources" FILES
42   WasmOcctView.cpp
43   WasmOcctPixMap.cpp
44   main.cpp)
45
46 # FreeType
47 find_package(freetype REQUIRED NO_DEFAULT_PATH)
48 if(freetype_FOUND)
49   message (STATUS "Using FreeType from \"${freetype_DIR}\"" )
50 else()
51   message(WARNING "Could not find FreeType, please set freetype_DIR variable." )
52 endif()
53
54 # Open CASCADE Technology
55 find_package(OpenCASCADE REQUIRED NO_DEFAULT_PATH)
56 if(OpenCASCADE_FOUND)
57   message (STATUS "Using OpenCASCADE from \"${OpenCASCADE_DIR}\"" )
58   INCLUDE_DIRECTORIES(${OpenCASCADE_INCLUDE_DIR})
59   LINK_DIRECTORIES(${OpenCASCADE_LIBRARY_DIR})
60 else()
61   message(WARNING "Could not find OpenCASCADE, please set OpenCASCADE_DIR variable." )
62   set(OCCT_LIBRARY_DIR)
63   set(OCCT_BIN_DIR)
64 endif()
65
66 set(OpenCASCADE_LIBS TKRWMesh TKBinXCAF TKBin TKBinL TKOpenGles TKXCAF TKVCAF TKCAF TKV3d TKHLR TKMesh TKService TKShHealing TKPrim TKTopAlgo TKGeomAlgo TKBRep TKGeomBase TKG3d TKG2d TKMath TKLCAF TKCDF TKernel)
67
68 add_executable(${APP_TARGET} ${SOURCES})
69 target_link_libraries(
70   ${APP_TARGET}
71   ${OpenCASCADE_LIBS}
72   freetype
73 )
74
75 install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}")
76 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wasm DESTINATION ${CMAKE_INSTALL_PREFIX})
77 if (NOT "${SOURCE_MAP_BASE}" STREQUAL "")
78   if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
79     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.wasm.map DESTINATION ${CMAKE_INSTALL_PREFIX})
80   endif()
81 endif()
82 install(FILES occt-webgl-sample.html DESTINATION ${CMAKE_INSTALL_PREFIX})
83 install(FILES ${OpenCASCADE_RESOURCE_DIR}/DrawResources/OCC_logo.png DESTINATION ${CMAKE_INSTALL_PREFIX})
84 install(FILES ${OpenCASCADE_RESOURCE_DIR}/DrawResources/lamp.ico DESTINATION ${CMAKE_INSTALL_PREFIX})