Skip to content

Commit

Permalink
Migrate swig wrappers out to their individual modules
Browse files Browse the repository at this point in the history
See the ./wrappers subdirectory for wrapper modules with an example in ./wrappers/example. Moved swig subdirectory to ./wrappers/old_swig, as it is no longer used in the build process, but is needed for further migration work and my be removed entirely after all modules are migrated into their own subdirectories
.
  • Loading branch information
BlueWall committed Aug 29, 2014
1 parent 4ccbad0 commit 530f2f2
Show file tree
Hide file tree
Showing 33 changed files with 1,695 additions and 2 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions 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)
76 changes: 76 additions & 0 deletions 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("")]
67 changes: 67 additions & 0 deletions 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"
)
3 changes: 3 additions & 0 deletions wrappers/csharp/OTX_.i
@@ -0,0 +1,3 @@
%module(directors=1) Opentxs

%include "../opentxs.i"
56 changes: 56 additions & 0 deletions 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()
92 changes: 92 additions & 0 deletions 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()

# <TARGET>
# <TARGET_BASE> the target without the suffix
# <OBJECTS>
# <OBJECT>
# <LINK_LIBRARIES>
# <FLAGS>
# <LINK_FLAGS>

# 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
#"<CMAKE_CSharp_ARCHIVE> -cf <TARGET> -C <OBJECT_DIR> <OBJECTS>")
"<CMAKE_CSharp_COMPILER> <CMAKE_STATIC_LIBRARY_CSharp_FLAGS> <OBJECTS> -out:<TARGET>")
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 "<CMAKE_COMMAND> -E copy <SOURCE> <OBJECT>")
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.
#"<CMAKE_CSharp_COMPILER> <FLAGS> <OBJECTS> -out:<TARGET>.exe <LINK_FLAGS> <LINK_LIBRARIES>")
"<CMAKE_CSharp_COMPILER> <FLAGS> <OBJECTS> -out:<TARGET_BASE>.exe <LINK_FLAGS> <LINK_LIBRARIES>")
endif()

if(NOT CMAKE_CSharp_CREATE_SHARED_LIBRARY)
set(CMAKE_CSharp_CREATE_SHARED_LIBRARY
#"<CMAKE_CSharp_COMPILER> /target:library <OBJECTS> -out:<TARGET>")
"<CMAKE_CSharp_COMPILER> <CMAKE_SHARED_LIBRARY_CSharp_FLAGS> <OBJECTS> -out:<TARGET>")
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.")

0 comments on commit 530f2f2

Please sign in to comment.