Skip to content

Commit

Permalink
example for how to use NabtoEmbeddedSDK with vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
mkm85 committed Sep 16, 2024
1 parent 5ffedde commit d56d71f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/distribution_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
distribution_test: [cmake_fetchcontent, cmake_find_package, direct_link_gcc]
distribution_test: [cmake_fetchcontent, cmake_find_package, direct_link_gcc, vcpkg_example]

steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions test/distribution/vcpkg_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project(vcpkg_example)
find_package(NabtoEmbeddedSDK REQUIRED)

add_executable(vcpkg_example main.c)
target_link_libraries(vcpkg_example PRIVATE NabtoEmbeddedSDK::nabto_device)
24 changes: 24 additions & 0 deletions test/distribution/vcpkg_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vcpkg example

This example shows how the nabto embedded sdk can be used with the vcpkg package
management system. This is just an example, consult the vcpkg documentation for
further information.

usage:

cd into this directory.
```
mkdir build
cd build
cmake -DCMAKE_MODULE_PATH=`pwd`/../../../../cmake/vcpkg -DCMAKE_TOOLCHAIN_FILE=`pwd`/../../../../3rdparty/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_OVERLAY_PORTS=`pwd`/../ports ..
make
./vcpkg_example
```

Explanation:
* The CMAKE_MODULE_PATH is needed since vcpkg still provides MbedTLS 2 and
tinycbor which does not come with find_package scripts.
* The CMAKE_TOOLCHAIN_FILE is set such that the cmake build system will use
vcpkg
* The VCPKG_OVERLAY_PORTS is set such that the NabtoEmbeddedSDK package can be
found since it is not present in the vcpkg package repository.
16 changes: 16 additions & 0 deletions test/distribution/vcpkg_example/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

SOURCE_DIR=${DIR}/../../..
BUILD_DIR=${SOURCE_DIR}/build/vcpkg_example
INSTALL_DIR=${BUILD_DIR}/install

mkdir -p ${BUILD_DIR}

set -v
set -e

cd ${BUILD_DIR}
cmake -DCMAKE_MODULE_PATH=${SOURCE_DIR}/cmake/vcpkg -DCMAKE_TOOLCHAIN_FILE=${SOURCE_DIR}/3rdparty/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_OVERLAY_PORTS=${DIR}/ports ${DIR}
make -j 16

./vcpkg_example
7 changes: 7 additions & 0 deletions test/distribution/vcpkg_example/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

#include <nabto/nabto_device.h>

int main(int argc, char* argv[]) {
printf("Nabto Embedded SDK verstion %s\r\n", nabto_device_version());
}
23 changes: 23 additions & 0 deletions test/distribution/vcpkg_example/ports/nabto-common/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(REF "95c9cae4b085668c4221f43c0d874d981daba4b1")

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nabto/nabto-common
REF ${REF}
SHA512 b4b45751df9eecce634f740d61a481625001e0669a250fb72499c760f3b0b46bb51121ca8041e2708f3a3b7e022a62b2b3137dac353e82ea6924fc9b6c2a7da8
HEAD_REF "master"
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DNABTO_COMMON_VERSION=0.0.0+${REF}
)

vcpkg_cmake_install()

vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(PACKAGE_NAME NabtoCommon CONFIG_PATH lib/cmake/NabtoCommon)

#vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSING.md")
17 changes: 17 additions & 0 deletions test/distribution/vcpkg_example/ports/nabto-common/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "nabto-common",
"version-string": "0.0.0",
"description": "Nabto Common",
"homepage": "https://github.com/nabto/nabto-common",
"license": "Apache-2.0",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
set(REF "b05465f002a6b00722e14ba7955758fe919a5b08")

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO nabto/nabto-embedded-sdk
REF ${REF}
SHA512 83491c30f02045e8c3428b4316297196a9e3baae508ec5571c657488efb4499958e728589ed7b00530d555664ebef204a94ffad6fef6fe3809b3915d50db48e4
HEAD_REF "master"
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DCMAKE_MODULE_PATH=${SOURCE_PATH}/cmake/vcpkg
-DDEVICE_BUILD_EXAMPLES=FALSE
-DDEVICE_BUILD_TESTS=FALSE
-DDEVICE_BUILD_APPS=FALSE
-DNABTO_DEVICE_PREFER_SYSTEM_LIBS=ON
-DNABTO_DEVICE_USE_SYSTEM_LIBEVENT=ON
-DNABTO_DEVICE_USE_SYSTEM_NABTOCOMMON=ON
-DNABTO_DEVICE_USE_SYSTEM_MBEDTLS=ON
-DNABTO_DEVICE_USE_SYSTEM_NLOHMANNJSON=ON
-DNABTO_DEVICE_USE_SYSTEM_TINYCBOR=ON
-DNABTO_DEVICE_BUILD_WITH_VCPKG_DEPENDENCIES=TRUE
-DNABTO_DEVICE_VERSION="0.0.0+${REF}"
)

vcpkg_cmake_install()

vcpkg_copy_pdbs()

vcpkg_cmake_config_fixup(PACKAGE_NAME NabtoEmbeddedSDK CONFIG_PATH lib/cmake/NabtoEmbeddedSDK)


#vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSING.md")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "nabto-embedded-sdk",
"version": "0.0.0+b05465f002a6b00722e14ba7955758fe919a5b08",
"description": "Nabto Embedded SDK",
"homepage": "https://github.com/nabto/nabto-embedded-sdk",
"license": "Apache-2.0",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "nabto-common"
},
{
"name": "libevent"
},
{
"name": "cjson"
},
{
"name": "mbedtls"
},
{
"name": "tinycbor"
}
]
}
5 changes: 5 additions & 0 deletions test/distribution/vcpkg_example/vcpkg-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"overlay-ports": [
"./ports"
]
}
7 changes: 7 additions & 0 deletions test/distribution/vcpkg_example/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "vcpkg-example",
"version-string": "0.0.1",
"dependencies": [
"nabto-embedded-sdk"
]
}

0 comments on commit d56d71f

Please sign in to comment.