1# Make sure we find the required Tcl components.
2if(VTK_WRAP_TCL)
3  set(VTK_WRAP_TCL_FIND_LIBS 1)
4  include(vtkWrapTcl)
5  include(vtkWrapHierarchy)
6endif()
7
8function(vtk_add_tcl_wrapping module_name module_srcs module_hdrs)
9  if(NOT VTK_WRAP_TCL_INIT_EXE)
10    if (TARGET vtkWrapTclInit)
11      set(VTK_WRAP_TCL_INIT_EXE vtkWrapTclInit)
12    else()
13      message(FATAL_ERROR
14        "VTK_WRAP_TCL_INIT_EXE must be set before calling vtk_add_tcl_wrapping.")
15    endif()
16  endif()
17  # Need to add the Wrapping directory to the include directory
18  set(_tcl_include_dirs
19    ${VTK_SOURCE_DIR}/Wrapping/Tcl
20    ${VTK_BINARY_DIR}/Wrapping/Tcl
21    ${TCL_INCLUDE_PATH})
22
23  if(NOT CMAKE_HAS_TARGET_INCLUDES)
24    include_directories(${_tcl_include_dirs})
25  endif()
26
27  # FIXME: These must be here for now, should be fixed in the wrap hierarchy stuff
28  if(NOT ${module_name}_EXCLUDE_FROM_WRAP_HIERARCHY)
29    set(KIT_HIERARCHY_FILE ${${module_name}_WRAP_HIERARCHY_FILE})
30  endif()
31
32  string(REGEX REPLACE "^vtk" "" kit_name "${module_name}")
33  set(KIT ${kit_name})
34
35# FIXME: Terrible temporary hack - add in the extra source file for CommonCore
36  if(${module_name} STREQUAL "vtkCommonCore")
37     set(extra_srcs ${VTK_SOURCE_DIR}/Wrapping/Tcl/vtkTclUtil.cxx)
38     set(extra_links vtksys)
39  else()
40    unset(extra_srcs)
41    # This contains the vtkTclUtil class....
42    set(extra_links vtkCommonCoreTCL)
43  endif()
44
45  # Figure out the dependent Tcl libraries for the module
46  foreach(dep ${${vtk-module}_LINK_DEPENDS})
47    if(NOT "${vtk-module}" STREQUAL "${dep}")
48      if(NOT ${dep}_EXCLUDE_FROM_WRAPPING AND NOT "${${dep}_TCL_NAME}" STREQUAL "")
49        list(APPEND extra_links ${${dep}_TCL_NAME}TCL)
50      endif()
51    endif()
52  endforeach()
53
54  # Tcl will not accept module names with numbers in.
55  set(tcl_module ${${module_name}_TCL_NAME})
56  vtk_wrap_tcl3(${tcl_module}TCL Tcl_SRCS "${module_srcs}" "")
57  vtk_add_library(${tcl_module}TCL ${Tcl_SRCS} ${extra_srcs})
58  if(CMAKE_HAS_TARGET_INCLUDES)
59    set_property(TARGET ${tcl_module}TCL APPEND
60      PROPERTY INCLUDE_DIRECTORIES ${_tcl_include_dirs})
61  endif()
62  if(${module_name}_IMPLEMENTS)
63    set_property(TARGET ${tcl_module}TCL PROPERTY COMPILE_DEFINITIONS
64      "${module_name}_AUTOINIT=1(${module_name})")
65  endif()
66  target_link_libraries(${tcl_module}TCL LINK_PUBLIC ${module_name}
67    ${extra_links} ${VTK_TCL_LIBRARIES})
68endfunction()
69