PROJECT(VTK_LOADED_COMMANDS)

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
INCLUDE_DIRECTORIES(${CMAKE_ROOT}/include ${CMAKE_ROOT}/Source)
ADD_LIBRARY(cmVTK_WRAP_TCL2 MODULE cmVTKWrapTcl2Command.c)
ADD_LIBRARY(cmVTK_WRAP_PYTHON2 MODULE cmVTKWrapPython2Command.c)
ADD_LIBRARY(cmVTK_WRAP_JAVA2 MODULE cmVTKWrapJava2Command.c)
ADD_LIBRARY(cmVTK_MAKE_INSTANTIATOR2 MODULE cmVTKMakeInstantiator2Command.c)
ADD_LIBRARY(cmVTK_GENERATE_JAVA_DEPENDENCIES MODULE cmVTKGenerateJavaDependencies.c)

# Make sure we build with flags matching the CMake executable.
IF(CMAKE_SYSTEM MATCHES "IRIX64")
  # A table of ABI flags.
  IF(CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_ABI_32 "-mabi=32")
    SET(CMAKE_ABI_n32 "-mabi=n32")
    SET(CMAKE_ABI_64 "-mabi=64")
  ELSE(CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_ABI_32 "-o32")
    SET(CMAKE_ABI_n32 "-n32")
    SET(CMAKE_ABI_64 "-64")
  ENDIF(CMAKE_COMPILER_IS_GNUCXX)  
  
  # Check how cmake was built.
  IF(CMAKE_FILE_SELF MATCHES "^CMAKE_FILE_SELF$")
    EXEC_PROGRAM(file ARGS ${CMAKE_COMMAND} OUTPUT_VARIABLE CMAKE_FILE_SELF)
    SET(CMAKE_FILE_SELF "${CMAKE_FILE_SELF}" CACHE INTERNAL
      "Output of file command on ${CMAKE_COMMAND}.")
  ENDIF(CMAKE_FILE_SELF MATCHES "^CMAKE_FILE_SELF$")
  
  # Remove any existing flag.
  SET(CMAKE_ABI_VARS
    CMAKE_C_FLAGS
    CMAKE_CXX_FLAGS
    CMAKE_EXE_LINKER_FLAGS
    CMAKE_SHARED_LINKER_FLAGS
    CMAKE_MODULE_LINKER_FLAGS
    )
  FOREACH(var ${CMAKE_ABI_VARS})
    FOREACH(regex "-([on]32|64)" "-mabi=[a-z0-9]*")
      STRING(REGEX REPLACE "${regex}" "" ${var} "${${var}}")
    ENDFOREACH(regex)
  ENDFOREACH(var)
  
  # Add the proper flag.
  IF(CMAKE_FILE_SELF MATCHES " 32-bit ")
    SET(CMAKE_ABI_FLAG "${CMAKE_ABI_32}")
  ENDIF(CMAKE_FILE_SELF MATCHES " 32-bit ")
  IF(CMAKE_FILE_SELF MATCHES " N32 ")
    SET(CMAKE_ABI_FLAG "${CMAKE_ABI_n32}")
  ENDIF(CMAKE_FILE_SELF MATCHES " N32 ")
  IF(CMAKE_FILE_SELF MATCHES " 64-bit ")
    SET(CMAKE_ABI_FLAG "${CMAKE_ABI_64}")
  ENDIF(CMAKE_FILE_SELF MATCHES " 64-bit ")

  FOREACH(var ${CMAKE_ABI_VARS})
    SET(${var} "${CMAKE_ABI_FLAG} ${${var}}")
  ENDFOREACH(var)
ENDIF(CMAKE_SYSTEM MATCHES "IRIX64")
