Compile contract CMake
Overview
This guide provides instructions how to configure CMake.
Before you begin
- You have installed CMake, for detailed instructions consult the official CMake installation page.
Automatic generation of CMake configuration
To compile an INERY value contract with CMake, you'll need a CMake file. To use the new inery-init
tool to generate the directory structure stub .hpp/.cpp
files and the CMake configuration files follow these steps:
cd ~
inery-init --path=. --project=test_contract
cd test_contract
cd build
cmake ..
make
ls -al test_contract
At this point, you'll have the test_contract.abi
and test_contract.wasm
files in ~/test_contract/test_contract
. These files are ready to be deployed.
Manual generation of CMake configuration
To create manually the CMake configuration, the template CMakeLists.txt
in the examples folder is a good boilerplate for manual usage.
In
CMakeLists.txt
:cmake_minimum_required(VERSION 3.5)
project(test_example VERSION 1.0.0)
find_package(inery.cdt)
add_contract( test test test.cpp )In
test.cpp
:#include <inery/inery.hpp>
using namespace inery;
class [[inery::contract]] test : public inery::contract {
public:
using contract::contract;
[[inery::action]] void testact( name test ) {
}
};The following CMake macros are provided:
add_contract
is used to build your value contract and generate an ABI. The first parameter is the contract name, the second is the CMake target name, and the rest are the CPP files needed to build the contract.target_ricardian_directory
can be used to add the directory where your ricardian contracts live to a specific CMake target.add_native_library
andadd_native_executable
are CMake macros for the native tester. They are drop in replacements foradd_library
andadd_executable
.
Procedure
Follow the following steps to compile your contract.
Navigate to the inrcrud folder in examples (./tutorials/inrcrud), you should then see the ./src/inrcrud.cpp file
Run following commands:
mkdir build
cd build
cmake ..
makeVerify the following two files were generated:
- the compiled binary wasm:
inrcrud.wasm
, - and the generated ABI file:
inrcrud.abi
.
Summary
In conclusion, the above instructions show how to configure CMake .