# bindings/d/CMakeLists.txt
### Process this file with cmake to produce Makefile
###
# Copyright (C) 2008 Werner Smekal
#
# This file is part of PLplot.
#
# PLplot is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License as published
# by the Free Software Foundation; version 2 of the License.
#
# PLplot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with PLplot; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

if(ENABLE_d)
  set(d_interface_INSTALLED_HEADERS plplot.d )

  install(FILES ${d_interface_INSTALLED_HEADERS}
    DESTINATION ${INCLUDE_DIR}
  )

  # Build d bindings
  set(plplotdmd_LIB_SRCS
    plplot.d
  )

  if(plplotdmd_SHARED)
    add_library(plplotdmd ${plplotdmd_LIB_SRCS})

    if(BUILD_SHARED_LIBS)
      set_source_files_properties(${plplotdmd_LIB_SRCS}
	PROPERTIES COMPILE_FLAGS "-DUSINGDLL" )
    endif(BUILD_SHARED_LIBS)

    target_link_libraries(plplotdmd plplot)

    if(USE_RPATH)
      get_target_property(LIB_INSTALL_RPATH plplot INSTALL_RPATH)
      set_target_properties(plplotdmd
	PROPERTIES
	SOVERSION ${plplotdmd_SOVERSION}
	VERSION ${plplotdmd_VERSION}
	INSTALL_RPATH "${LIB_INSTALL_RPATH}"
	INSTALL_NAME_DIR "${LIB_DIR}"
	)
    else(USE_RPATH)
      set_target_properties(plplotdmd
	PROPERTIES
	SOVERSION ${plplotdmd_SOVERSION}
	VERSION ${plplotdmd_VERSION}
	INSTALL_NAME_DIR "${LIB_DIR}"
	)
    endif(USE_RPATH)
  else(plplotdmd_SHARED)
    add_library(plplotdmd STATIC ${plplotdmd_LIB_SRCS})
    target_link_libraries(plplotdmd plplot)
  endif(plplotdmd_SHARED)

  if(NON_TRANSITIVE)
    # empty list ==> non-transitive linking for everything that links to
    # libplplotdmdd in the shared libraries case.
    target_link_libraries(plplotdmd LINK_INTERFACE_LIBRARIES)
  endif(NON_TRANSITIVE)

  install(TARGETS plplotdmd
    EXPORT export_plplot
    ARCHIVE DESTINATION ${LIB_DIR}
    LIBRARY DESTINATION ${LIB_DIR}
    RUNTIME DESTINATION ${BIN_DIR}
  )

  # Configure pkg-config *.pc file corresponding to libplplotdmd
  pkg_config_file("d" "D" " D binding" "plplotdmd" "" "")
endif(ENABLE_d)
