############################################################################################
# KWWidgets version
############################################################################################
#NeuroLib_USE_ITK()

FIND_PACKAGE(ITK REQUIRED)
IF (NOT ITK_FOUND)
  MESSAGE (FATAL_ERROR "Need ITK to build")
ENDIF (NOT ITK_FOUND)
INCLUDE(${ITK_USE_FILE})

FIND_PACKAGE(KWWidgets)
IF (KWWidgets_FOUND)
  INCLUDE(${KWWidgets_USE_FILE})

  SET(LIB_NAME "vtkKWMeshVisuLib")
  SET(LIB_SRCS "vtkKWMeshVisu.cxx")
  SET(LIB_EXTRA_SRCS "itkMeshTovtkPolyData.cxx" "KWMeshVisuAttributeIO.cxx")

	
  INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
  INCLUDE("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
  IF("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" EQUAL "5.0") # VTK 5.0 compat
    SET(VTK_WRAP_TCL3_INIT_DIR "${VTK_SOURCE_DIR}/Wrapping")
  ENDIF("${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" EQUAL "5.0")
  VTK_WRAP_TCL3(${LIB_NAME} LIB_TCL_SRCS ${LIB_SRCS} "")

  # Create the library (in static mode for convenience).

  ADD_LIBRARY(${LIB_NAME} STATIC ${LIB_TCL_SRCS} ${LIB_SRCS} ${LIB_EXTRA_SRCS})

  # The name of our executable and the corresponding source file.

  SET(EXE_NAME "KWMeshVisu")
  SET(EXE_SRCS "${EXE_NAME}.cxx")

  # Create the executable, and link it against the KWWidgets libraries and our
  # own library.

  ADD_EXECUTABLE(${EXE_NAME} WIN32 ${EXE_SRCS})
  TARGET_LINK_LIBRARIES(${EXE_NAME} ${KWWidgets_LIBRARIES} ${ITK_LIBRARIES} ${LIB_NAME})

# If we are building this example as a standalone external project:
# - Generate a few small scripts (.bat, .sh, .csh) that can be sourced to set
# the various environments variables (PATH, TCLLIBPATH, LD_LIBRARY_PATH, etc.) 
# required by this executable and its known third-party dependencies (VTK, ITK,
# SOV, KWWidgets, etc.).
# - Generate a lightweight C launcher for this *specific* executable: It sets
# the above environment variables before launching the executable itself.

IF(NOT KWWidgets_SOURCE_DIR)
  INCLUDE("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
  KWWidgets_GENERATE_SETUP_PATHS_SCRIPTS("${CMAKE_CURRENT_BINARY_DIR}")
  SET(LAUNCHER_EXE_NAME "${EXE_NAME}Launcher")
  KWWidgets_GENERATE_SETUP_PATHS_LAUNCHER(
    "${CMAKE_CURRENT_BINARY_DIR}" "${LAUNCHER_EXE_NAME}" "" "${EXE_NAME}")
ENDIF(NOT KWWidgets_SOURCE_DIR)

# If needed, copy the Tcl/Tk support files required at run-time 
# to initialize Tcl/Tk. This is only triggered if VTK was built
# against a Tcl/Tk static library.

INCLUDE("${KWWidgets_CMAKE_DIR}/KWWidgetsTclTkMacros.cmake")
IF(NOT KWWidgets_SOURCE_DIR)
  KWWidgets_COPY_TCL_TK_SUPPORT_FILES("${PROJECT_BINARY_DIR}/lib")
ENDIF(NOT KWWidgets_SOURCE_DIR)

ENDIF (KWWidgets_FOUND)

