diff --git a/.github/workflows/distribution_tests.yml b/.github/workflows/distribution_tests.yml index 2f2989b5..5dc0b00b 100644 --- a/.github/workflows/distribution_tests.yml +++ b/.github/workflows/distribution_tests.yml @@ -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 diff --git a/test/distribution/vcpkg_example/CMakeLists.txt b/test/distribution/vcpkg_example/CMakeLists.txt new file mode 100644 index 00000000..eee3e688 --- /dev/null +++ b/test/distribution/vcpkg_example/CMakeLists.txt @@ -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) diff --git a/test/distribution/vcpkg_example/README.md b/test/distribution/vcpkg_example/README.md new file mode 100644 index 00000000..2c6e6a43 --- /dev/null +++ b/test/distribution/vcpkg_example/README.md @@ -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. diff --git a/test/distribution/vcpkg_example/build.sh b/test/distribution/vcpkg_example/build.sh new file mode 100755 index 00000000..8561701e --- /dev/null +++ b/test/distribution/vcpkg_example/build.sh @@ -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 diff --git a/test/distribution/vcpkg_example/main.c b/test/distribution/vcpkg_example/main.c new file mode 100644 index 00000000..5080628a --- /dev/null +++ b/test/distribution/vcpkg_example/main.c @@ -0,0 +1,7 @@ +#include + +#include + +int main(int argc, char* argv[]) { + printf("Nabto Embedded SDK verstion %s\r\n", nabto_device_version()); +} diff --git a/test/distribution/vcpkg_example/ports/nabto-common/portfile.cmake b/test/distribution/vcpkg_example/ports/nabto-common/portfile.cmake new file mode 100644 index 00000000..2df9556d --- /dev/null +++ b/test/distribution/vcpkg_example/ports/nabto-common/portfile.cmake @@ -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") diff --git a/test/distribution/vcpkg_example/ports/nabto-common/vcpkg.json b/test/distribution/vcpkg_example/ports/nabto-common/vcpkg.json new file mode 100644 index 00000000..e457c643 --- /dev/null +++ b/test/distribution/vcpkg_example/ports/nabto-common/vcpkg.json @@ -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 + } + ] + } diff --git a/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/portfile.cmake b/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/portfile.cmake new file mode 100644 index 00000000..4a377b0f --- /dev/null +++ b/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/portfile.cmake @@ -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") diff --git a/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/vcpkg.json b/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/vcpkg.json new file mode 100644 index 00000000..17ed7ce3 --- /dev/null +++ b/test/distribution/vcpkg_example/ports/nabto-embedded-sdk/vcpkg.json @@ -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" + } + ] + } diff --git a/test/distribution/vcpkg_example/vcpkg-configuration.json b/test/distribution/vcpkg_example/vcpkg-configuration.json new file mode 100644 index 00000000..f7b4d758 --- /dev/null +++ b/test/distribution/vcpkg_example/vcpkg-configuration.json @@ -0,0 +1,5 @@ +{ + "overlay-ports": [ + "./ports" + ] +} diff --git a/test/distribution/vcpkg_example/vcpkg.json b/test/distribution/vcpkg_example/vcpkg.json new file mode 100644 index 00000000..832c0e39 --- /dev/null +++ b/test/distribution/vcpkg_example/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "vcpkg-example", + "version-string": "0.0.1", + "dependencies": [ + "nabto-embedded-sdk" + ] +}