phaser / KRAL

Build system based on CMake that adds modules and support for mobile platforms
GNU General Public License v3.0
5 stars 2 forks source link

Build native plugins for Unity3d #3

Open roscopecoltran opened 7 years ago

roscopecoltran commented 7 years ago

Hi phaser,

Hope you are all well !

I was looking after some cool CMake macros to support mobile devices and I found KRAL, so first of all, thank you for share it :-)

Context:

I wanted to extend 3 others CMake macros collections, and 1 native bindings wrapper called CppSharp, in order to build some dependencies and use them as Unity3D native plugins.

  1. Hunter, for package management
  2. Polly, for cross-platform build and CI testing
  3. CMakepp, to manage project manifests (eg. link)
  4. CppSharp, to generate .NET bindings that wrap C/C++ code allowing interoperability with managed languages. (useful for existing native codebase and to add scripting support, or to consume an existing native library)

Goal:

Build and export a CMake driven project, with its dependencies to the following platforms and architectures:

Export tree skeleton for a project or dependency build:

Plugins/PluginNameForUnity/
Plugins/PluginNameForUnity/iOS/libpluginname.a **(armv7, arm64)**
Plugins/PluginNameForUnity/iOS/pluginname.framework **(iOS Framework)**
Plugins/PluginNameForUnity/libpluginname.bundle **(MacOSX; i396;x86_64)**
Plugins/PluginNameForUnity/Android/libs/armeabi-v7a/libpluginname.so 
Plugins/PluginNameForUnity/Android/libs/armeabi-v7a-neon/libpluginname.so
Plugins/PluginNameForUnity/Android/libs/armeabi-v8a/libpluginname.so
Plugins/PluginNameForUnity/Android/libs/x86/libpluginname.so
Plugins/PluginNameForUnity/Android/libs/x86_64/libpluginname.so
Plugins/PluginNameForUnity/Android/libs/mips/libpluginname.so
Plugins/PluginNameForUnity/Android/libs/mips64/libpluginname.so
Plugins/PluginNameForUnity/x86/libpluginname.so **(Linux 32bits)**
Plugins/PluginNameForUnity/x86/libpluginname.dll **(Windows 64bits)**
Plugins/PluginNameForUnity/x86_64/libpluginname.so **(Linux 32bits)**
Plugins/PluginNameForUnity/x86_64/libpluginname.dll **(Windowss 64bits)**
Plugins/PluginNameForUnity/WSA/PhoneSDK81/ARM/libpluginname.dll
Plugins/PluginNameForUnity/WSA/PhoneSDK81/x86/libpluginname.dll
Plugins/PluginNameForUnity/WSA/SDK81/ARM/libpluginname.dll
Plugins/PluginNameForUnity/WSA/SDK81/x86/libpluginname.dll
Plugins/PluginNameForUnity/WSA/SDK81/x64/libpluginname.dll
Plugins/PluginNameForUnity/WSA/UWP/ARM/libpluginname.dll
Plugins/PluginNameForUnity/WSA/UWP/x86/libpluginname.dll
Plugins/PluginNameForUnity/WSA/UWP/x64/libpluginname.dll

How to ?

Questions:

  1. As I saw to your familiar with CMake and Unity3d, have you ever considered such macros in KRAL ? I could only see some macros for generating Apple frameworks
  2. Would you advise to extend KRAL or hunter for such purpose ? or create another CMake module wrapping all of them ?
  3. Would you rather use SWIG or CppSharp for generating P/Invoke layerP/Invoke layer ?

Any input or point of views are welcomed before I start this cmake packing layer :-)

Have a great day and week !

Cheers, Richard

phaser commented 7 years ago

Hi Richard,

  1. I'm not sure I wholly understand the use case for Unity3d. I assume that you would want to write a plugin for Unity3d in C++, generate a project that generates a DLL/*.so (depending on the platform) and have that copied inside an Unity3d project. This can be done, right now, but as I didn't do any work on KRAL for quite some time, I suspect some things may be a little bit outdated.

I've never used hunter. It looks cool. I had some of the same ideas for KRAL but sadly not enough time to develop them.

  1. Yeah, if I'm not missing something and what I said at point 1. is correct then yes, this is doable in CMake by extending KRAL or hunter. I would recommend hunter because it seems to have a lot more developers than KRAL (just me :) ).

  2. I don't know. I've never used any of them. For the plugins I wrote (not very sophisticated), I wrote the C# glue layer by hand.

Keep in mind that what KRAL and/or hunter do is not the platform dependent CMake parts, but the package management and wrapping part. If you have a monolithic project without many dependencies or you know what your dependencies are beforehand, then you can just write your project in CMake using Polly to help with the platform dependent parts. I wrote KRAL to help with changing dependencies (from platform to platform, but also from project to project), multiple toolchains and IDEs, and separating of relatively big projects into multiple more manageable packages.

So if the project isn't too big or very well defined you can probably do it faster by writing a CMake project for it.

Hope this helps! Cristian