Skip to content

Instantly share code, notes, and snippets.

@madebr
Last active October 24, 2019 17:15
Show Gist options
  • Save madebr/339d016f8ae44be891bdd32b5ab3073a to your computer and use it in GitHub Desktop.
Save madebr/339d016f8ae44be891bdd32b5ab3073a to your computer and use it in GitHub Desktop.
SWIG issue 1001
cmake_minimum_required(VERSION 3.14)
project(swig_test C)
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(SWIG REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR})
link_libraries(${PYTHON_LIBRARIES})
cmake_policy(SET CMP0078 NEW)
cmake_policy(SET CMP0086 NEW)
include(UseSWIG)
swig_add_library(mymod TYPE MODULE LANGUAGE python SOURCES example.i example.c)
option(WITH_CSHARP "Add C#")
if(WITH_CSHARP)
enable_language(CSharp)
add_executable(main main.cs)
endif()
from conans import ConanFile, CMake
class Build(ConanFile):
requires = ('swig_installer/4.0.1@madebr/testing',)
settings = 'os', 'arch', 'build_type', 'compiler',
generators = 'virtualenv', 'cmake',
def build(self):
print('settings.arch', str(self.settings.arch))
cmake = CMake(self)
cmake.configure()
cmake.build()
/* File : example.c */
double My_variable = 3.0;
/* Compute factorial of n */
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
/* Compute n mod m */
int my_mod(int n, int m) {
return(n % m);
}
/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);
%}
extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment