###############################################################################
# Description       : CMake build script for libSBML language bindings
# Original author(s): Frank Bergmann <fbergman@caltech.edu>
# Organization      : California Institute of Technology
#
# This file is part of libSBML.  Please visit http://sbml.org for more
# information about SBML, and the latest version of libSBML.
#
# Copyright (C) 2013-2018 jointly by the following organizations:
#     1. California Institute of Technology, Pasadena, CA, USA
#     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
#     3. University of Heidelberg, Heidelberg, Germany
#
# Copyright (C) 2009-2013 jointly by the following organizations: 
#     1. California Institute of Technology, Pasadena, CA, USA
#     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
#  
# Copyright (C) 2006-2008 by the California Institute of Technology,
#     Pasadena, CA, USA 
#  
# Copyright (C) 2002-2005 jointly by the following organizations: 
#     1. California Institute of Technology, Pasadena, CA, USA
#     2. Japan Science and Technology Agency, Japan
# 
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation.  A copy of the license agreement is provided
# in the file named "LICENSE.txt" included with this software distribution
# and also available online as http://sbml.org/software/libsbml/license.html
#
###############################################################################

function(update_ifile fileName binDir files)
#message ("Generating ${fileName} for ${files}")
file(WRITE "${binDir}/${fileName}" "// This file is autogenerated and will be overwritten by the configuration process\n\n")
foreach(package ${files})
	file(APPEND "${binDir}/${fileName}" "%include \"${package}\"\n")
endforeach()
file(APPEND "${binDir}/${fileName}" "\n")


endfunction(update_ifile)

function(update_cfile fileName binDir files)

file(WRITE "${binDir}/${fileName}" "// This file is autogenerated and will be overwritten by the configuration process\n\n")
foreach(package ${files})
	file(APPEND "${binDir}/${fileName}" "#include \"${package}\"\n")
endforeach()
file(APPEND "${binDir}/${fileName}" "\n")

endfunction(update_cfile)

#
# update files in swig directory
#
# - libsbml-packages.i
file(GLOB LIBSBML_PACKAGES_I RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/swig "${CMAKE_CURRENT_SOURCE_DIR}/swig/*-package.i")
update_ifile(
   "libsbml-packages.i" 
   ${CMAKE_CURRENT_BINARY_DIR}/swig 
   "${LIBSBML_PACKAGES_I}"
)

#
# - libsbml-packages.h
#
file(GLOB LIBSBML_PACKAGES_I RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/swig "${CMAKE_CURRENT_SOURCE_DIR}/swig/*-package.h")
update_cfile(
   "libsbml-packages.h" 
   ${CMAKE_CURRENT_BINARY_DIR}/swig 
   "${LIBSBML_PACKAGES_I}"
)

#
# When checked removes all generated SWIG wrappers upon configure
#
option(LIBSBML_REMOVE_WRAPPERS
"Remove existing wrapper files generated by SWIG prior to 
recreating them, when building libSBML." OFF)
mark_as_advanced(LIBSBML_REMOVE_WRAPPERS)

#
# and build selected language bindings
#

if(WITH_CSHARP)
add_subdirectory(csharp)
endif()

if(WITH_JAVA)
add_subdirectory(java)
endif()

if(WITH_PERL)
add_subdirectory(perl)
endif()

if(WITH_MATLAB)
add_subdirectory(matlab)
endif()

if(WITH_OCTAVE)
add_subdirectory(octave)
endif()

if(WITH_PYTHON)
add_subdirectory(python)
endif()

if(WITH_RUBY)
add_subdirectory(ruby)
endif()

if(WITH_PHP)
add_subdirectory(php)
endif()

if(WITH_R)
add_subdirectory(r)
endif()

if(WITH_JAVASCRIPT)
add_subdirectory(javascript)
endif()

