For some lib
target already defined:
add_library(lib header.h source.cpp)
Add Scapix:
include(FetchContent)
FetchContent_Declare(
cmodule
URL "https://github.com/scapix-com/cmodule/archive/refs/tags/v2.0.1.tar.gz"
URL_HASH SHA256=a9477bbefb43b6fabdc2dc044207fe42cca63999c60b6baf06ba0c62fa116ec5
)
FetchContent_MakeAvailable(cmodule)
find_package(Scapix REQUIRED)
scapix_bridge_headers(lib "com.example.lib" header.h)
The same CMake project will build C++ library with bindings for different languages, depending on SCAPIX_BRIDGE parameter:
$ cmake -B build -DSCAPIX_BRIDGE=java
Supported values for SCAPIX_BRIDGE parameter:
scapix_add_target() / scapix_bridge_headers() parameters:
For Python bridge, the order of headers passed to scapix_bridge_headers() matters: headers with base classes should come before headers with derived classes.
scapix_fix_sources()
Cosmetic: call scapix_fix_sources(lib)
to organize sources in IDEs like Visual Studio and XCode (calls CMake source_group() function).
When using Java Bridge (SCAPIX_BRIDGE=java), you can specify the following options:
See Scapix JNI documentation.
By default, Scapix generates JNI_OnLoad() function for target library. You can also use your own JNI_OnLoad(), which then needs to call scapix_JNI_OnLoad().
target_compile_definitions(scapix PUBLIC SCAPIX_CUSTOM_JNI_ONLOAD)
#include <scapix/bridge/java/on_load.h>
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
{
// ... your additional JNI init code ...
return scapix_JNI_OnLoad(vm, reserved);
}
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/refs/tags/v2.0.1.tar.gz"
URL_HASH SHA256=a9477bbefb43b6fabdc2dc044207fe42cca63999c60b6baf06ba0c62fa116ec5
)
FetchContent_MakeAvailable(cmodule)
find_package(Boost REQUIRED COMPONENTS filesystem iostreams context)
target_link_libraries(mylib PUBLIC Boost::filesystem Boost::iostreams Boost::context)
find_package(ZLIB REQUIRED)
target_link_libraries(mylib PRIVATE ZLIB::ZLIB)
find_package(BZip2 REQUIRED)
target_link_libraries(mylib PRIVATE BZip2::BZip2)
find_package(CURL REQUIRED)
target_link_libraries(mylib PRIVATE CURL::libcurl)