# Set up options needed for ConfigureWrapping
# Useful Variables:
# The user should set JAVA_OUTPUT_DIR if they want generated Java classes to go
# anywhere other than ${PROJECT_BINARY_DIR}/Java.
# If SWIG needs to include any files in nonstandard locations, the directories
# must be added to with include_directories().

# Be careful setting up the paths to the ITK and gccxml dirs that WrapITK
# already found -- they might not be valid.
set(possible_itk_dir "@ITK_DIR@")
if(EXISTS "${possible_itk_dir}")
set(ITK_DIR "${possible_itk_dir}" CACHE PATH "Path to ITK build or install.")
endif()

set(possible_gccxml "@GCCXML@")
if(EXISTS "${possible_gccxml}")
set(GCCXML "${possible_gccxml}"  CACHE FILEPATH "Path to gccxml.")
endif()

set(possible_swig_dir "@SWIG_DIR@")
if(EXISTS "${possible_swig_dir}")
set(SWIG_DIR "${possible_swig_dir}"  CACHE PATH "Path to Swig build or install")
endif()

# Set up the rest of the variables that WrapITK was built with.
set(ITK_WRAP_unsigned_char @ITK_WRAP_unsigned_char@ CACHE BOOL "Wrap unsigned char type")
set(ITK_WRAP_unsigned_short @ITK_WRAP_unsigned_short@ CACHE BOOL "Wrap unsigned short type")
set(ITK_WRAP_unsigned_long @ITK_WRAP_unsigned_long@ CACHE BOOL "Wrap unsigned long type")
set(ITK_WRAP_unsigned_long_long @ITK_WRAP_unsigned_long_long@ CACHE BOOL "Wrap unsigned long long type")
set(ITK_WRAP_signed_char @ITK_WRAP_signed_char@ CACHE BOOL "Wrap signed char type")
set(ITK_WRAP_signed_short @ITK_WRAP_signed_short@ CACHE BOOL "Wrap signed short type")
set(ITK_WRAP_signed_long @ITK_WRAP_signed_long@ CACHE BOOL "Wrap signed long type")
set(ITK_WRAP_signed_long_long @ITK_WRAP_signed_long@ CACHE BOOL "Wrap signed long long type")
set(ITK_WRAP_float @ITK_WRAP_float@ CACHE BOOL "Wrap float type")
set(ITK_WRAP_double @ITK_WRAP_double@ CACHE BOOL "Wrap double type")
set(ITK_WRAP_vector_float @ITK_WRAP_vector_float@ CACHE BOOL "Wrap vector float type")
set(ITK_WRAP_vector_double @ITK_WRAP_vector_double@ CACHE BOOL "Wrap vector double type")
set(ITK_WRAP_covariant_vector_float @ITK_WRAP_covariant_vector_float@ CACHE BOOL "Wrap covariant vector float type")
set(ITK_WRAP_covariant_vector_double @ITK_WRAP_covariant_vector_double@ CACHE BOOL "Wrap covariant vector double type")
set(ITK_WRAP_rgb_unsigned_char @ITK_WRAP_rgb_unsigned_char@ CACHE BOOL "Wrap RGB< unsigned char > type")
set(ITK_WRAP_rgb_unsigned_short @ITK_WRAP_rgb_unsigned_short@ CACHE BOOL "Wrap RGB< unsigned short > type")
set(ITK_WRAP_complex_float @ITK_WRAP_complex_float@ CACHE BOOL "Wrap complex<float> type")
set(ITK_WRAP_complex_double @ITK_WRAP_complex_double@ CACHE BOOL "Wrap complex<double> type")
set(ITK_WRAP_IMAGE_DIMS "@ITK_WRAP_IMAGE_DIMS@" CACHE STRING "dimensions available separated by semicolons (;)")

@CONFIG_WRAP_ITK_MORE_OPTIONS@

foreach(var ITK_DIR GCCXML
    ITK_WRAP_unsigned_char ITK_WRAP_unsigned_short ITK_WRAP_unsigned_long ITK_WRAP_signed_char
    ITK_WRAP_signed_short ITK_WRAP_signed_long ITK_WRAP_float ITK_WRAP_double ITK_WRAP_vector_float
    ITK_WRAP_vector_double ITK_WRAP_covariant_vector_float ITK_WRAP_covariant_vector_double
    ITK_WRAP_rgb_unsigned_char ITK_WRAP_rgb_unsigned_short ITK_WRAP_complex_float ITK_WRAP_complex_double
    ITK_WRAP_rgba_unsigned_char ITK_WRAP_rgba_unsigned_short
    ITK_WRAP_IMAGE_DIMS)
  mark_as_advanced(${var})
endforeach()

set(WRAP_ITK_CONFIG_DIR "@CONFIG_CONFIG_DIR@")
set(WRAP_ITK_CMAKE_DIR "@CONFIG_CMAKE_DIR@")
if("${WrapITK_DIR}" MATCHES "^${CMAKE_INSTALL_PREFIX}")
  string(REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}/*" "" prefix "${WrapITK_DIR}")
  set(WRAP_ITK_INSTALL_PREFIX "${prefix}" CACHE PATH "subpath where where most of WrapITK files will be installed")
else()
  message("Warning: the CMAKE_INSTALL_PREFIX doesn't match the WrapITK one. Your installation may not be usable.")
  set(WRAP_ITK_INSTALL_PREFIX "@WRAP_ITK_INSTALL_PREFIX@" CACHE PATH "subpath where where most of WrapITK files will be installed")
endif()

if(JAVA_OUTPUT_DIR)
  set(ITK_WRAP_JAVA_DIR "${JAVA_OUTPUT_DIR}")
else()
  set(ITK_WRAP_JAVA_DIR "${PROJECT_BINARY_DIR}/Java")
  if(${module_prefix}_WRAP_JAVA)
    file(MAKE_DIRECTORY "${ITK_WRAP_JAVA_DIR}")
  endif()
endif()

set(WRAP_ITK_INSTALL_LOCATION "@CONFIG_WRAP_ITK_INSTALL_LOCATION@")
set(WRAP_ITK_TYPEDEFS_DIRECTORY "@CONFIG_WRAP_ITK_TYPEDEFS_DIRECTORY@")
set(WRAP_ITK_LIB_DIRECTORY "@CONFIG_WRAP_ITK_LIB_DIR@")
set(WRAP_ITK_MODULES "@CONFIG_WRAP_ITK_MODULES@")

# Tell the world that this is an external project using WrapITK:
set(EXTERNAL_WRAP_ITK_PROJECT ON)

# libraries are all in the same dir
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib" CACHE INTERNAL "Single output directory for building all libraries.")

# Now include ConfigureWrapping
include("${WRAP_ITK_CMAKE_DIR}/ConfigureWrapping.cmake")

# include must be there to add the path *after* the local path
include_directories("@CONFIG_WRAP_ITK_TYPEDEFS_DIRECTORY@")

# If WrapITK has been installed, we need to point the linker at the various
# language directories, where libSwigRuntime has been installed.
# Otherwise, we need to point the linker at the bin directory of the build dir.
macro(LINK_IF_EXISTS dir)
  if(EXISTS "${dir}")
    link_directories("${dir}")
  endif()
endmacro()

link_directories("@CONFIG_WRAP_ITK_LIB_DIR@")

find_program(ITK_TEST_DRIVER itkTestDriver)
