| OS | C++ | Python | Java | .NET |
|---|---|---|---|---|
| amd64 Linux | ||||
| amd64 macOS | ||||
| arm64 macOS | ||||
| amd64 Windows |
This is a complete example of how to create a Modern CMake C++ Project with the SWIG code generator to generate wrapper and package for Python, .Net and Java.
This project should run on GNU/Linux, MacOS and Windows.
You can find detailed documentation for C++, Swig, Python 3, .Net Core and Java.
note: You should read C++ and Swig first since since other languages are just swig generated wrappers from the C++.
You'll need:
- "CMake >= 3.18".
- "Python >= 3.6" and python module 'pip' (ed "setuptools" and "wheel" will be auto installed on demand).
The project layout is as follow:
-
CMakeLists.txt Top-level for CMake based build.
-
cmake Subsidiary CMake files.
- python.cmake All internall Python CMake stuff.
- dotnet.cmake All internall .Net CMake stuff.
- java.cmake All internall Java CMake stuff.
-
ci Root directory for continuous integration.
-
Foo Root directory for
Foolibrary.- CMakeLists.txt for
Foo. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
FooPython. - foo.i SWIG Python wrapper.
- CMakeLists.txt for
- dotnet
- CMakeLists.txt for
Foo.Net. - foo.i SWIG .Net wrapper.
- CMakeLists.txt for
- java
- CMakeLists.txt for
FooJava. - java/foo.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
Bar Root directory for
Barlibrary.- CMakeLists.txt for
Bar. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
BarPython. - bar.i SWIG Python wrapper.
- CMakeLists.txt for
- dotnet
- CMakeLists.txt for
Bar.Net. - bar.i SWIG .Net wrapper.
- CMakeLists.txt for
- java
- CMakeLists.txt for
BarJava. - java/bar.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
FooBar Root directory for
FooBarlibrary.- CMakeLists.txt for
FooBar. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
FooBarPython. - foobar.i SWIG Python wrapper.
- CMakeLists.txt for
- dotnet
- CMakeLists.txt for
FooBar.Net. - foobar.i SWIG .Net wrapper.
- CMakeLists.txt for
- java
- CMakeLists.txt for
FooBarJava. - java/foobar.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
FooBarApp Root directory for
FooBarAppexecutable.- CMakeLists.txt for
FooBarApp. - src private folder.
- CMakeLists.txt for
-
python Root directory for Python template files
setup.py.insetup.py template for the Python native package.
-
dotnet Root directory for .Net template files
-
java Root directory for Java template files
To complexify a little, the CMake project is composed of three libraries (Foo, Bar and FooBar) with the following dependencies:
Foo:
Bar:
FooBar: PUBLIC Foo PRIVATE BarTo build the C++ project, as usual:
cmake -S. -Bbuild
cmake --build buildFew links on the subject...
Project layout:
- The Pitchfork Layout Revision 1 (cxx-pflR1)
CMake:
- https://llvm.org/docs/CMakePrimer.html
- https://cliutils.gitlab.io/modern-cmake/
- https://cgold.readthedocs.io/en/latest/
Python:
.Net:
Some issue related to this process
- Nuget needs to support dependencies specific to target runtime #1660
- Improve documentation on creating native packages #238
- Guide for packaging C# library using P/Invoke
Image has been generated using plantuml:
plantuml -Tsvg docs/{file}.dotSo you can find the dot source files in docs.
Apache 2. See the LICENSE file for details.
This is not an official Google product, it is just code that happens to be owned by Google.