0032342: Draw Harness - preload basic Tcl scripts into WebAssembly
[occt.git] / src / DRAWEXE / CMakeLists.txt
1 project(DRAWEXE)
2
3 unset (CUSTOM_EXTERNLIB)
4 if (NOT BUILD_SHARED_LIBS)
5   # link specific list of plugins explicitly
6   FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB_STATIC" CUSTOM_EXTERNLIB)
7   if (USE_OPENGL)
8     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGles)
9     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGlesTest)
10     list (REMOVE_ITEM CUSTOM_EXTERNLIB CSF_OpenGlesLibs)
11   elseif(USE_GLES2)
12     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGl)
13     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGlTest)
14     list (REMOVE_ITEM CUSTOM_EXTERNLIB CSF_OpenGlLibs)
15   else()
16     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGles)
17     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGlesTest)
18     list (REMOVE_ITEM CUSTOM_EXTERNLIB CSF_OpenGlesLibs)
19     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGl)
20     list (REMOVE_ITEM CUSTOM_EXTERNLIB TKOpenGlTest)
21     list (REMOVE_ITEM CUSTOM_EXTERNLIB CSF_OpenGlLibs)
22   endif()
23 endif()
24
25 set (EXECUTABLE_PROJECT ON)
26 OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit)
27 unset (EXECUTABLE_PROJECT)
28 unset (CUSTOM_EXTERNLIB)
29
30 if (EMSCRIPTEN)
31   # Look for Tcl version string from file tcl.h
32   set (TCL_MAJOR_VERSION  8)
33   set (TCL_MINOR_VERSION  0)
34   set (TCL_RELEASE_SERIAL 0)
35   set (TCL_VERSION_FILE "${3RDPARTY_TCL_INCLUDE_DIR}/tcl.h")
36   if (EXISTS "${TCL_VERSION_FILE}")
37     file(READ "${TCL_VERSION_FILE}" aTclHeader)
38     foreach (SOUGHT_VERSION TCL_MAJOR_VERSION TCL_MINOR_VERSION TCL_RELEASE_SERIAL)
39       string(REGEX MATCH "#define ${SOUGHT_VERSION} * [0-9]+" macrodef "${aTclHeader}")
40       string(REGEX MATCH "[0-9]+" ${SOUGHT_VERSION} "${macrodef}")
41     endforeach()
42   endif()
43   #message(STATUS "Tcl version: ${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}.${TCL_RELEASE_SERIAL}")
44
45   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s WASM=1")
46   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s MAX_WEBGL_VERSION=2")
47   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1")
48   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --bind")
49
50   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s MODULARIZE=1")
51   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORT_NAME='createDRAWEXE'")
52
53   # Embed Draw Harness .tcl scripts at recognizable location.
54   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/../DrawResources@/DrawResources")
55   # Tcl will look for "init.tcl" at path "$tcl_library/init.tcl" on startup (configurable from environment variable TCL_LIBRARY)
56   # In case of WebAssembly build $tcl_library looks like "tcl8.6.11/library" by default.
57   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ${3RDPARTY_TCL_LIBRARY_DIR}/tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}@/tcl${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}.${TCL_RELEASE_SERIAL}/library")
58
59   install(FILES ${PROJECT_NAME}.html      DESTINATION "${INSTALL_DIR_BIN}/${OCCT_INSTALL_BIN_LETTER}")
60   install(FILES ../DrawResources/lamp.ico DESTINATION "${INSTALL_DIR_BIN}/${OCCT_INSTALL_BIN_LETTER}")
61   install(FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.data DESTINATION "${INSTALL_DIR_BIN}/${OCCT_INSTALL_BIN_LETTER}")
62 endif()