🔨Usage
Once you have the package installed, you only need to plop down an include command into your CMakeLists.txt.
include(CMakeKt)
Your Kotlin/Native klib
file will be available in the build/cinterop
folder. Look to Customization for learning how to change this.
Definition Generation
cinterop
tools intake a .def
file that uses C header declarations and libraries to generate a klib
file.
Example
# Declare Library
add_library("${PROJECT_NAME}" STATIC
src/main.c
src/main.h
src/kotlin-native/kotlin.h
)
# Look for headers in "include/kotlin-native"
file(GLOB_RECURSE KN_DEFINITION_HEADERS
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include/kotlin-native"
"include/kotlin-native/*.h"
)
# Set Kotlin Package
set(KN_DEFINITION_PACKAGE "dev.gmitch215.mynativeproject")
# Include some directories to look for libraries
set(KN_DEFINITION_LIBRARY_PATHS "${CMAKE_CURRENT_BINARY_DIR} ${RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_INSTALL_BINDIR} ${CMAKE_INSTALL_LIBDIR}")
# Include *.a and *.so Libraries from paths (Linux)
file(GLOB KN_DEFINITION_LIBRARIES
RELATIVE "${RUNTIME_OUTPUT_DIRECTORY}"
"${RUNTIME_OUTPUT_DIRECTORY}/*.a"
"${RUNTIME_OUTPUT_DIRECTORY}/*.so"
)
# Specify Output Paths
set(KN_CINTEROP_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/build/cinterop")
set(KN_CINTEROP_FILE_NAME "${PROJECT_NAME}.klib")
# Set Maven Details
set(KN_INSTALL_ARTIFACTID "${PROJECT_NAME}-maven")
# Include after variables were declared
include(CMakeKt)
add_klib_binary("${PROJECT_NAME}") # Inputs a target name
# optionally add a maven deploy step
option(DEPLOY_PROJECT "Deploy ${PROJECT_NAME}" OFF)
if (DEPLOY_PROJECT)
add_maven_deployment(
"${PROJECT_NAME}" # Target Name
"https://repo.example.org/repository/maven-releases" # Remote URL
"my-repository" # Repository ID, for auth in settings.xml
)
endif()
The install
target will install the klib
binary to your Maven Local directory. It is compatible with a custom repository location if specified in settings.xml
.
Last updated