OS | C++ | Python | Java | .NET |
---|---|---|---|---|
Linux | ||||
macOS | ||||
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
Foo
library.- CMakeLists.txt for
Foo
. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
Foo
Python. - 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
Foo
Java. - java/foo.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
Bar Root directory for
Bar
library.- CMakeLists.txt for
Bar
. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
Bar
Python. - 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
Bar
Java. - java/bar.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
FooBar Root directory for
FooBar
library.- CMakeLists.txt for
FooBar
. - include public folder.
- src private folder.
- python
- CMakeLists.txt for
FooBar
Python. - 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
FooBar
Java. - java/foobar.i SWIG Java wrapper.
- CMakeLists.txt for
- CMakeLists.txt for
-
FooBarApp Root directory for
FooBarApp
executable.- CMakeLists.txt for
FooBarApp
. - src private folder.
- CMakeLists.txt for
-
python Root directory for Python template files
setup.py.in
setup.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 Bar
To build the C++ project, as usual:
cmake -S. -Bbuild
cmake --build build
Few 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}.dot
So 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.