diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c1280e08c..55e42152bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,8 +301,7 @@ endif() add_subdirectory(deps) add_subdirectory(src) add_subdirectory(tests) -add_subdirectory(swig) - +add_subdirectory(wrappers) #----------------------------------------------------------------------------- # Produce a pkg-config file diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt new file mode 100644 index 0000000000..60fbe60e74 --- /dev/null +++ b/wrappers/CMakeLists.txt @@ -0,0 +1,32 @@ + +set(SWIG_INCLUDE_DIRS + SYSTEM + ${CMAKE_CURRENT_SOURCE_DIR}/../deps/ + ${CMAKE_CURRENT_SOURCE_DIR}/../include/ + ${CMAKE_CURRENT_SOURCE_DIR}/../include/opentxs + ${CMAKE_CURRENT_SOURCE_DIR}/../include/opentxs/core + ${CMAKE_CURRENT_SOURCE_DIR}/../include/opentxs/ext + ${CMAKE_CURRENT_SOURCE_DIR}/../include/opentxs/api +) + +if(PYTHON) + subdirs(python) +endif(PYTHON) + +if(CSHARP) + subdirs(csharp) +endif(CSHARP) + +if(JAVA) + subdirs(java) +endif(JAVA) + +if(PHP) + subdirs(php) +endif(PHP) + +if(PERL) + #subdirs(perl) + message("Perl module currently breaks the build so is disabled.") + message("See ./wrappers/CMakeLists.txt:28 to manually enable.") +endif(PERL) diff --git a/wrappers/csharp/AssemblyInfo.cs.in b/wrappers/csharp/AssemblyInfo.cs.in new file mode 100644 index 0000000000..f66c5bc34b --- /dev/null +++ b/wrappers/csharp/AssemblyInfo.cs.in @@ -0,0 +1,76 @@ +#region License +/*========================================================================= + + BSD License [http://www.opensource.org/licenses/bsd-license.php] + Copyright (c) 2006-2011 Mathieu Malaterre + All rights reserved. + See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither name of Mathieu Malaterre, or CREATIS, nor the names of any + contributors (CNRS, INSERM, UCB, Universite Lyon I), may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=========================================================================*/ +#endregion License + +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("GDCM Framework Binding For .NET")] +[assembly: AssemblyDescription("GDCM Framework Binding For .NET")] +[assembly: AssemblyConfiguration("Retail")] +[assembly: AssemblyCompany("GDCM -- http://gdcm.sourceforge.net")] +[assembly: AssemblyProduct("gdcm-sharp.dll")] +[assembly: AssemblyDefaultAlias("gdcm-sharp")] +[assembly: AssemblyCopyright("Copyright ©2006-2011 Mathieu Malaterre. All rights reserved.")] +[assembly: AssemblyTrademark("GDCM -- http://gdcm.sourceforge.net")] +[assembly: AssemblyCulture("")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("@GDCM_API_VERSION@")] +[assembly: AssemblyFileVersion("@GDCM_API_VERSION@")] +[assembly: AssemblyInformationalVersion("@GDCM_API_VERSION@")] + +// The following attributes specify the key for the sign of your assembly. See the +// .NET Framework documentation for more information about signing. +// This is not required, if you don't want signing let these attributes like they're. +[assembly: AssemblyDelaySign(false)] +// http://msdn.microsoft.com/en-us/library/6f05ezxy(VS.80).aspx +[assembly: AssemblyKeyFile("key.snk")] +//[assembly: AssemblyKeyFile("")] +//[assembly: AssemblyKeyName("GDCM Key")] +//[assembly: AssemblyKeyName("")] diff --git a/wrappers/csharp/CMakeLists.txt b/wrappers/csharp/CMakeLists.txt new file mode 100644 index 0000000000..7c52e70bc0 --- /dev/null +++ b/wrappers/csharp/CMakeLists.txt @@ -0,0 +1,67 @@ +## Work in progress +## +message("** Csharp Wrapper") + +set(OTX_WRAPPER_NAME "Opentxs") + +set(CMAKE_SWIG_FLAGS "") + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(CSharp REQUIRED) + +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +# place our csharp code in a subdir to keep it clean +set(CSHARP_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/otx_sharp CACHE INTERNAL "") +set(CSHARP_BINARY_DIRECTORY ${CSHARP_SOURCE_DIRECTORY} CACHE INTERNAL "") +file(MAKE_DIRECTORY ${CSHARP_SOURCE_DIRECTORY}) +set(CMAKE_SWIG_OUTDIR ${CSHARP_BINARY_DIRECTORY}) +## + + +# -dllimport = native/glue lib +set(CMAKE_SWIG_FLAGS "-namespace Opentxs -dllimport opentxs-api -outdir ${CMAKE_SWIG_OUTDIR}" ) +separate_arguments(CMAKE_SWIG_FLAGS) + +# so file +set(CMAKE_SWIG_FLAGS -I${CMAKE_SOURCE_DIR}) +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS on) + + +swig_add_module(${OTX_WRAPPER_NAME} csharp OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} opentxs-api) + +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + +# add_library(Opentxs-sharp opentxs-api) +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME ${OTX_WRAPPER_NAME}) + + +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT csharp) + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/AssemblyInfo.cs.in" + "${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs" + @ONLY) + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/key.snk + ${CMAKE_CURRENT_BINARY_DIR}/key.snk + COPYONLY) + +add_custom_command( + OUTPUT "${GDCM_LIBRARY_DIR}/opentxs-sharp.dll" + COMMAND ${CMAKE_CSHARP_COMPILER} ARGS "/t:library" "/out:${GDCM_LIBRARY_DIR}/opentxs-sharp.dll" "*.cs" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS "${swig_generated_file_fullname}" + "${CMAKE_CURRENT_BINARY_DIR}/AssemblyInfo.cs" + COMMENT "csc *.cs" +) diff --git a/wrappers/csharp/OTX_.i b/wrappers/csharp/OTX_.i new file mode 100644 index 0000000000..026f85c2e8 --- /dev/null +++ b/wrappers/csharp/OTX_.i @@ -0,0 +1,3 @@ +%module(directors=1) Opentxs + +%include "../opentxs.i" diff --git a/wrappers/csharp/cmake/CMakeCSharpCompiler.cmake.in b/wrappers/csharp/cmake/CMakeCSharpCompiler.cmake.in new file mode 100644 index 0000000000..ac5200d133 --- /dev/null +++ b/wrappers/csharp/cmake/CMakeCSharpCompiler.cmake.in @@ -0,0 +1,56 @@ +set(CMAKE_CSharp_COMPILER "@CMAKE_CSharp_COMPILER@") +set(CMAKE_CSharp_COMPILER_ARG1 "@CMAKE_CSharp_COMPILER_ARG1@") +#set(CMAKE_Fortran_COMPILER_ID "@CMAKE_Fortran_COMPILER_ID@") +#set(CMAKE_Fortran_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@") +#set(CMAKE_AR "@CMAKE_AR@") +#set(CMAKE_RANLIB "@CMAKE_RANLIB@") +# Should none on Win32, and 'mono' on unix +set(CMAKE_CSharp_RUNTIME "@CMAKE_CSharp_RUNTIME@") +set(CMAKE_CSharp_ARCHIVE "@CMAKE_CSharp_ARCHIVE@") # gacutil ?? + +set(CMAKE_CSharp_COMPILER_LOADED 1) + +set(CMAKE_CSharp_COMPILER_ENV_VAR "CSC") + +set(CMAKE_CSharp_SOURCE_FILE_EXTENSIONS cs;CS) +set(CMAKE_CSharp_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) +set(CMAKE_CSharp_LINKER_PREFERENCE 20) +set(CMAKE_STATIC_LIBRARY_PREFIX_CSharp "") +set(CMAKE_STATIC_LIBRARY_SUFFIX_CSharp ".dll") +set(CMAKE_SHARED_LIBRARY_PREFIX_CSharp "") +set(CMAKE_SHARED_LIBRARY_SUFFIX_CSharp ".dll") + +# FIXME ... where should it go +#set(CMAKE_EXECUTABLE_SUFFIX ".exe") + +set(CMAKE_STATIC_LIBRARY_CREATE_CSharp_FLAGS "/target:library") +set(CMAKE_STATIC_LIBRARY_CSharp_FLAGS "/target:library") +#CMAKE_STATIC_LIBRARY_CSharp_FLAGS + +# partial library +set(CMAKE_MODULE_LIBRARY_CREATE_CSharp_FLAGS "/target:module") +set(CMAKE_MODULE_LIBRARY_CSharp_FLAGS "/target:module") + +# static +set(CMAKE_SHARED_LIBRARY_CREATE_CSharp_FLAGS "/target:library") +set(CMAKE_SHARED_LIBRARY_CSharp_FLAGS "/target:library") +#set(CMAKE_SHARED_LIBRARY_LINK_CSharp_FLAGS "-r") +#set(CMAKE_SHARED_LIBRARY_RUNTIME_CSharp_FLAG "-r") +#set(CMAKE_SHARED_LIBRARY_LINK_CSharp_FLAGS "-r") + +# FIXME: CMAKE_LINK_LIBRARY_FILE_FLAG always add a space, so I cannot simply use "/r" because +# I would need to remove the space, but instead use the -r that tolerate a space +#set(CMAKE_LINK_LIBRARY_FILE_FLAG "") +#set(CMAKE_LINK_LIBRARY_FLAG "-r") + +#set(CMAKE_CREATE_WIN32_EXE /target:winexe) +#set(CMAKE_CREATE_CONSOLE_EXE /target:exe) + +#set(CMAKE_LINK_LIBRARY_FLAG "-l") + +#set(CMAKE_EXECUTABLE_RUNTIME_CSharp_FLAG "-foo") + +if(WIN32) +else() + set(CMAKE_CSHARP_INTERPRETER ${MONO_EXECUTABLE}) +endif() diff --git a/wrappers/csharp/cmake/CMakeCSharpInformation.cmake b/wrappers/csharp/cmake/CMakeCSharpInformation.cmake new file mode 100644 index 0000000000..c6dd1b3f23 --- /dev/null +++ b/wrappers/csharp/cmake/CMakeCSharpInformation.cmake @@ -0,0 +1,92 @@ + +# This file sets the basic flags for the CSharp language in CMake. +# It also loads the available platform file for the system-compiler +# if it exists. + +#set(CMAKE_BASE_NAME) +#get_filename_component(CMAKE_BASE_NAME ${CMAKE_CSharp_COMPILER} NAME_WE) +#set(CMAKE_SYSTEM_AND_CSharp_COMPILER_INFO_FILE +# #${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake) +# ${CMAKE_ROOT}/Modules/Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}.cmake) +#message(${CMAKE_SYSTEM_AND_CSharp_COMPILER_INFO_FILE}) +#include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL) + +# This should be included before the _INIT variables are +# used to initialize the cache. Since the rule variables +# have if blocks on them, users can still define them here. +# But, it should still be after the platform file so changes can +# be made to those values. + +if(CMAKE_USER_MAKE_RULES_OVERRIDE) + include(${CMAKE_USER_MAKE_RULES_OVERRIDE}) +endif() + +# Copy from CSharp, ref CXX ??? +if(CMAKE_USER_MAKE_RULES_OVERRIDE_CSHARP) + include(${CMAKE_USER_MAKE_RULES_OVERRIDE_CSHARP}) +endif() + +# +# the target without the suffix +# +# +# +# +# + +# this is a place holder if java needed flags for javac they would go here. +if(NOT CMAKE_CSharp_CREATE_STATIC_LIBRARY) +# if(WIN32) +# set(class_files_mask "*.class") +# else() + set(class_files_mask ".") +# endif() + + set(CMAKE_CSharp_CREATE_STATIC_LIBRARY + #" -cf -C ") + " -out:") +endif() + +# compile a CSharp file into an object file +if(NOT CMAKE_CSharp_COMPILE_OBJECT) + # there is no such thing as intermediate representation (object file) in C#. + # Instead to avoid multiple recompilation of the same src file, I could use the .dll form, since + # one can add src / .dll that same way + + # copy src version + set(CMAKE_CSharp_COMPILE_OBJECT " -E copy ") +endif() + +if(NOT CMAKE_CSharp_LINK_EXECUTABLE) + set(CMAKE_CSharp_LINK_EXECUTABLE + # I could not references 'SOURCES' so I simply copy all source to fake OBJECTS + + # .exe is required otherwise I get: + # Unhandled Exception: System.ArgumentException: Module file name + # 'cmTryCompileExec' must have file extension. + #" -out:.exe ") + " -out:.exe ") +endif() + +if(NOT CMAKE_CSharp_CREATE_SHARED_LIBRARY) + set(CMAKE_CSharp_CREATE_SHARED_LIBRARY + #" /target:library -out:") + " -out:") +endif() + +# set java include flag option and the separator for multiple include paths +#set(CMAKE_INCLUDE_FLAG_CSharp "-classpath ") +#if(WIN32 AND NOT CYGWIN) +# set(CMAKE_INCLUDE_FLAG_SEP_CSharp ";") +#else() +# set(CMAKE_INCLUDE_FLAG_SEP_CSharp ":") +#endif() + +set(CMAKE_CSharp_FLAGS_INIT "$ENV{CSFLAGS} ${CMAKE_CSharp_FLAGS_INIT}") + +# avoid just having a space as the initial value for the cache +if(CMAKE_CSharp_FLAGS_INIT STREQUAL " ") + set(CMAKE_CSharp_FLAGS_INIT) +endif() +set (CMAKE_CSharp_FLAGS "${CMAKE_CSharp_FLAGS_INIT}" CACHE STRING + "Flags used by the compiler during all build types.") diff --git a/wrappers/csharp/cmake/CMakeDetermineCSharpCompiler.cmake b/wrappers/csharp/cmake/CMakeDetermineCSharpCompiler.cmake new file mode 100644 index 0000000000..dd183c61c6 --- /dev/null +++ b/wrappers/csharp/cmake/CMakeDetermineCSharpCompiler.cmake @@ -0,0 +1,67 @@ + +# determine the compiler to use for CSharp programs +# NOTE, a generator may set CMAKE_CSharp_COMPILER before +# loading this file to force a compiler. +# use environment variable CSHARP first if defined by user, next use +# the cmake variable CMAKE_GENERATOR_CSHARP which can be defined by a generator +# as a default compiler +# +# Sets the following variables: +# CMAKE_CSharp_COMPILER +# CMAKE_AR +# CMAKE_RANLIB +# CMAKE_COMPILER_IS_GNUGNAT + +if(NOT CMAKE_CSharp_COMPILER) + # prefer the environment variable CSHARP + if($ENV{CSHARP} MATCHES ".+") + get_filename_component(CMAKE_CSharp_COMPILER_INIT $ENV{CSHARP} PROGRAM PROGRAM_ARGS CMAKE_CSharp_FLAGS_ENV_INIT) + if(CMAKE_CSharp_FLAGS_ENV_INIT) + set(CMAKE_CSharp_COMPILER_ARG1 "${CMAKE_CSharp_FLAGS_ENV_INIT}" CACHE STRING "First argument to CSharp compiler") + endif() + if(NOT EXISTS ${CMAKE_CSharp_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable CSHARP:\n$ENV{CSHARP}.") + endif() + endif() + + # next prefer the generator-specified compiler + if(CMAKE_GENERATOR_CSHARP) + if(NOT CMAKE_CSharp_COMPILER_INIT) + set(CMAKE_CSharp_COMPILER_INIT ${CMAKE_GENERATOR_CSHARP}) + endif() + endif() + + # finally list compilers to try + if(CMAKE_CSharp_COMPILER_INIT) + set(CMAKE_CSharp_COMPILER_LIST ${CMAKE_CSharp_COMPILER_INIT}) + else() + # Known compilers: + # mcs/gmcs/smcs # mono + # csc: DotNet + set(CMAKE_CSharp_COMPILER_LIST csc mcs gmcs smcs) + endif() + + # Find the compiler. + find_program(CMAKE_CSharp_COMPILER NAMES ${CMAKE_CSharp_COMPILER_LIST} DOC "CSharp compiler") + if(CMAKE_CSharp_COMPILER_INIT AND NOT CMAKE_CSharp_COMPILER) + set(CMAKE_CSharp_COMPILER "${CMAKE_CSharp_COMPILER_INIT}" CACHE FILEPATH "CSharp compiler" FORCE) + endif() +endif() +mark_as_advanced(CMAKE_CSharp_COMPILER) + +get_filename_component(COMPILER_LOCATION "${CMAKE_CSharp_COMPILER}" + PATH) + + +#include(CMakeFindBinUtils) + +# configure variables set in this file for fast reload later on +configure_file( + #${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in + ${CMAKE_MODULE_PATH}/CMakeCSharpCompiler.cmake.in + # "${CMAKE_PLATFORM_ROOT_BIN}/CMakeCSharpCompiler.cmake" + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCSharpCompiler.cmake + @ONLY + ) + +set(CMAKE_CSharp_COMPILER_ENV_VAR "CSC") diff --git a/wrappers/csharp/cmake/CMakeTestCSharpCompiler.cmake b/wrappers/csharp/cmake/CMakeTestCSharpCompiler.cmake new file mode 100644 index 0000000000..b90e52ebfd --- /dev/null +++ b/wrappers/csharp/cmake/CMakeTestCSharpCompiler.cmake @@ -0,0 +1,51 @@ + +# This file is used by EnableLanguage in cmGlobalGenerator to +# determine that that selected CShapr compiler can actually compile +# and link the most basic of programs. If not, a fatal error +# is set and cmake stops processing commands and will not generate +# any makefiles or projects. +if(NOT CMAKE_CSharp_COMPILER_WORKS) + message(STATUS "Check for working CSharp compiler: ${CMAKE_CSharp_COMPILER}") + file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCSharpCompiler.cs + "class Dummy {\n" + "static void Main() {\n" + "}\n}\n") + try_compile(CMAKE_CSharp_COMPILER_WORKS ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCSharpCompiler.cs + OUTPUT_VARIABLE OUTPUT) + set(C_TEST_WAS_RUN 1) +endif() + +if(NOT CMAKE_CSharp_COMPILER_WORKS) + message(STATUS "Check for working CSharp compiler: ${CMAKE_CSharp_COMPILER} -- broken") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the CSharp compiler works failed with " + "the following output:\n${OUTPUT}\n\n") + message(FATAL_ERROR "The CSharp compiler \"${CMAKE_CSharp_COMPILER}\" " + "is not able to compile a simple test program.\nIt fails " + "with the following output:\n ${OUTPUT}\n\n" + "CMake will not be able to correctly generate this project.") +else() + if(C_TEST_WAS_RUN) + message(STATUS "Check for working CSharp compiler: ${CMAKE_CSharp_COMPILER} -- works") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the CSharp compiler works passed with " + "the following output:\n${OUTPUT}\n\n") + endif() + set(CMAKE_CSharp_COMPILER_WORKS 1 CACHE INTERNAL "") + + if(CMAKE_CSharp_COMPILER_FORCED) + # The compiler configuration was forced by the user. + # Assume the user has configured all compiler information. + else() + # Try to identify the ABI and configure it into CMakeCSharpCompiler.cmake + include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) + CMAKE_DETERMINE_COMPILER_ABI(C ${CMAKE_ROOT}/Modules/CMakeCSharpCompilerABI.c) + configure_file( + #${CMAKE_ROOT}/Modules/CMakeCSharpCompiler.cmake.in + ${CMAKE_MODULE_PATH}/CMakeCSharpCompiler.cmake.in + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCSharpCompiler.cmake + @ONLY + ) + endif() +endif() diff --git a/wrappers/csharp/cmake/FindCSharp.cmake b/wrappers/csharp/cmake/FindCSharp.cmake new file mode 100644 index 0000000000..a61216621e --- /dev/null +++ b/wrappers/csharp/cmake/FindCSharp.cmake @@ -0,0 +1,24 @@ +# A C# Module for cmake +# +# TODO: +# Should I inspect the ENV{CSC} var first ? +# +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +if(WIN32) + find_package(DotNETFrameworkSDK) +else() + #TODO handle CSharp_FIND_QUIETLY + #TODO handle CSharp_FIND_REQUIRED + find_package(MONO) +endif() + +# http://public.kitware.com/Bug/view.php?id=7757 +get_filename_component(current_list_path ${CMAKE_CURRENT_LIST_FILE} PATH) +set(CSharp_USE_FILE ${current_list_path}/UseCSharp.cmake) diff --git a/wrappers/csharp/cmake/FindDotNETFrameworkSDK.cmake b/wrappers/csharp/cmake/FindDotNETFrameworkSDK.cmake new file mode 100644 index 0000000000..2b1de6f286 --- /dev/null +++ b/wrappers/csharp/cmake/FindDotNETFrameworkSDK.cmake @@ -0,0 +1,52 @@ +# - Find .NET Software Development Kit +# This module finds an installed .NET Software Development Kit. It sets the following variables: +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +# Note: +# .NET Framework SDK Version 1.1 +# http://www.microsoft.com/downloads/details.aspx?FamilyID=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displaylang=en +# .NET Framework 2.0 Software Development Kit (SDK) (x86) +# http://www.microsoft.com/downloads/details.aspx?FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en +# Microsoft .NET Framework 3.5 +# http://www.microsoft.com/downloads/details.aspx?familyid=333325FD-AE52-4E35-B531-508D977D32A6&displaylang=en + +# Comparison Between C++ and C# +# http://msdn.microsoft.com/en-us/library/yyaad03b(VS.71).aspx + +# http://www.akadia.com/services/dotnet_assemblies.html + +# Visual C# Language Concepts +# Building from the Command Line +# http://msdn.microsoft.com/en-us/library/1700bbwd(VS.71).aspx + +# FIXME, path are hardcoded. +# http://www.walkernews.net/2007/07/30/how-to-verify-dot-net-framework-version/ + +find_program(CSC_v1_EXECUTABLE csc + $ENV{windir}/Microsoft.NET/Framework/v1.1.4322/ +) +find_program(CSC_v2_EXECUTABLE csc + $ENV{windir}/Microsoft.NET/Framework/v2.0.50727/ +) +find_program(CSC_v3_EXECUTABLE csc + $ENV{windir}/Microsoft.NET/Framework/v3.5/ +) +find_program(CSC_v4_EXECUTABLE csc + $ENV{windir}/Microsoft.NET/Framework/v4.0.30319/ +) + +get_filename_component(current_list_path ${CMAKE_CURRENT_LIST_FILE} PATH) +set(DotNETFrameworkSDK_USE_FILE ${current_list_path}/UseDotNETFrameworkSDK.cmake) + +mark_as_advanced( + CSC_v1_EXECUTABLE + CSC_v2_EXECUTABLE + CSC_v3_EXECUTABLE + CSC_v4_EXECUTABLE +) diff --git a/wrappers/csharp/cmake/FindMONO.cmake b/wrappers/csharp/cmake/FindMONO.cmake new file mode 100644 index 0000000000..df35990769 --- /dev/null +++ b/wrappers/csharp/cmake/FindMONO.cmake @@ -0,0 +1,72 @@ +# - Find MONO +# This module finds an installed MONO. It sets the following variables: +# MONO_FOUND - set to true if MONO is found +# MONO_DIR - the directory where swig is installed +# MONO_EXECUTABLE - the path to the swig executable +# MONO_VERSION - the version number of the swig executable +# +# All informations are collected from the MONO_EXECUTABLE so the +# version to be found can be changed from the command line by +# means of setting MONO_EXECUTABLE +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +set(MONO_FOUND FALSE) + +# apt-get install mono-jit mono-mcs mono-gac mono-gmcs + +# eg. +# $ gmcs HelloWorld.cs +# $ mono HelloWorld.exe + +# TODO: what are 'cscc' and 'ilrun' ? + +find_program(MONO_EXECUTABLE mono) +find_program(MCS_EXECUTABLE mcs) # 1.0 +find_program(GMCS_EXECUTABLE mono-csc gmcs) # 2.0 +find_program(SMCS_EXECUTABLE smcs) # Moonlight +# mono-gac: /usr/bin/gacutil +find_program(GACUTIL_EXECUTABLE gacutil) # gacutil - Global Assembly Cache management utility. +# mono-1.0-devel: /usr/bin/ilasm +find_program(ILASM_EXECUTABLE ilasm) # ilasm, ilasm2 - Mono IL assembler +# mono-1.0-devel: /usr/bin/sn +find_program(SN_EXECUTABLE sn) # sn - Digitally sign/verify/compare strongnames on CLR assemblies. + +# We decide to declare mono found when both interpreter and compiler 1.0 are found. +if(MONO_EXECUTABLE AND MCS_EXECUTABLE) +set(MONO_FOUND TRUE) +# TODO get version +# TODO: there are multiple 'mcs' command on unix, need to check this is Mono: +# mcs --version should return "Mono C# compiler version 1.9.1.0" +elseif(MONO_EXECUTABLE AND GMCS_EXECUTABLE) +set(MONO_FOUND TRUE) +elseif(MONO_EXECUTABLE AND SMCS_EXECUTABLE) +set(MONO_FOUND TRUE) +endif() + +if(NOT MONO_FOUND) + if(NOT MONO_FIND_QUIETLY) + if(MONO_FIND_REQUIRED) + message(FATAL_ERROR "MONO was not found. Please specify mono/mcs executable location") + else() + message(STATUS "MONO was not found. Please specify mono/mcs executable location") + endif() + endif() +endif() + +get_filename_component(current_list_path ${CMAKE_CURRENT_LIST_FILE} PATH) +set(MONO_USE_FILE ${current_list_path}/UseMONO.cmake) + +mark_as_advanced( + MONO_EXECUTABLE + MCS_EXECUTABLE + GMCS_EXECUTABLE + SMCS_EXECUTABLE + ILASM_EXECUTABLE + SN_EXECUTABLE + GACUTIL_EXECUTABLE +) diff --git a/wrappers/csharp/cmake/UseCSharp.cmake b/wrappers/csharp/cmake/UseCSharp.cmake new file mode 100644 index 0000000000..3216b841ca --- /dev/null +++ b/wrappers/csharp/cmake/UseCSharp.cmake @@ -0,0 +1,187 @@ +# - C# module for CMake +# Defines the following macros: +# CSHARP_ADD_EXECUTABLE(name [ files ]) +# - Define C# executable with given name +# CSHARP_ADD_LIBRARY(name [ files ]) +# - Define C# library with given name +# CSHARP_LINK_LIBRARIES(name [ libraries ]) +# - Link libraries to csharp library +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +# TODO: +# http://www.cs.nuim.ie/~jpower/Research/csharp/Index.html + +if(WIN32) + include(${DotNETFrameworkSDK_USE_FILE}) + # remap + set(CMAKE_CSHARP1_COMPILER ${CSC_v1_EXECUTABLE}) + set(CMAKE_CSHARP2_COMPILER ${CSC_v2_EXECUTABLE}) + set(CMAKE_CSHARP3_COMPILER ${CSC_v3_EXECUTABLE}) + set(CMAKE_CSHARP4_COMPILER ${CSC_v4_EXECUTABLE}) + + #set(CMAKE_CSHARP3_INTERPRETER ${MONO_EXECUTABLE}) +else() + include(${MONO_USE_FILE}) + set(CMAKE_CSHARP1_COMPILER ${MCS_EXECUTABLE}) + set(CMAKE_CSHARP2_COMPILER ${GMCS_EXECUTABLE}) + set(CMAKE_CSHARP3_COMPILER ${SMCS_EXECUTABLE}) + set(CMAKE_CSHARP4_COMPILER ${SMCS_EXECUTABLE}) + + set(CMAKE_CSHARP_INTERPRETER ${MONO_EXECUTABLE}) +endif() + +set(DESIRED_CSHARP_COMPILER_VERSION 2 CACHE STRING "Pick a version for C# compiler to use: 1, 2, 3 or 4") +mark_as_advanced(DESIRED_CSHARP_COMPILER_VERSION) + +# default to v1: +if(DESIRED_CSHARP_COMPILER_VERSION MATCHES 1) + set(CMAKE_CSHARP_COMPILER ${CMAKE_CSHARP1_COMPILER}) +elseif(DESIRED_CSHARP_COMPILER_VERSION MATCHES 2) + set(CMAKE_CSHARP_COMPILER ${CMAKE_CSHARP2_COMPILER}) +elseif(DESIRED_CSHARP_COMPILER_VERSION MATCHES 3) + set(CMAKE_CSHARP_COMPILER ${CMAKE_CSHARP3_COMPILER}) +elseif(DESIRED_CSHARP_COMPILER_VERSION MATCHES 4) + set(CMAKE_CSHARP_COMPILER ${CMAKE_CSHARP4_COMPILER}) +else() + message(FATAL_ERROR "Do not know this version") +endif() + +# CMAKE_CSHARP_COMPILER /platform and anycpu +if(WIN32) +# There is a subttle issue when compiling on 64bits platform using a 32bits compiler +# See bug ID: 3510023 (BadImageFormatException: An attempt was made to load a progr) + +set(CSC_ACCEPTS_PLATFORM_FLAG 0) + +if(CMAKE_CSHARP_COMPILER) + execute_process(COMMAND "${CMAKE_CSHARP_COMPILER}" "/?" OUTPUT_VARIABLE CSC_HELP) + # when cmd locale is in French it displays: "/platform:" in english: "/platform:" + # so only regex match in /platform: + if("${CSC_HELP}" MATCHES "/platform:") + set(CSC_ACCEPTS_PLATFORM_FLAG 1) + endif() +endif() + +if(NOT DEFINED CSC_PLATFORM_FLAG) + set(CSC_PLATFORM_FLAG "") + if(CSC_ACCEPTS_PLATFORM_FLAG) + set(CSC_PLATFORM_FLAG "/platform:x86") + if("${CMAKE_SIZEOF_VOID_P}" GREATER 4) + set(CSC_PLATFORM_FLAG "/platform:x64") + endif() + endif() +endif() +endif() + + +# Check something is found: +if(NOT CMAKE_CSHARP_COMPILER) + # status message only for now: + message("Sorry C# v${DESIRED_CSHARP_COMPILER_VERSION} was not found on your system") +else() + #if (NOT CSHARP_FIND_QUIETLY) + message(STATUS "Will be using C# v${DESIRED_CSHARP_COMPILER_VERSION}: ${CMAKE_CSHARP_COMPILER}") + #endif () +endif() + +macro(CSHARP_ADD_LIBRARY name) + set(csharp_cs_sources) + set(csharp_cs_sources_dep) + foreach(it ${ARGN}) + if(EXISTS ${it}) + set(csharp_cs_sources "${csharp_cs_sources} ${it}") + set(csharp_cs_sources_dep ${csharp_cs_sources_dep} ${it}) + else() + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${it}) + set(csharp_cs_sources "${csharp_cs_sources} ${CMAKE_CURRENT_SOURCE_DIR}/${it}") + set(csharp_cs_sources_dep ${csharp_cs_sources_dep} ${CMAKE_CURRENT_SOURCE_DIR}/${it}) + else() + #message("Could not find: ${it}") + set(csharp_cs_sources "${csharp_cs_sources} ${it}") + endif() + endif() + endforeach() + + #set(SHARP #) + separate_arguments(csharp_cs_sources) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.dll + COMMAND ${CMAKE_CSHARP_COMPILER} + ARGS "/t:library" "/out:${name}.dll" ${csharp_cs_sources} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS "${csharp_cs_sources_dep}" + COMMENT "Creating Csharp library ${name}.cs" + ) + add_custom_target(CSharp_${name} ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}.dll + ) +endmacro() + +macro(CSHARP_ADD_EXECUTABLE name) + set(csharp_cs_sources) + foreach(it ${ARGN}) + if(EXISTS ${it}) + set(csharp_cs_sources "${csharp_cs_sources} ${it}") + else() + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${it}) + set(csharp_cs_sources "${csharp_cs_sources} ${CMAKE_CURRENT_SOURCE_DIR}/${it}") + else() + #message("Could not find: ${it}") + set(csharp_cs_sources "${csharp_cs_sources} ${it}") + endif() + endif() + endforeach() + + set(CSHARP_EXECUTABLE_${name}_ARGS + #"/out:${name}.dll" ${csharp_cs_sources} + #"/r:gdcm_csharp.dll" + "/out:${name}.exe ${csharp_cs_sources}" + ) + +endmacro() + +macro(CSHARP_LINK_LIBRARIES name) + set(csharp_libraries) + set(csharp_libraries_depends) + foreach(it ${ARGN}) + #if(EXISTS ${it}.dll) + set(csharp_libraries "${csharp_libraries} /r:${it}.dll") + # set(csharp_libraries_depends ${it}.dll) + #else() + # if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${it}.dll) + # set(csharp_libraries "${csharp_libraries} /r:${it}.dll") + # set(csharp_libraries_depends ${CMAKE_CURRENT_BINARY_DIR}/${it}.dll) + # else() + # message("Could not find: ${it}") + # endif() + #endif() + endforeach() + set(CSHARP_EXECUTABLE_${name}_ARGS " ${csharp_libraries} ${CSHARP_EXECUTABLE_${name}_ARGS}") + #message( "DEBUG: ${CSHARP_EXECUTABLE_${name}_ARGS}" ) + + # BAD DESIGN ! + # This should be in the _ADD_EXECUTABLE... + separate_arguments(CSHARP_EXECUTABLE_${name}_ARGS) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.exe + COMMAND ${CMAKE_CSHARP_COMPILER} + #ARGS "/r:gdcm_csharp.dll" "/out:${name}.exe" ${csharp_cs_sources} + ARGS ${CSHARP_EXECUTABLE_${name}_ARGS} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + #DEPENDS ${csharp_cs_sources} + COMMENT "Create HelloWorld.exe" + ) + + #message("DEBUG2:${csharp_libraries_depends}") + add_custom_target(CSHARP_EXECUTABLE_${name} ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}.exe + ${csharp_libraries_depends} + ) + +endmacro() diff --git a/wrappers/csharp/cmake/UseCSharpTest.cmake b/wrappers/csharp/cmake/UseCSharpTest.cmake new file mode 100644 index 0000000000..9388b17bc0 --- /dev/null +++ b/wrappers/csharp/cmake/UseCSharpTest.cmake @@ -0,0 +1,83 @@ +# Add a python test from a python file +# One cannot simply do: +# set(ENV{PYTHONPATH} ${LIBRARY_OUTPUT_PATH}) +# set(my_test "from test_mymodule import *\;test_mymodule()") +# add_test(PYTHON-TEST-MYMODULE python -c ${my_test}) +# Since cmake is only transmitting the ADD_TEST line to ctest thus you are loosing +# the env var. The only way to store the env var is to physically write in the cmake script +# whatever PYTHONPATH you want and then add the test as 'cmake -P python_test.cmake' +# +# Usage: +# set_source_files_properties(test.py PROPERTIES PYTHONPATH +# "${LIBRARY_OUTPUT_PATH}:${VTK_DIR}") +# ADD_PYTHON_TEST(PYTHON-TEST test.py) +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +# Need python interpreter: +#find_package(PythonInterp REQUIRED) +#mark_as_advanced(PYTHON_EXECUTABLE) +# UseCSharp.cmake + +macro(ADD_CSHARP_TEST TESTNAME FILENAME) + get_source_file_property(loc ${FILENAME} LOCATION) + get_source_file_property(pyenv ${FILENAME} RUNTIMEPATH) + if(CMAKE_CONFIGURATION_TYPES) + # I cannot use CMAKE_CFG_INTDIR since it expand to "$(OutDir)" + if(pyenv) + set(pyenv "${pyenv};${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}") + else() + set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}) + #set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}) + #set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CONFIG_TYPE}) + #set(pyenv ${LIBRARY_OUTPUT_PATH}/\${CMAKE_CONFIG_TYPE}) + endif() + else() + if(pyenv) + set(pyenv ${pyenv}:${LIBRARY_OUTPUT_PATH}) + else() + set(pyenv ${LIBRARY_OUTPUT_PATH}) + endif() + endif() + string(REGEX REPLACE ";" " " wo_semicolumn "${ARGN}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake +" + set(ENV{LD_LIBRARY_PATH} ${pyenv}) + set(ENV{MONO_PATH} ${pyenv}) + #message(\"pyenv: ${pyenv}\") + #message( \"wo_semicolumn: ${wo_semicolumn}\" ) + execute_process( + COMMAND ${CMAKE_CSHARP_INTERPRETER} ${loc} ${wo_semicolumn} + #WORKING_DIRECTORY @LIBRARY_OUTPUT_PATH@ + RESULT_VARIABLE import_res + OUTPUT_VARIABLE import_output + ERROR_VARIABLE import_output + ) + + # Pass the output back to ctest + if(import_output) + message("\${import_output}") + endif() + if(import_res) + message(SEND_ERROR "\${import_res}") + endif() +" +) + add_test(NAME ${TESTNAME} COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake) +endmacro() + +# Byte compile recursively a directory (DIRNAME) +#macro(ADD_PYTHON_COMPILEALL_TEST DIRNAME) +# # First get the path: +# get_filename_component(temp_path "${PYTHON_LIBRARIES}" PATH) +# # Find the python script: +# get_filename_component(PYTHON_COMPILE_ALL_PY "${temp_path}/../compileall.py" ABSOLUTE) +# # add test, use DIRNAME to create uniq name for the test: +# add_test(COMPILE_ALL-${DIRNAME} ${PYTHON_EXECUTABLE} "${PYTHON_COMPILE_ALL_PY}" -q ${DIRNAME}) +#endmacro() +# diff --git a/wrappers/csharp/cmake/UseDotNETFrameworkSDK.cmake b/wrappers/csharp/cmake/UseDotNETFrameworkSDK.cmake new file mode 100644 index 0000000000..78509e8959 --- /dev/null +++ b/wrappers/csharp/cmake/UseDotNETFrameworkSDK.cmake @@ -0,0 +1,6 @@ +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# diff --git a/wrappers/csharp/cmake/UseMONO.cmake b/wrappers/csharp/cmake/UseMONO.cmake new file mode 100644 index 0000000000..af95f89a67 --- /dev/null +++ b/wrappers/csharp/cmake/UseMONO.cmake @@ -0,0 +1,45 @@ +# - MONO module for CMake +# Defines the following macros: +# MONO_ADD_MODULE(name language [ files ]) +# - Define swig module with given name and specified language +# MONO_LINK_LIBRARIES(name [ libraries ]) +# - Link libraries to swig module +# All other macros are for internal use only. +# To get the actual name of the swig module, +# use: ${MONO_MODULE_name_REAL_NAME}. +# Set Source files properties such as CPLUSPLUS and MONO_FLAGS to specify +# special behavior of MONO. Also global CMAKE_MONO_FLAGS can be used to add +# special flags to all swig calls. +# Another special variable is CMAKE_MONO_OUTDIR, it allows one to specify +# where to write all the swig generated module (swig -outdir option) +# The name-specific variable MONO_MODULE__EXTRA_DEPS may be used +# to specify extra dependencies for the generated modules. +# +# Copyright (c) 2006-2011 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +# +# Create Swig module +# +macro(MONO_ADD_MODULE name) + set(swig_dot_i_sources) + foreach(it ${ARGN}) + set(swig_dot_i_sources ${swig_dot_i_sources} "${it}") + endforeach() + +endmacro() + +# +# Like TARGET_LINK_LIBRARIES but for swig modules +# +macro(MONO_LINK_LIBRARIES name) + if(MONO_MODULE_${name}_REAL_NAME) + target_link_libraries(${MONO_MODULE_${name}_REAL_NAME} ${ARGN}) + else() + message(SEND_ERROR "Cannot find Swig library \"${name}\".") + endif() +endmacro() diff --git a/wrappers/csharp/key.snk b/wrappers/csharp/key.snk new file mode 100644 index 0000000000..232fad9494 Binary files /dev/null and b/wrappers/csharp/key.snk differ diff --git a/wrappers/example/CMakeLists.txt b/wrappers/example/CMakeLists.txt new file mode 100644 index 0000000000..03fe0e4e9c --- /dev/null +++ b/wrappers/example/CMakeLists.txt @@ -0,0 +1,41 @@ +message("** Example wrapper") + +set(OTX_WRAPPER_NAME "Example") + +set(CMAKE_SWIG_FLAGS "") + +find_package(SWIG 3.0.0 REQUIRED) +include(${SWIG_USE_FILE}) + +## Place any required custom modules in a ./cmake subdirectory +## pretend we are building a wrapper for php +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(PHP5) + +## These are defined in our top-level opentxs.i which is included by +## our OTX_.i +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +# module name is set in the wrapper's OTX_.i +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS ON) + +# use our module "example" found in the wrapper's OTX_.i +swig_add_module(${OTX_WRAPPER_NAME} php OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} ${PHP_LIBRARIES}) + +## cmake/swig does some funky stuff with names, fortunately they provide +## a macro to handle it. We use our $OTX_WRAPPER_NAME to reference it +## and shorten it to ${MOD_NAME} +## +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + + +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME ${OTX_WRAPPER_NAME}) +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT php) + diff --git a/wrappers/example/OTX_.i b/wrappers/example/OTX_.i new file mode 100644 index 0000000000..842f83fb52 --- /dev/null +++ b/wrappers/example/OTX_.i @@ -0,0 +1,3 @@ +%module(directors="1") example + +%include "../opentxs.i" diff --git a/wrappers/java/CMakeLists.txt b/wrappers/java/CMakeLists.txt new file mode 100644 index 0000000000..230b93cf77 --- /dev/null +++ b/wrappers/java/CMakeLists.txt @@ -0,0 +1,40 @@ +## Work in progress +## +message("** Java Wrapper") + +set(OTX_WRAPPER_NAME "JOpentxs") + +set(CMAKE_SWIG_FLAGS "") +find_package(SWIG 3.0.0 REQUIRED) +include(${SWIG_USE_FILE}) + +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +find_package(Java) + +include_directories( + ${JAVA_INCLUDE_PATH}) + +## Java sources: place all our java code in subdir to keep it clean +set(JAVA_SOURCE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/otx_java CACHE INTERNAL "") +set(JAVA_BINARY_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/otx_java CACHE INTERNAL "") +file(MAKE_DIRECTORY ${JAVA_SOURCE_DIRECTORY}) +file(MAKE_DIRECTORY ${JAVA_BINARY_DIRECTORY}) + +set(CMAKE_SWIG_OUTDIR ${JAVA_BINARY_DIRECTORY}) + +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS ON) +swig_add_module(${OTX_WRAPPER_NAME} java OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} ${JAVA_LIBRARIES}) + +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME ${OTX_WRAPPER_NAME}) +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT java) + diff --git a/wrappers/java/OTX_.i b/wrappers/java/OTX_.i new file mode 100644 index 0000000000..71aa48211d --- /dev/null +++ b/wrappers/java/OTX_.i @@ -0,0 +1,4 @@ +%module(directors=1) JOpentxs + +%include "../opentxs.i" +%include "otx_java.i" diff --git a/wrappers/java/otx_java.i b/wrappers/java/otx_java.i new file mode 100644 index 0000000000..bea9f60535 --- /dev/null +++ b/wrappers/java/otx_java.i @@ -0,0 +1,461 @@ +/* Originally part of the monolithic opentxs.i +*/ + +// this is generaly not a good thing to include (typesafe enums are good), however I need to investigate more if we can safely remove it. +// the main benifit from including this directive is that enums can be used in a switch statement, (however in later java I think that this is no-longer an issue). +%include "java/enumtypeunsafe.swg"; + +// +// ------------------------------------------------------------ +// Put this: inside the %typemap (javacode) for the class that you want to have equals(). +// +/* +%define OT_SUPPORT_EQUALS +#ifdef SWIGJAVA +public boolean equals(Object obj) { + boolean equal = false; + if (obj instanceof $javaclassname) + equal = ((($javaclassname)obj).swigCPtr == this.swigCPtr); // Look at this cast! I am using polymorphism, I can't cast like this.... + return equal; +} +public int32_t hashCode() { + return (int32_t)getPointer(); +} +#endif +%enddef +*/ + +// ------------------------------------------------------------------------------- +// Put a list of these ABOVE the class definitions below. +// ALL objects, containers AND elements, are OT Storable objects. +// +// These two blocks enable the object to dynamic cast back +// to its true type, after factory construction. +// +// TODO: Fix this since "this" doesn't work at static level. +// (Anyway, doesn't it already have a pointer to its container?) +%define OT_BEFORE_STORABLE_TYPE(STORABLE_TYPE_A) +//%typemap(javaout) STORABLE_TYPE_A * ot_dynamic_cast { +// int64_t cPtr = $jnicall; +// $javaclassname ret = null; +// if (cPtr != 0) { +// ret = new $javaclassname(cPtr, $owner); +// ret.addReference(this); +// } +// return ret; +//} +%enddef + +// Todo: add mapping to Java destruct process, so that when the proxy +// goes out of scope, it is smart enough to remove itself from the reference list. +// Why is it being added in the first place? Because it is pointing to a certain +// object -- therefore according to Java it should have a reference to that object. +// Otherwise it will end up pointing to bad memory, when that object gets cleaned +// up by the garbage collector (who THOUGHT no one was referencing it.) +// +// ------------------------------------------------------------------------------- + +// Put this: inside the %typemap(javacode) for the CONTAINER_TYPE (near the top of it.) +// +// Any container stores a list of references to its elements, +// where a reference is added each time you use the "Add" method, so +// that none of its elements are erased out from under it by the Java Garbage Collector. +// +%define OT_CONTAINER_TYPE_MEMBERS + private List elementList = new ArrayList(); +%enddef + +// ---------------------------- +// If a class is meant to be used as an element inside a container, then use this +// macro to create the necessary typemap for that class's GET method. +// +// Put it: With the rest of the TYPEMAP for the class in question. (Above the class +// definition itself, and above the container typemaps.) +// +// Swig uses it: Any container that defines a get method for that class based on +// the signature below: THE_ELEMENT_TYPE * Get##THE_ELEMENT_TYPE +// +%define OT_IS_ELEMENT_TYPE(THE_ELEMENT_TYPE_A) +// When the CONTAINER_TYPE's "Get" function is called, this will add a Java +// reference to prevent premature garbage collection and resulting use +// of dangling C++ pointer. Intended for methods that return pointers or +// references to a member variable. +%typemap(javaout,noblock=1) THE_ELEMENT_TYPE_A * Get##THE_ELEMENT_TYPE_A { + int64_t cPtr = $jnicall; + $javaclassname ret = null; + if (cPtr != 0) { + ret = new $javaclassname(cPtr, $owner); + ret.addReference(this); + } + return ret; +} +// ---- +// Swig uses this in every CONTAINER_TYPE's "Add" function, which all +// have a parameter profile matching this typemap. +// +%typemap(javain,noblock=1) THE_ELEMENT_TYPE_A & disownObject { getCPtrAddRef##THE_ELEMENT_TYPE_A($javainput) } + +// This is used by CONTAINER_TYPE's "Remove" function. Do not change the +// parameter name nIndex##name or this typemap will stop working... +%typemap(javain,noblock=1) size_t nIndex##THE_ELEMENT_TYPE_A { removeRef##THE_ELEMENT_TYPE_A($javainput) } + +%enddef +// ---------------------------------------------------------------------------------- + + +// The STORABLE_TYPE (BitcoinAcct, say) keeps a reference to its CONTAINER_TYPE (WalletData). +// +// Put it: inside the %typemap(javacode) for the ELEMENT_TYPE, for EACH possible container type. +// +%define OT_CAN_BE_CONTAINED_BY(CONTAINER_TYPE_A) + // Ensure that the GC doesn't collect any OT_CONTAINER instance set from Java + private CONTAINER_TYPE_A containerRef##CONTAINER_TYPE_A; + // ---------------- + protected void addReference(CONTAINER_TYPE_A theContainer) { // This is Java code + containerRef##CONTAINER_TYPE_A = theContainer; + } + // ---------------- +%enddef + +// ------------------------------------------------------------------------------- + +// You might wonder, why did I use THE_ELEMENT_TYPE_A and then THE_ELEMENT_TYPE_B, +// etc? Because I didn't want to risk one define somehow overlapping another and +// substituting the wrong name because they both happened to use the same token +// for substitution. Therefore I made sure they all had different token naming. +// (FYI.) + + +// The CONTAINER_TYPE (WalletData) uses this for *EACH* Get/Add/Remove item within. +// So this macro appears multiple times, if there are multiple deques. (Like a contact +// has nyms AND accounts inside of it.) +// +// Put it: inside the %typemap(javacode) for the CONTAINER_TYPE, for EACH ELEMENT_TYPE. +// +// Ensure that the GC doesn't collect any THE_ELEMENT_TYPE set from Java +// as the underlying C++ class stores a shallow copy + +// Altered the SWIG example so that we store a list of these references, instead +// of only the latest one. (None of them should go out of scope until this object does.) + +%define OT_ADD_ELEMENT(THE_ELEMENT_TYPE_B) // THIS BLOCK CONTAINS JAVA CODE. +private Long removeRef##THE_ELEMENT_TYPE_B(Long lIndex) { + // + // loop through the elements in the actual container, in order to find the one + // at lIndex. Once it is found, then loop through the reference list and remove + // the corresponding reference for that element. + // + THE_ELEMENT_TYPE_B refActualElement = Get##THE_ELEMENT_TYPE_B(lIndex); + + if (refActualElement == null) + return lIndex; // oh well. + + // Loop through the reference list and remove the corresponding reference + // for the specified element. + // + for(Integer intIndex = 0; intIndex < elementList.size(); intIndex++) + { + Object theObject = elementList.get(intIndex); + + if ((theObject == null) || !(theObject instanceof THE_ELEMENT_TYPE_B)) + continue; + + THE_ELEMENT_TYPE_B tempRef = (THE_ELEMENT_TYPE_B)(theObject); + + if ((THE_ELEMENT_TYPE_B.getCPtr(tempRef) == THE_ELEMENT_TYPE_B.getCPtr(refActualElement))) + { + elementList.remove(tempRef); + break; + } + } + + return lIndex; +} + +private Long getCPtrAddRef##THE_ELEMENT_TYPE_B(THE_ELEMENT_TYPE_B element) { + // Whenever adding a reference to the list, I remove it first (if already there.) + // That way we never store more than one reference per actual contained object. + // + for(Integer intIndex = 0; intIndex < elementList.size(); intIndex++) + { + Object theObject = elementList.get(intIndex); + + if ((theObject == null) || !(theObject instanceof THE_ELEMENT_TYPE_B)) + continue; + + THE_ELEMENT_TYPE_B tempRef = (THE_ELEMENT_TYPE_B)(theObject); + + if ((THE_ELEMENT_TYPE_B.getCPtr(tempRef) == THE_ELEMENT_TYPE_B.getCPtr(element))) + { + elementList.remove(tempRef); // It was already there, so let's remove it before adding (below.) + break; + } + } + // Now we add it... + // + THE_ELEMENT_TYPE_B tempLocalRef = element; + elementList.add(tempLocalRef); + return THE_ELEMENT_TYPE_B.getCPtr(element); +} // Hope I get away with overloading this for every type. Otherwise, +%enddef +// hope I can just change the function name to customize it to type. + +// ---------------------------------------- + + +OT_BEFORE_STORABLE_TYPE(OTDB::OTDBString) +OT_IS_ELEMENT_TYPE(OTDBString) + +%typemap(javacode,noblock=1) OTDB::OTDBString { + // ------------------------ +} + +// ******************************* + + +OT_BEFORE_STORABLE_TYPE(OTDB::Blob) +OT_IS_ELEMENT_TYPE(Blob) + +%typemap(javacode,noblock=1) OTDB::Blob { + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::StringMap) +OT_IS_ELEMENT_TYPE(StringMap) + +%typemap(javacode,noblock=1) OTDB::StringMap { + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::BitcoinAcct) +OT_IS_ELEMENT_TYPE(BitcoinAcct) + +%typemap(javacode,noblock=1) OTDB::BitcoinAcct { + OT_CAN_BE_CONTAINED_BY(WalletData) + // ------------------------ +} + +// ******************************* + + +OT_BEFORE_STORABLE_TYPE(OTDB::ServerInfo) +OT_IS_ELEMENT_TYPE(ServerInfo) + +%typemap(javacode,noblock=1) OTDB::ServerInfo { + OT_CAN_BE_CONTAINED_BY(ContactNym) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::BitcoinServer) +OT_IS_ELEMENT_TYPE(BitcoinServer) + +%typemap(javacode,noblock=1) OTDB::BitcoinServer { + OT_CAN_BE_CONTAINED_BY(WalletData) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::RippleServer) +OT_IS_ELEMENT_TYPE(RippleServer) + +%typemap(javacode,noblock=1) OTDB::RippleServer { + OT_CAN_BE_CONTAINED_BY(WalletData) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::LoomServer) +OT_IS_ELEMENT_TYPE(LoomServer) + +%typemap(javacode,noblock=1) OTDB::LoomServer { + OT_CAN_BE_CONTAINED_BY(WalletData) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::ContactNym) +OT_IS_ELEMENT_TYPE(ContactNym) + +%typemap(javacode,noblock=1) OTDB::ContactNym { + OT_CAN_BE_CONTAINED_BY(Contact) + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(ServerInfo) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::ContactAcct) +OT_IS_ELEMENT_TYPE(ContactAcct) + +%typemap(javacode,noblock=1) OTDB::ContactAcct { + OT_CAN_BE_CONTAINED_BY(Contact) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::WalletData) +OT_IS_ELEMENT_TYPE(WalletData) + +%typemap(javacode,noblock=1) OTDB::WalletData { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(BitcoinServer) + OT_ADD_ELEMENT(BitcoinAcct) + OT_ADD_ELEMENT(RippleServer) + OT_ADD_ELEMENT(LoomServer) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::Contact) +OT_IS_ELEMENT_TYPE(Contact) + +%typemap(javacode,noblock=1) OTDB::Contact { + OT_CAN_BE_CONTAINED_BY(AddressBook) + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(ContactNym) + OT_ADD_ELEMENT(ContactAcct) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::AddressBook) +OT_IS_ELEMENT_TYPE(AddressBook) + +%typemap(javacode,noblock=1) OTDB::AddressBook { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(Contact) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::MarketData) +OT_IS_ELEMENT_TYPE(MarketData) + +%typemap(javacode,noblock=1) OTDB::MarketData { + OT_CAN_BE_CONTAINED_BY(MarketList) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::MarketList) +OT_IS_ELEMENT_TYPE(MarketList) + +%typemap(javacode,noblock=1) OTDB::MarketList { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(MarketData) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::BidData) +OT_IS_ELEMENT_TYPE(BidData) + +%typemap(javacode,noblock=1) OTDB::BidData { + OT_CAN_BE_CONTAINED_BY(OfferListMarket) + // ------------------------ +} + +// ******************************* + + +OT_BEFORE_STORABLE_TYPE(OTDB::AskData) +OT_IS_ELEMENT_TYPE(AskData) + +%typemap(javacode,noblock=1) OTDB::AskData { + OT_CAN_BE_CONTAINED_BY(OfferListMarket) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::OfferListMarket) +OT_IS_ELEMENT_TYPE(OfferListMarket) + +%typemap(javacode,noblock=1) OTDB::OfferListMarket { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(BidData) + OT_ADD_ELEMENT(AskData) +} + + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::TradeDataMarket) +OT_IS_ELEMENT_TYPE(TradeDataMarket) + +%typemap(javacode,noblock=1) OTDB::TradeDataMarket { + OT_CAN_BE_CONTAINED_BY(TradeListMarket) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::TradeListMarket) +OT_IS_ELEMENT_TYPE(TradeListMarket) + +%typemap(javacode,noblock=1) OTDB::TradeListMarket { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(TradeDataMarket) +} + + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::OfferDataNym) +OT_IS_ELEMENT_TYPE(OfferDataNym) + +%typemap(javacode,noblock=1) OTDB::OfferDataNym { + OT_CAN_BE_CONTAINED_BY(OfferListNym) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::OfferListNym) +OT_IS_ELEMENT_TYPE(OfferListNym) + +%typemap(javacode,noblock=1) OTDB::OfferListNym { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(OfferDataNym) +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::TradeDataNym) +OT_IS_ELEMENT_TYPE(TradeDataNym) + +%typemap(javacode,noblock=1) OTDB::TradeDataNym { + OT_CAN_BE_CONTAINED_BY(TradeListNym) + // ------------------------ +} + +// ******************************* + +OT_BEFORE_STORABLE_TYPE(OTDB::TradeListNym) +OT_IS_ELEMENT_TYPE(TradeListNym) + +%typemap(javacode,noblock=1) OTDB::TradeListNym { + // ------------------------ + OT_CONTAINER_TYPE_MEMBERS + OT_ADD_ELEMENT(TradeDataNym) +} + diff --git a/swig/CMakeLists.txt b/wrappers/old_swig/CMakeLists.txt similarity index 100% rename from swig/CMakeLists.txt rename to wrappers/old_swig/CMakeLists.txt diff --git a/swig/buildwrappers.sh b/wrappers/old_swig/buildwrappers.sh similarity index 100% rename from swig/buildwrappers.sh rename to wrappers/old_swig/buildwrappers.sh diff --git a/swig/opentxs.i b/wrappers/old_swig/opentxs.i similarity index 100% rename from swig/opentxs.i rename to wrappers/old_swig/opentxs.i diff --git a/wrappers/opentxs.i b/wrappers/opentxs.i new file mode 100644 index 0000000000..8c18b9a2dd --- /dev/null +++ b/wrappers/opentxs.i @@ -0,0 +1,109 @@ +/* + + Main file for the opentxs swig wrappers to define any variables + common to all wrappers. This is included from each wrapper's OTX_.i + + This was created from the opentsx.i which once contained all wrapper + directives. Each wrapper has been migrated to its own sub-directory. + +*/ + + +%ignore strtoimax; +%ignore strtoumax; + +%include "inttypes.i" +%include "std_string.i"; +%include "std_vector.i"; +%include "std_map.i" +%include "typemaps.i" + + +%{ +#ifndef IMPORT +#define IMPORT +#endif + +#include +#include +#include + +#include "../../include/opentxs/core/OTPassword.hpp" +#include "../../include/opentxs/api/OTAPI.hpp" +#include "../../include/opentxs/api/OT_ME.hpp" +#include "../../include/opentxs/core/OTStorage.hpp" +#include "../../include/opentxs/core/OTAsymmetricKey.hpp" +#include "../../include/opentxs/api/OTRecord.hpp" +#include "../../include/opentxs/api/OTRecordList.hpp" + +%} + +namespace std { + %template(VectorUnsignedChar) vector; + %template(MapStringString) map; +}; + +/* Some of these may actually belong to the Java wrapper? +*/ +%newobject CreateObject(StoredObjectType eType); +%newobject QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr=""); +%newobject DecodeObject(StoredObjectType theObjectType, std::string strInput); +%newobject Storage::QueryObject(StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr=""); +%newobject Storage::DecodeObject(StoredObjectType theObjectType, std::string strInput); +%newobject Storage::CreateObject(StoredObjectType eType); +%newobject CreateStorageContext(StorageType eStoreType, PackType ePackType=OTDB_DEFAULT_PACKER); + +%ignore OTRecord::operator<(const OTRecord & rhs); +%ignore OTPassword::operator=(const OTPassword & rhs); +%ignore OTPasswordData; +%ignore clone; +%ignore Storable::Create(StoredObjectType eType, PackType thePackType); +%ignore OTPasswordData; +%ignore PackedBuffer; +%ignore OTPacker; +%ignore PackerSubclass; +%ignore Storage::Create(StorageType eStorageType, PackType ePackType); +%ignore stat; +%ignore std::istream; +%ignore std::ostream; +%ignore msgpack::sbuffer; +%ignore std::map; +%ignore stlplus::simple_ptr_clone; + + +%ignore weak_ptr_OTRecord; + +%ignore vec_OTRecordList; +%ignore list_of_strings; +%ignore map_of_strings; + + +%rename(OTRecordLessThan) opentxs::OTRecord::operator<(const OTRecord& rhs); + +%feature("director") OTCallback; +%feature("director") OTNameLookup; + +/* Parse the header file to generate wrappers */ + +#ifndef EXPORT +#define EXPORT +#endif + +%include "../../include/opentxs/core/OTPassword.hpp" +%include "../../include/opentxs/api/OTAPI.hpp" +%include "../../include/opentxs/api/OT_ME.hpp" +%include "../../include/opentxs/core/OTStorage.hpp" +%include "../../include/opentxs/api/OTRecord.hpp" +%include "../../include/opentxs/api/OTRecordList.hpp" + + +bool opentxs::OT_API_Set_PasswordCallback(OTCaller & theCaller); +bool opentxs::OT_API_Set_AddrBookCallback(OTLookupCaller & theCaller); + + +// add the follwing to every .cxx file. +%inline %{ + using namespace opentxs; + using namespace OTDB; +%} + diff --git a/wrappers/perl/CMakeLists.txt b/wrappers/perl/CMakeLists.txt new file mode 100644 index 0000000000..794a71011a --- /dev/null +++ b/wrappers/perl/CMakeLists.txt @@ -0,0 +1,33 @@ +message("** Perl Wrapper") + +set(OTX_WRAPPER_NAME "OpenTransactions") + +set(CMAKE_SWIG_FLAGS "") + +find_package(SWIG 3.0.0 REQUIRED) +include(${SWIG_USE_FILE}) + +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +find_package(PerlLibs REQUIRED) + +include_directories( + ${PERL_INCLUDE_PATH} +) + +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS ON) +## Perl modules must not use lower case names, we will use OpenTransactions +swig_add_module(${OTX_WRAPPER_NAME} perl OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} ${PERL_LIBRARIES}) + +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME ${OTX_WRAPPER_NAME}) +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT perl) + diff --git a/wrappers/perl/OTX_.i b/wrappers/perl/OTX_.i new file mode 100644 index 0000000000..0bd8f41da7 --- /dev/null +++ b/wrappers/perl/OTX_.i @@ -0,0 +1,3 @@ +%module(directors=1) OpenTransactions + +%include "../opentxs.i" diff --git a/wrappers/php/CMakeLists.txt b/wrappers/php/CMakeLists.txt new file mode 100644 index 0000000000..0b35fa4541 --- /dev/null +++ b/wrappers/php/CMakeLists.txt @@ -0,0 +1,39 @@ +message("** PHP Wrapper") + +set(OTX_WRAPPER_NAME "opentxs_php") + +set(CMAKE_SWIG_FLAGS "") + +find_package(SWIG 3.0.0 REQUIRED) +include(${SWIG_USE_FILE}) + +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(PHP5) + +include_directories( + ${PHP5_INCLUDE_DIR} + ${PHP5_MAIN_INCLUDE_DIR} + ${PHP5_ZEND_INCLUDE_DIR} + ${PHP5_TSRM_INCLUDE_DIR} +) + +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS ON) +swig_add_module(${OTX_WRAPPER_NAME} php OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} ${PHP_LIBRARIES}) + +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME ${OTX_WRAPPER_NAME}) +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR} + COMPONENT php) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${OTX_WRAPPER_NAME}.php + DESTINATION ${CMAKE_INSTALL_LIBDIR}/ + COMPONENT php) diff --git a/wrappers/php/OTX_.i b/wrappers/php/OTX_.i new file mode 100644 index 0000000000..5d93e90f6b --- /dev/null +++ b/wrappers/php/OTX_.i @@ -0,0 +1,3 @@ +%module(directors=1) opentxs_php + +%include "../opentxs.i" diff --git a/swig/FindPHP5.cmake b/wrappers/php/cmake/FindPHP5.cmake similarity index 100% rename from swig/FindPHP5.cmake rename to wrappers/php/cmake/FindPHP5.cmake diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt new file mode 100644 index 0000000000..88da6571ce --- /dev/null +++ b/wrappers/python/CMakeLists.txt @@ -0,0 +1,36 @@ +message("** Python Wrapper") + +set(OTX_WRAPPER_NAME "opentxs-python") + +set(CMAKE_SWIG_FLAGS "") + +find_package(SWIG 3.0.0 REQUIRED) +include(${SWIG_USE_FILE}) + +include_directories( + ${SWIG_INCLUDE_DIRS} +) + +find_package(PythonLibs) +include_directories( + ${PYTHON_INCLUDE_PATH} +) + +set_source_files_properties(OTX_.i PROPERTIES CPLUSPLUS ON) +swig_add_module(${OTX_WRAPPER_NAME} python OTX_.i) +swig_link_libraries(${OTX_WRAPPER_NAME} ${PYTHON_LIBRARIES}) + +set(MOD_NAME ${SWIG_MODULE_${OTX_WRAPPER_NAME}_REAL_NAME}) + +target_link_libraries(${MOD_NAME} opentxs-api) +set_target_properties(${MOD_NAME} + PROPERTIES OUTPUT_NAME _opentxs) +string(REGEX REPLACE "\\.[0-9]+$" "" PYTHON_VERSION "${PYTHONLIBS_VERSION_STRING}") +install(TARGETS ${MOD_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION}/site-packages + COMPONENT python) +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/opentxs.py + DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION}/site-packages + COMPONENT python) + diff --git a/wrappers/python/OTX_.i b/wrappers/python/OTX_.i new file mode 100644 index 0000000000..2f8915d559 --- /dev/null +++ b/wrappers/python/OTX_.i @@ -0,0 +1,9 @@ +/* The swig module name affects the build, and there were issues with + conflicts by having them all named opentxs (from the original monolithic + opentxs.i). + This has been named opentxs and may be in use by others. + Would the name pyopentxs be better? +*/ +%module(directors=1) opentxs + +%include "../opentxs.i"