Starting from scratch

New project

The Vertices SDK is built to be included in any project as an external component.
The best way to achieve this is probably to make use of git submodules.
So let's say we have a clean repository with empty directories:
    external: I like to have a directory keeping external libs
    components: provided by the SDK you are building on
    myproject: the source code your team is writing
    utils: some scripts and tools that are useful
    build: generated build files
1
mkdir porting_guide
2
cd porting_guide
3
mkdir external components myproject utils build
Copied!
The structure is alive. Let's get the SDK.
1
# init directory as a git repository
2
git init
3
# clone SDK into external/c-vertices-sdk
4
git submodule add https://github.com/vertices-network/c-vertices-sdk external/c-vertices-sdk
5
# update submodules of the SDK itself
6
git submodule update --init --recursive
7
# check content of the SDK
8
ls external/c-vertices-sdk
Copied!
Let's create a main.c file with the minimum content:
1
touch myproject/main.c
Copied!
1
#include <stdio.h>
2
​
3
int main(int argc, char *argv[])
4
{
5
printf("Hello world\n");
6
​
7
return 0;
8
}
9
​
Copied!

CMake

We can now init our project with two CMake files that will be used to build the entire project:
1
touch CMakeLists.txt myproject/CMakeLists.txt
Copied!
Here is the minimum content of the root CMakeLists.txt:
1
cmake_minimum_required (3.20)
2
project (porting_guide)
3
​
4
# adding the Vertices SDK
5
add_subdirectory(external/c-vertices-sdk)
6
​
7
# adding the User code
8
add_subdirectory(myproject)
Copied!
Now we can add our main.c file into myproject/CMakeLists.txt:
1
set(PROJECT_NAME myproject)
2
project(${PROJECT_NAME})
3
​
4
# add source file related to that project
5
set(SRC_FILES
6
main.c
7
)
8
​
9
# Add directories to include below (headers folders)
10
set(INC_FOLDERS
11
)
12
​
13
include_directories(${INC_FOLDERS})
14
add_executable(${PROJECT_NAME} ${SRC_FILES})
Copied!
Before we can start including headers from the Vertices SDK, we need to add the library into myproject :
At the end of myproject/CMakeLists.txt, append that line:
1
target_link_libraries(${PROJECT_NAME} vertices)
Copied!
Now you can include the Vertices header in the main file:
1
#include "vertices.h" // ready to use the Vertices SDK library
Copied!
There are still some missing parts that will be covered in the next chapters.
Follow the next step to get our implementation of those first two steps πŸ₯³
Last modified 3mo ago