Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit 1a45ce6

Browse files
authored
Merge pull request #303 from ethereum/cmake_vmtester_helper
cmake: Add helper for adding vmtester based VM test
2 parents 22ed657 + 2a2a732 commit 1a45ce6

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [6.3.0] - unreleased
44

5+
- Added: [[#303](https://github.com/ethereum/evmc/pull/303)]
6+
A CMake helper for running evmc-vmtester.
57
- Added: [[#313](https://github.com/ethereum/evmc/pull/313)]
68
The loader module introduces standardized EVMC module configuration string
79
which contains path to the module and additional options.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ install(
7979
FILES
8080
${CMAKE_CURRENT_BINARY_DIR}/evmcConfig.cmake
8181
${CMAKE_CURRENT_BINARY_DIR}/evmcConfigVersion.cmake
82+
cmake/EVMC.cmake
8283
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/evmc
8384
)
8485

cmake/Config.cmake.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@PACKAGE_INIT@
22

3-
include("${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake")
3+
include(${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake)
44
check_required_components(evmc)
5+
6+
include(${CMAKE_CURRENT_LIST_DIR}/EVMC.cmake)

cmake/EVMC.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EVMC: Ethereum Client-VM Connector API.
2+
# Copyright 2019 The EVMC Authors.
3+
# Licensed under the Apache License, Version 2.0.
4+
5+
6+
# Adds a CMake test to check the given EVMC VM implementation with the evmc-vmtester tool.
7+
#
8+
# evmc_add_vm_test(NAME <test_name> TARGET <vm>)
9+
# - NAME argument specifies the name of the added test,
10+
# - TARGET argument specifies the CMake target being a shared library with EVMC VM implementation.
11+
function(evmc_add_vm_test)
12+
if(NOT TARGET evmc::evmc-vmtester)
13+
message(FATAL_ERROR "The evmc-vmtester has not been installed with this EVMC package")
14+
endif()
15+
16+
cmake_parse_arguments("" "" NAME;TARGET "" ${ARGN})
17+
add_test(NAME ${_NAME} COMMAND $<TARGET_FILE:evmc::evmc-vmtester> $<TARGET_FILE:${_TARGET}>)
18+
endfunction()

examples/use_evmc_in_cmake/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ find_package(evmc CONFIG REQUIRED)
1212

1313
add_executable(use_evmc_in_cmake use_evmc_in_cmake.c)
1414
target_link_libraries(use_evmc_in_cmake PRIVATE evmc::evmc)
15+
16+
17+
18+
# Only for integration tests.
19+
if(NOT COMMAND evmc_add_vm_test)
20+
message(FATAL_ERROR "Function evmc_add_vm_test() not in EVMC.cmake module")
21+
endif()

test/vmtester/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
# Copyright 2018-2019 The EVMC Authors.
33
# Licensed under the Apache License, Version 2.0.
44

5+
include(EVMC)
56
include(GNUInstallDirs)
67

78
add_executable(evmc-vmtester vmtester.hpp vmtester.cpp tests.cpp)
89
set_target_properties(evmc-vmtester PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..)
910
target_link_libraries(evmc-vmtester PRIVATE evmc loader evmc-example-host GTest::gtest)
1011
set_source_files_properties(vmtester.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}")
12+
add_executable(evmc::evmc-vmtester ALIAS evmc-vmtester)
1113

1214

13-
install(TARGETS evmc-vmtester RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
15+
install(TARGETS evmc-vmtester EXPORT evmcTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1416

1517
set(prefix ${PROJECT_NAME}/vmtester)
1618

17-
add_test(NAME ${prefix}/examplevm COMMAND evmc-vmtester $<TARGET_FILE:evmc-example-vm>)
18-
add_test(NAME ${prefix}/example_precompiles_vm COMMAND evmc-vmtester $<TARGET_FILE:evmc-example-precompiles-vm>)
19+
evmc_add_vm_test(NAME ${prefix}/examplevm TARGET evmc-example-vm)
20+
evmc_add_vm_test(NAME ${prefix}/example_precompiles_vm TARGET evmc-example-precompiles-vm)
1921

2022
add_test(NAME ${prefix}/help COMMAND evmc-vmtester --version --help)
2123
set_tests_properties(${prefix}/help PROPERTIES PASS_REGULAR_EXPRESSION "Usage:")

0 commit comments

Comments
 (0)