CMake Integration

The recommended way is to setup one CMake project file for cross-platform C++ code (built for different platforms as either static or dynamic library) and a set of separate application projects for different platforms, some using Cmake and some created manually in corresponding IDEs.

In CMakeLists.txt for your C++ target, call scapix_bridge_headers(). This will invoke Scapix generator during build when C++ bridge classes change.

Example:

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL "https://github.com/scapix-com/cmodule/archive/v1.0.29.tar.gz"
  URL_HASH SHA256=b49019b355423aebacd927e99541b146c900ef416ae1da6a8343a2a274dd4876
)
FetchContent_MakeAvailable(cmodule)

find_package(Scapix REQUIRED)

scapix_bridge_headers(
    chatlib
    "com.example.chat"
    "source/chat/contact.h"
    "source/chat/session.h"
    "source/chat/model.h"
)

scapix_bridge_headers() parameters:

  • target - your lib target with cross-platform C++ code
  • domain - reverse domain for your application (example: com.companyname.appname)
  • bridge_headers - individually listed pathnames of header files containing your C++ bridge classes (classes derived from scapix::bridge::object)

For Python bridge, the order of headers passed to scapix_bridge_headers() matters: headers with base classes should come before headers with derived classes.

CMake Parameters

The same CMake project will build targets with different language bridge and different platform specific code (if any). Use Scapix project parameters to configure build target:

  • SCAPIX_BRIDGE - bridge language to use: cpp, java, objc, python, js, cs.
  • SCAPIX_PLATFORM (optional) - one of the folders inside source/<project>/platform/: ios, android, macos, windows, linux, etc. Default: generic.
  • SCAPIX_JAVA_API (optional) - one of the folders inside scapix/java_api/: jdk-11.0.2, android-28, etc. Default: jdk-11.0.2. You can generate additional java_api C++ headers from any (compiled) java code using scapix_java utility.

Dependency management

Scapix uses cmodule for CMake dependency management.

You can also add additional dependencies to your project and cmodule will automatically download and build these libraries for any target platform like iOS, Android, WebAssembly, etc.

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL "https://github.com/scapix-com/cmodule/archive/v1.0.29.tar.gz"
  URL_HASH SHA256=b49019b355423aebacd927e99541b146c900ef416ae1da6a8343a2a274dd4876
)
FetchContent_MakeAvailable(cmodule)

find_package(Boost REQUIRED COMPONENTS filesystem iostreams context)
target_link_libraries(${target} PUBLIC Boost::filesystem Boost::iostreams Boost::context)

find_package(ZLIB REQUIRED)
target_link_libraries(${target} PRIVATE ZLIB::ZLIB)

find_package(BZip2 REQUIRED)
target_link_libraries(${target} PRIVATE BZip2::BZip2)