CMake Integration

include(FetchContent)
FetchContent_Declare(
  cmodule
  URL "https://github.com/scapix-com/cmodule/archive/refs/tags/v2.0.0.tar.gz"
  URL_HASH SHA256=58695a9d73dc95a2c214097729917c7d9c366bf511e162d566cf55dd2b9cd7be
)
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)

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.0.0.tar.gz"
  URL_HASH SHA256=58695a9d73dc95a2c214097729917c7d9c366bf511e162d566cf55dd2b9cd7be
)
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)