Skip to content

building

JBenda edited this page Nov 16, 2024 · 6 revisions

Build and Installation

The project uses cmake and can therefore be built with

mkdir build
mkdir install
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../install
cmake --build . --config Release
cmake --install . --component <component-name e.g. lib>

After this, you can use cpack to create zip-archives for the different components of that project. It is also possible to install a component with cmake --install . --component <component-name e.g. lib>

If you are interested in a debug-build of inkcpp you can set -DCMAKE_BUILD_TYPE=Debug instead, and build with cmake --build . --config Debug which will produce the debug version.

The components are:

lib

Contains the inkcpp and inkcpp_compiler libraries and header files needed to use it in a C++ project this component supports cmake find_package command, for an example see this example.

cl

Contains inkcpp_cl the inkcpp command line client, for example to compile the ink binaries.

unreal

Contains folder structure to include inkcpp in an Unreal project.

A complete list of all cmake flags can be found here.

cmake example

tree
|- test.ink
|- main.cpp
|- CMakeListst.txt
inklecat -j test.ink
mkdir build; cd build
cmake .. -DCMAKE_PREFIX_PATH=<path-to-install-directory> -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
cd ..
./build/main

The Path for the executable may depend on your build system.

test.ink

EXTERNAL my_ink_function(a,b)

Hello world!
*	Hello back!
	Nice to hear from you!
* 	Bye
	BTW 3 + 5 = {my_ink_function(3,5)}
-> END

Create test.ink.json with inkclecat -j test.ink

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(main)

find_package(inkcpp CONFIG REQUIRED)

add_executable(main main.cpp)
set_property(TARGET main PROPERTY CXX_STANDARD 17)
target_link_libraries(main inkcpp inkcpp_compiler)

main.cpp

#include <ink/system.h>
#include <ink/choice.h>
#include <ink/runner.h>
#include <ink/story.h>
#include <ink/compiler.h>

#include <iostream>

using namespace ink::runtime;

int
MyInkFunction( int a, int b )
{
	return a + b;
}

int
main()
{
	ink::compiler::run("test.ink.json", "test.bin");
	// Load ink binary story, generated from the inkCPP compiler
	story* myInk = story::from_file( "test.bin" );

	// Create a new thread
	runner thread = myInk->new_runner();

	// Register external functions (glue automatically generated via templates)
	thread->bind( "my_ink_function", &MyInkFunction );

	// Write to cout
	while ( thread->can_continue() )
		std::cout << thread->getline();

	// Iterate choices
	int id = 0;
	for ( const choice& c : *thread )
	{
		std::cout << (id++) << ". " << c.text() << std::endl;
	}
	std::cin >> id;
	thread->choose(id);

	// Write to cout
	while ( thread->can_continue() )
		std::cout << thread->getline();
}
Clone this wiki locally