# -*- mode: cmake -*-
# This file used to configure CMake variables that are used to build the
# installed examples.
# Identify that this is the build system for the installed examples.
set(BUILD_TEST ON)
set(CORE_BUILD OFF)

# =======================================================================
# pkg-config support as well as macros to put link flags in standard
# *.pc (pkg-config) form as well as standard fullpath form used by cmake.
# PKG_CONFIG_EXECUTABLE can be used to discover whether pkg-config was
# found or not.
# =======================================================================
include(pkg-config)

set(LIB_TAG "@LIB_TAG@")
set(INCLUDE_DIR @INCLUDE_DIR@)
set(MATH_LIB @MATH_LIB@)

# language_info_LIST contains information about the languages used
# in the noninteractive tests.
# First field is language (which must be consistent with following
# configured set commands).
# Second field is suffix on plplot-test.sh results for that language.

set(language_info_LIST
  ada:a
  c:c
  cxx:cxx
  d:d
  f77:f
  f95:f95
  java:j
  lua:lua
  ocaml:ocaml
  octave:o
  pdl:pdl
  python:p
  tcl:t
  )

# This list of set commands must be consistent with the above list which
# potentially is a maintenance issue.  However, cannot make this list
# automatically with a foreach loop because explicit configuration of
# each name is required.
set(CORE_ENABLE_ada @ENABLE_ada@)
# N.B. The core never sets ENABLE_c since C is always on for the core.
set(CORE_ENABLE_c ON)
set(CORE_ENABLE_cxx @ENABLE_cxx@)
set(CORE_ENABLE_d @ENABLE_d@)
set(CORE_ENABLE_f77 @ENABLE_f77@)
set(CORE_ENABLE_f95 @ENABLE_f95@)
set(CORE_ENABLE_java @ENABLE_java@)
set(CORE_ENABLE_lua @ENABLE_lua@)
set(CORE_ENABLE_ocaml @ENABLE_ocaml@)
set(CORE_ENABLE_octave @ENABLE_octave@)
set(CORE_ENABLE_pdl @ENABLE_pdl@)
set(CORE_ENABLE_python @ENABLE_python@)
set(CORE_ENABLE_tcl @ENABLE_tcl@)

# Interactive bindings
set(CORE_ENABLE_tk @ENABLE_tk@)
set(CORE_ENABLE_gnome2 @ENABLE_gnome2@)
set(CORE_ENABLE_wxwidgets @ENABLE_wxwidgets@)
set(CORE_ENABLE_qt @ENABLE_qt@)

# What computer languages do we have configured by the core build system?
option(DEFAULT_NO_BINDINGS
  "All language bindings are disabled by default"
  OFF
  )

if(DEFAULT_NO_BINDINGS)
  set(PRESET_DEFAULT ON)
  set(DEFAULT OFF)
else(DEFAULT_NO_BINDINGS)
  set(PRESET_DEFAULT OFF)
endif(DEFAULT_NO_BINDINGS)

# Add interactive bindings to list for option processing
foreach(language_info tk:? gnome2:? wxwidgets:? qt:? ${language_info_LIST})
  string(REGEX REPLACE "^(.*):.*$" "\\1" language ${language_info})
  #message("DEBUG: language = ${language}")
  if(language STREQUAL "c")
    #special case where the build system requires C.
    set(ENABLE_${language} ON CACHE BOOL "Enable ${language} bindings" FORCE)
  else(language STREQUAL "c")
    if(CORE_ENABLE_${language})
      if(NOT PRESET_DEFAULT)
	set(DEFAULT ${CORE_ENABLE_${language}})
      endif(NOT PRESET_DEFAULT)
      option(ENABLE_${language} "Enable ${language} bindings" ${DEFAULT})
    else(CORE_ENABLE_${language})
      set(ENABLE_${language} OFF CACHE BOOL "Enable ${language} bindings" FORCE)
    endif(CORE_ENABLE_${language})
  endif(language STREQUAL "c")
endforeach(language_info ${language_info_LIST})

# Always carry out C checks because build system requires a C compiler
# for some of the automatic checking that is done.
set(alwaysc ON)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(alwaysc OR ENABLE_c)
  include(CMakeDetermineCCompiler)
  if(NOT CMAKE_C_COMPILER)
    # This is a FATAL_ERROR rather than STATUS message because C compiler
    # absolutely required for some of the automatic checking that is done.
    message(FATAL_ERROR "C compiler absolutely required to build this project.")
    message(STATUS "WARNING: C compiler not found so disabling C examples.")
    set(ENABLE_c OFF CACHE BOOL "Enable c bindings" FORCE)
  endif(NOT CMAKE_C_COMPILER)
endif(alwaysc OR ENABLE_c)

if(alwaysc OR ENABLE_c)
  enable_language(C OPTIONAL)
  if(NOT CMAKE_C_COMPILER_WORKS)
    # This is a FATAL_ERROR rather than STATUS message because C compiler
    # absolutely required for some of the automatic checking that is done.
    message(FATAL_ERROR "C compiler absolutely required to build this project.")
    message(STATUS "WARNING: C compiler does not work so disabling C examples.")
    set(ENABLE_c OFF CACHE BOOL "Enable c bindings" FORCE)
  endif(NOT CMAKE_C_COMPILER_WORKS)
endif(alwaysc OR ENABLE_c)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(ENABLE_ada)
  include(CMakeDetermineAdaCompiler)
  if(NOT CMAKE_Ada_COMPILER)
    message(STATUS "WARNING: Ada compiler not found so disabling Ada examples.")
    set(ENABLE_ada OFF CACHE BOOL "Enable ada bindings" FORCE)
  endif(NOT CMAKE_Ada_COMPILER)
endif(ENABLE_ada)

if(ENABLE_ada)
  enable_language(Ada OPTIONAL)
  if(NOT CMAKE_Ada_COMPILER_WORKS)
    message(STATUS "WARNING: Ada compiler does not work so disabling Ada examples.")
    set(ENABLE_ada OFF CACHE BOOL "Enable ada bindings" FORCE)
  endif(NOT CMAKE_Ada_COMPILER_WORKS)
endif(ENABLE_ada)

if(ENABLE_ada)
  set(ADA_INCLUDE_DIR @ADA_INCLUDE_DIR@)
  set(ADA_LIB_DIR @ADA_LIB_DIR@)
endif(ENABLE_ada)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(ENABLE_cxx)
  include(CMakeDetermineCXXCompiler)
  if(NOT CMAKE_CXX_COMPILER)
    message(STATUS "WARNING: C++ compiler not found so disabling C++ examples.")
    set(ENABLE_cxx OFF CACHE BOOL "Enable cxx bindings" FORCE)
  endif(NOT CMAKE_CXX_COMPILER)
endif(ENABLE_cxx)

if(ENABLE_cxx)
  enable_language(CXX OPTIONAL)
  if(NOT CMAKE_CXX_COMPILER_WORKS)
    message(STATUS "WARNING: C++ compiler does not work so disabling C++ examples.")
    set(ENABLE_cxx OFF CACHE BOOL "Enable cxx bindings" FORCE)
  endif(NOT CMAKE_CXX_COMPILER_WORKS)
endif(ENABLE_cxx)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(ENABLE_d)
  include(CMakeDetermineDCompiler)
  if(NOT CMAKE_D_COMPILER)
    message(STATUS "WARNING: D compiler not found so disabling D examples.")
    set(ENABLE_d OFF CACHE BOOL "Enable d bindings" FORCE)
  endif(NOT CMAKE_D_COMPILER)
endif(ENABLE_d)

if(ENABLE_d)
  enable_language(D OPTIONAL)
  if(NOT CMAKE_D_COMPILER_WORKS)
    message(STATUS "WARNING: D compiler does not work so disabling D examples.")
    set(ENABLE_d OFF CACHE BOOL "Enable d bindings" FORCE)
  endif(NOT CMAKE_D_COMPILER_WORKS)
endif(ENABLE_d)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(ENABLE_f77 OR ENABLE_f95)
  include(CMakeDetermineFortranCompiler)
  if(NOT CMAKE_Fortran_COMPILER)
    message(STATUS "WARNING: Fortran compiler not found so disabling Fortran examples.")
    set(ENABLE_f77 OFF CACHE BOOL "Enable f77 bindings" FORCE)
    set(ENABLE_f95 OFF CACHE BOOL "Enable f95 bindings" FORCE)
  endif(NOT CMAKE_Fortran_COMPILER)
endif(ENABLE_f77 OR ENABLE_f95)

if(ENABLE_f77 OR ENABLE_f95)
  enable_language(Fortran OPTIONAL)
  if(NOT CMAKE_Fortran_COMPILER_WORKS)
    message(STATUS "WARNING: Fortran compiler does not work so disabling Fortran examples.")
    set(ENABLE_f77 OFF CACHE BOOL "Enable f77 bindings" FORCE)
    set(ENABLE_f95 OFF CACHE BOOL "Enable f95 bindings" FORCE)
  endif(NOT CMAKE_Fortran_COMPILER_WORKS)
endif(ENABLE_f77 OR ENABLE_f95)

if(ENABLE_f77 OR ENABLE_f95)
  set(STATIC_OPTS @STATIC_OPTS@)
endif(ENABLE_f77 OR ENABLE_f95)

if(ENABLE_f95)
  set(F95_MOD_DIR @F95_MOD_DIR@)
endif(ENABLE_f95)

# OPTIONAL below currently does not work properly with CMake so attempt
# to deal with a possibly missing compiler first as a workaround.
if(ENABLE_java)
  include(CMakeDetermineJavaCompiler)
  if(NOT CMAKE_Java_COMPILER)
    message(STATUS "WARNING: Java compiler not found so disabling Java examples.")
    set(ENABLE_java OFF CACHE BOOL "Enable java bindings" FORCE)
  endif(NOT CMAKE_Java_COMPILER)
endif(ENABLE_java)

if(ENABLE_java)
  enable_language(Java OPTIONAL)
  if(NOT CMAKE_Java_COMPILER_WORKS)
    message(STATUS "WARNING: Java compiler does not work so disabling Java examples.")
    set(ENABLE_java OFF CACHE BOOL "Enable java bindings" FORCE)
  endif(NOT CMAKE_Java_COMPILER_WORKS)
endif(ENABLE_java)

if(ENABLE_java)
  find_package(JNI)
  set(JAR_DIR @JAR_DIR@)
endif(ENABLE_java)

if(ENABLE_ocaml)
  set(OCAMLC @OCAMLC@)
  set(CMAKE_INSTALL_LIBDIR @CMAKE_INSTALL_LIBDIR@)
  set(OCAML_INSTALL_DIR @OCAML_INSTALL_DIR@)
endif(ENABLE_ocaml)

if(ENABLE_python)
  set(ENABLE_pygcw @ENABLE_pygcw@)
endif(ENABLE_python)

if(ENABLE_tcl OR ENABLE_tk)
  set(TCL_TCLSH @TCL_TCLSH@)
  set(MKTCLINDEX @MKTCLINDEX@)
  set(MKTCLINDEX_ARGS @MKTCLINDEX_ARGS@)
endif(ENABLE_tcl OR ENABLE_tk)

if(ENABLE_tk)
  set(ENABLE_itk @ENABLE_itk@)
  set(TCL_INCLUDE_PATH @TCL_INCLUDE_PATH@)
  set(TK_INCLUDE_PATH @TK_INCLUDE_PATH@)
endif(ENABLE_tk)

if(ENABLE_wxwidgets)
  # Use identical compile and link flags to build wxwidgets application.
  set(wxwidgets_COMPILE_FLAGS "@wxwidgets_COMPILE_FLAGS@")
  set(wxwidgets_LINK_FLAGS @wxwidgets_LINK_FLAGS@)
endif(ENABLE_wxwidgets)

if(ENABLE_qt)
  set(CORE_QT_VERSION_MAJOR @QT_VERSION_MAJOR@)
  set(CORE_QT_VERSION_MINOR @QT_VERSION_MINOR@)
  set(CORE_QT_VERSION_PATCH @QT_VERSION_PATCH@)
endif(ENABLE_qt)

# List of all devices that will be used for noninteractive device tests.
# Exclude some devices (linuxvga, conex?) in plplot-test.sh
# where it is likely they are interactive.
# The first field is the device, the second field is whether it produces
# familied output (to help keep track of file dependencies).  That field must
# be consistent with the shell logic which deploys the -fam option for
# certain devices in plplot-test.sh.cmake.
# N.B. That field has nothing to do with whether the device is turned ON
# or not.
set(noninteractive_devices_info_LIST
  pdfcairo:OFF
  pngcairo:ON
  pscairo:OFF
  svgcairo:ON
  cgm:OFF
  dg300:OFF
  epsqt:ON
  pdfqt:ON
  bmpqt:ON
  jpgqt:ON
  pngqt:ON
  ppmqt:ON
  tiffqt:ON
  svgqt:ON
  gif:ON
  jpeg:ON
  png:ON
  # All hp7xxx devices are semi-broken (Invalid pen selection warnings)
  #  hp7470:OFF
  #  hp7580:OFF
  # lj_hpgl is severely broken (segfaults).
  #  lj_hpgl:OFF
  imp:OFF
  ljii:OFF
  ljiip:OFF
  # pbm is severely broken (glibc double free detected)
  #  pbm:OFF
  pdf:OFF
  # Include ps in list because we want to test monochromatic results, but
  # exclude psc because that already done with noninteractive language tests.
  ps:OFF
  #  psc:OFF
  pstex:OFF
  psttf:OFF
  psttfc:OFF
  svg:ON
  tek4010f:OFF
  tek4107f:OFF
  wxpng:OFF
  xfig:ON
  )

# This list of set commands must be consistent with the above list which
# potentially is a maintenance issue.  However, cannot make this list
# automatically with a foreach loop because explicit configuration of
# each name is required.
set(CORE_PLD_pdfcairo @PLD_pdfcairo@)
set(CORE_PLD_pngcairo @PLD_pngcairo@)
set(CORE_PLD_pscairo @PLD_pscairo@)
set(CORE_PLD_svgcairo @PLD_svgcairo@)
set(CORE_PLD_cgm @PLD_cgm@)
set(CORE_PLD_dg300 @PLD_dg300@)
set(CORE_PLD_epsqt @PLD_epsqt@)
set(CORE_PLD_pdfqt @PLD_pdfqt@)
set(CORE_PLD_bmpqt @PLD_bmpqt@)
set(CORE_PLD_jpgqt @PLD_jpgqt@)
set(CORE_PLD_pngqt @PLD_pngqt@)
set(CORE_PLD_ppmqt @PLD_ppmqt@)
set(CORE_PLD_tiffqt @PLD_tiffqt@)
set(CORE_PLD_svgqt @PLD_svgqt@)
set(CORE_PLD_gif @PLD_gif@)
set(CORE_PLD_jpeg @PLD_jpeg@)
set(CORE_PLD_png @PLD_png@)
set(CORE_PLD_hp7470 @PLD_hp7470@)
set(CORE_PLD_hp7580 @PLD_hp7580@)
set(CORE_PLD_lj_hpgl @PLD_lj_hpgl@)
set(CORE_PLD_imp @PLD_imp@)
set(CORE_PLD_ljii @PLD_ljii@)
set(CORE_PLD_ljiip @PLD_ljiip@)
set(CORE_PLD_pbm @PLD_pbm@)
set(CORE_PLD_pdf @PLD_pdf@)
set(CORE_PLD_ps @PLD_ps@)
set(CORE_PLD_pstex @PLD_pstex@)
set(CORE_PLD_psttf @PLD_psttf@)
set(CORE_PLD_svg @PLD_svg@)
set(CORE_PLD_tek4010f @PLD_tek4010f@)
set(CORE_PLD_tek4107f @PLD_tek4107f@)
set(CORE_PLD_wxpng @PLD_wxpng@)
set(CORE_PLD_xfig @PLD_xfig@)

# Special case where core configures both ps and psc with PLD_ps.
set(CORE_PLD_psc @PLD_ps@)
# Special case where core configures both psttf and psttfc with PLD_psttf.
set(CORE_PLD_psttfc @PLD_psttf@)

# Set interactive/external devices that are needed to build certain examples.
set(CORE_PLD_xcairo @PLD_xcairo@)
set(CORE_PLD_extcairo @PLD_extcairo@)

option(DEFAULT_NO_DEVICES
  "Disable all (ON) or enable individually (OFF) devices by default"
  OFF
  )

if(DEFAULT_NO_DEVICES)
  set(PRESET_DEFAULT ON)
  set(DEFAULT OFF)
else(DEFAULT_NO_DEVICES)
  set(PRESET_DEFAULT OFF)
endif(DEFAULT_NO_DEVICES)

# Generate psc, xcairo, and extcairo options in addition to everything on
# noninteractive_devices_info_LIST

foreach(noninteractive_devices_info psc:? xcairo:? extcairo:? ${noninteractive_devices_info_LIST})
  string(REGEX REPLACE "^(.*):.*$" "\\1" DEVICE ${noninteractive_devices_info})
  #message("DEBUG: DEVICE = ${DEVICE}")
  if(CORE_PLD_${DEVICE})
    if(NOT PRESET_DEFAULT)
      set(DEFAULT ${CORE_PLD_${DEVICE}})
    endif(NOT PRESET_DEFAULT)
    option(PLD_${DEVICE} "Enable ${DEVICE} device" ${DEFAULT})
  else(CORE_PLD_${DEVICE})
    set(PLD_${DEVICE} OFF CACHE BOOL "Enable ${device} device" FORCE)
  endif(CORE_PLD_${DEVICE})

endforeach(noninteractive_devices_info psc:OFF xcairo:OFF extcairo:OFF ${noninteractive_devices_info_LIST})
