Skip to content

Commit 9b3474f

Browse files
committed
add a sample to use cmake package
this sample specifically aims to test the top-level CMakeLists.txt, which traditionally has weak coverage. cf. #2686 #4290
1 parent b7474b3 commit 9b3474f

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) 2025 Midokura Japan KK. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required(VERSION 3.16)
5+
6+
project(printversion LANGUAGES C)
7+
8+
add_executable(printversion printversion.c)
9+
find_package(iwasm REQUIRED)
10+
target_link_libraries(printversion iwasm::vmlib)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2023 Midokura Japan KK. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
*/
5+
6+
#include <inttypes.h>
7+
#include <stdint.h>
8+
#include <stdio.h>
9+
10+
#include <wasm_export.h>
11+
12+
int
13+
main(int argc, char **argv)
14+
{
15+
uint32_t major;
16+
uint32_t minor;
17+
uint32_t patch;
18+
wasm_runtime_get_version(&major, &minor, &patch);
19+
printf("wasm-micro-runtime %" PRIu32 ".%" PRIu32 ".%" PRIu32 "\n", major,
20+
minor, patch);
21+
}

samples/printversion/test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /bin/sh
2+
3+
# Copyright (C) 2025 Midokura Japan KK. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
set -e
7+
8+
DIST=$(mktemp -d)
9+
10+
# WAMR_BUILD_SIMD=0 to avoid fetching simde, which is
11+
# not relevant to this particular test.
12+
cmake -B build-wamr \
13+
-D CMAKE_INSTALL_PREFIX=${DIST} \
14+
-D WAMR_BUILD_SIMD=0 \
15+
../..
16+
cmake --build build-wamr -t install
17+
18+
cmake -B build-app \
19+
-D CMAKE_PREFIX_PATH=${DIST} \
20+
-D CMAKE_INSTALL_PREFIX=${DIST} \
21+
.
22+
cmake --build build-app
23+
24+
./build-app/printversion

0 commit comments

Comments
 (0)