Merge pull request #40 from strangebroadcasts/feature/csharp-swig-bindings
Add CMake rules to generate C# bindings
This commit is contained in:
@@ -7,5 +7,6 @@ Code Contributors
|
||||
=================
|
||||
|
||||
Andrew Pam (@xanni) <andrew@sericyb.com.au>
|
||||
Jørgen Lund (@strangebroadcasts) <jlund@strangebroadcasts.com>
|
||||
|
||||
Note: (@user) means a github user name.
|
||||
|
||||
@@ -5,6 +5,7 @@ cmake_minimum_required (VERSION 2.6)
|
||||
set(BUILD_BINDINGS_PERL OFF CACHE BOOL "Build the SourcetrailDB Perl bindings.")
|
||||
set(BUILD_BINDINGS_PYTHON OFF CACHE BOOL "Build the SourcetrailDB Python bindings.")
|
||||
set(BUILD_BINDINGS_JAVA OFF CACHE BOOL "Build the SourcetrailDB Java bindings.")
|
||||
set(BUILD_BINDINGS_CSHARP OFF CACHE BOOL "Build the SourcetrailDB C# bindings.")
|
||||
set(BUILD_EXAMPLES ON CACHE BOOL "Build the examples.")
|
||||
|
||||
set(PROJECT_NAME "SourcetrailDB")
|
||||
@@ -83,6 +84,16 @@ else()
|
||||
message(STATUS "Building the SourcetrailDB Java bindings will be skipped. You can enable building this target by setting 'BUILD_BINDINGS_JAVA' to 'ON'.")
|
||||
endif()
|
||||
|
||||
# --- C# Binding ---
|
||||
if (BUILD_BINDINGS_CSHARP)
|
||||
message(STATUS "The SourcetrailDB C# bindings will be built.")
|
||||
|
||||
set(CSHARP_BINDING_TARGET_NAME "bindings_csharp")
|
||||
set(CSHARP_BINDING_OUTPUT_DIR "")
|
||||
add_subdirectory("${CMAKE_SOURCE_DIR}/bindings_csharp" "${CMAKE_BINARY_DIR}/bindings_csharp")
|
||||
else()
|
||||
message(STATUS "Building the SourcetrailDB C# bindings will be skipped. You can enable building this target by setting 'BUILD_BINDINGS_CSHARP' to 'ON'.")
|
||||
endif()
|
||||
|
||||
# --- Examples ---
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ Even though the core implementation is written in C++, this does not require you
|
||||
* Perl (via [SWIG](http://www.swig.org/))
|
||||
* Python (via [SWIG](http://www.swig.org/))
|
||||
* Java (via [SWIG](http://www.swig.org/))
|
||||
* C# (via [SWIG](http://www.swig.org/))
|
||||
|
||||
If the language of your choice is not covered by this list, feel free to [open an issue](https://github.com/CoatiSoftware/SourcetrailDB/issues) or provide a pull request.
|
||||
|
||||
|
||||
## Versioning
|
||||
|
||||
The SourcetrailDB version format consists of three numbers in the format `vXX.dbYY.pZZ`.
|
||||
@@ -150,6 +150,20 @@ $ make
|
||||
|
||||
Swig is configured to generate the Java binding code as a pre-build event, so you don't need to bother with updating manually.
|
||||
|
||||
### C# Bindings
|
||||
|
||||
Requirements:
|
||||
* [SWIG 3.0.12](http://www.swig.org/) is used to automatically generate C# binding code. Make sure that SWIG is added to your path environment variable.
|
||||
|
||||
If you want to build the C# bindings run:
|
||||
```
|
||||
$ cd path/to/SourcetrailDB
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake -DBUILD_BINDINGS_CSHARP=ON ..
|
||||
$ make
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
The examples help you to understand SourcetrailDB usage in practice. Please take a look at each examples README file for build and use instructions. Each example also provides a Sourcetrail project file `.srctrlprj` showing you how to use a custom indexer directly from Sourcetrail (see [Integrating with Sourcetrail](#integrating-with-sourcetrail)).
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
cmake_minimum_required (VERSION 2.6)
|
||||
|
||||
# --- Setup Paths ---
|
||||
|
||||
set(RESOURCES_SWIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../resources_swig")
|
||||
set(GENERATED_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/src")
|
||||
set(CSHARP_BINDING_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
|
||||
|
||||
set(SWIG_INTERFACE_FILE "${RESOURCES_SWIG_DIR}/interface/sourcetraildb.i")
|
||||
set(CSHARP_BINDINGS_NAMESPACE "CoatiSoftware.SourcetrailDB")
|
||||
set(CSHARP_BINDING_TARGET_OUTPUT_NAME "SourcetrailDB")
|
||||
|
||||
# --- Find Swig ---
|
||||
|
||||
find_package(SWIG REQUIRED)
|
||||
include(${SWIG_USE_FILE})
|
||||
|
||||
# --- Configure Target ---
|
||||
|
||||
set_source_files_properties(${SWIG_INTERFACE_FILE} PROPERTIES CPLUSPLUS ON)
|
||||
set_property(SOURCE ${SWIG_INTERFACE_FILE} PROPERTY COMPILE_OPTIONS -namespace ${CSHARP_BINDINGS_NAMESPACE} -dllimport ${CSHARP_BINDING_TARGET_OUTPUT_NAME})
|
||||
|
||||
include_directories(
|
||||
"${RESOURCES_SWIG_DIR}/include"
|
||||
"${CORE_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
swig_add_library(
|
||||
${CSHARP_BINDING_TARGET_NAME}
|
||||
TYPE SHARED
|
||||
LANGUAGE csharp
|
||||
OUTPUT_DIR ${CSHARP_BINDING_OUTPUT_DIR}
|
||||
OUTFILE_DIR ${GENERATED_SRC_DIR}
|
||||
SOURCES ${SWIG_INTERFACE_FILE} ${RESOURCES_SWIG_DIR}/src/sourcetraildb.cpp
|
||||
)
|
||||
|
||||
set_target_properties(${CSHARP_BINDING_TARGET_NAME}
|
||||
PROPERTIES OUTPUT_NAME ${CSHARP_BINDING_TARGET_OUTPUT_NAME}
|
||||
SWIG_FLAGS ${CSHARP_BINDINGS_NAMESPACE})
|
||||
|
||||
swig_link_libraries(${CSHARP_BINDING_TARGET_NAME} ${CSHARP_LIBRARIES} ${LIB_CORE_TARGET_NAME})
|
||||
|
||||
configure_file("CoatiSoftware.SourcetrailDB.csproj" "CoatiSoftware.SourcetrailDB.csproj" COPYONLY)
|
||||
@@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
|
||||
<Content Include="$(ProjectDir)/SourcetrailDB.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>SourcetrailDB.dll</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
|
||||
<Content Include="$(ProjectDir)/SourcetrailDB.so">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>SourcetrailDB.so</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'">
|
||||
<Content Include="$(ProjectDir)/SourcetrailDB.dylib">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>SourcetrailDB.dylib</Link>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user