CMake Integration

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL https://github.com/scapix-com/cmodule/archive/refs/tags/v2.2.0.tar.gz
  URL_HASH SHA256=b4e11cd566d340f0fbed62de2c3372498a7b508d76f7c3915a57508da3b79944
)
FetchContent_MakeAvailable(cmodule)

add_executable(example example.cpp)

# optionally override target platform:
set(SCAPIX_JAVA_API "jdk-11" CACHE STRING "")

find_package(ScapixJavaAPI REQUIRED)
target_link_libraries(example PRIVATE scapix::java_api)

SCAPIX_JAVA_API automatically selects platform from Android API version your project targets or JDK version used. You can override this automatic selection. You can also generate additional java_api C++ headers from any (compiled) java code using scapix_java utility.

Configuration options

SCAPIX_JNI_CACHE_CLASS_LOADER, default: ON

In some JVM scenarios (notably on Android), JNI FindClass() fails to load application classes when called from C++ created threads. More information here: Why didn’t FindClass find my class?. This implements the option “Cache a reference to the ClassLoader object somewhere handy, and issue loadClass calls directly.”

set(SCAPIX_JNI_CACHE_CLASS_LOADER OFF)

SCAPIX_JNI_AUTO_ATTACH_THREAD, default: ON

Threads created by Java are already “attached” to JVM, but if you call Java code from threads created in C++, each such thread needs to call scapix::jni::attach_thread() at least once. This option enables automatic attachment, at the expense of slight overhead.

set(SCAPIX_JNI_AUTO_ATTACH_THREAD OFF)

SCAPIX_JNI_STANDARD_UTF8, default: ON

By default, C++ std::string objects created from Java strings use standard UTF8 encoding. If disabled, modified UTF8 is used instead. This may provide better performance, depending on JVM implementation.

set(SCAPIX_JNI_STANDARD_UTF8 OFF)

C++ 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/refs/tags/v2.2.0.tar.gz
  URL_HASH SHA256=b4e11cd566d340f0fbed62de2c3372498a7b508d76f7c3915a57508da3b79944
)
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)