From 4e91af62d36189dc32c6aded0556490bf20cfb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Jun 2018 11:25:19 +0200 Subject: [PATCH 1/4] CMake: Export CMake package config --- CMakeLists.txt | 26 +++++++++++++++++++++++++- cmake/Config.cmake.in | 4 ++++ lib/instructions/CMakeLists.txt | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 76b280b29..ab2b989e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,9 @@ option(EVMC_EXAMPLES "Build EVMC examples" OFF) option(HUNTER_ENABLED "Enable Hunter package manager support" "${EVMC_TESTING}") include(cmake/cable/bootstrap.cmake) +include(CableBuildType) include(CableCompilerSettings) +include(CMakePackageConfigHelpers) include(HunterGate) include(GNUInstallDirs) include(defaults/HunterCacheServers) @@ -30,13 +32,16 @@ HunterGate( project(evmc) set(PROJECT_VERSION "0.1.0.dev0") +cable_set_build_type(DEFAULT Release CONFIGURATION_TYPES Debug Release) + cable_configure_compiler(NO_STACK_PROTECTION) set(include_dir ${PROJECT_SOURCE_DIR}/include) add_library(evmc INTERFACE) add_library(evmc::evmc ALIAS evmc) -target_include_directories(evmc INTERFACE ${include_dir}) +target_include_directories(evmc INTERFACE $$) +install(TARGETS evmc EXPORT evmcTargets) install(DIRECTORY include/evmc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) @@ -51,6 +56,25 @@ if(EVMC_EXAMPLES) add_subdirectory(examples) endif() +write_basic_package_version_file(evmcConfigVersion.cmake COMPATIBILITY ExactVersion) + +configure_package_config_file( + cmake/Config.cmake.in + evmcConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/evmc +) + +install( + EXPORT evmcTargets + NAMESPACE evmc:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/evmc +) +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/evmcConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/evmcConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/evmc +) if(WIN32) set(CPACK_GENERATOR ZIP) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 000000000..13df106bb --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake") +check_required_components(evmc) diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index 4d9905e5f..117e6c701 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -10,6 +10,6 @@ add_library( ) add_library(evmc::instructions ALIAS instructions) -target_include_directories(instructions PUBLIC ${include_dir}) +target_include_directories(instructions PUBLIC $$) install(TARGETS instructions EXPORT evmcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) From 9af6c35b48b15c2df0efa040a0837aa147b3aad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Jun 2018 11:38:08 +0200 Subject: [PATCH 2/4] Add examples how to use CMake packages --- examples/use_evmc_in_cmake/CMakeLists.txt | 14 ++++++++++++++ examples/use_evmc_in_cmake/use_evmc_in_cmake.c | 14 ++++++++++++++ examples/use_instructions_in_cmake/CMakeLists.txt | 14 ++++++++++++++ .../use_instructions_in_cmake.c | 14 ++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 examples/use_evmc_in_cmake/CMakeLists.txt create mode 100644 examples/use_evmc_in_cmake/use_evmc_in_cmake.c create mode 100644 examples/use_instructions_in_cmake/CMakeLists.txt create mode 100644 examples/use_instructions_in_cmake/use_instructions_in_cmake.c diff --git a/examples/use_evmc_in_cmake/CMakeLists.txt b/examples/use_evmc_in_cmake/CMakeLists.txt new file mode 100644 index 000000000..82725a2a4 --- /dev/null +++ b/examples/use_evmc_in_cmake/CMakeLists.txt @@ -0,0 +1,14 @@ +# EVMC: Ethereum Client-VM Connector API. +# Copyright 2018 Pawel Bylica. +# Licensed under the MIT License. See the LICENSE file. + +# This example shows how to use evmc INTERFACE library from evmc CMake package. + +cmake_minimum_required(VERSION 3.5) + +project(use_evmc_in_cmake) + +find_package(evmc CONFIG REQUIRED) + +add_executable(use_evmc_in_cmake use_evmc_in_cmake.c) +target_link_libraries(use_evmc_in_cmake PRIVATE evmc::evmc) diff --git a/examples/use_evmc_in_cmake/use_evmc_in_cmake.c b/examples/use_evmc_in_cmake/use_evmc_in_cmake.c new file mode 100644 index 000000000..756555f71 --- /dev/null +++ b/examples/use_evmc_in_cmake/use_evmc_in_cmake.c @@ -0,0 +1,14 @@ +/* EVMC: Ethereum Client-VM Connector API. + * Copyright 2018 Pawel Bylica. + * Licensed under the MIT License. See the LICENSE file. + */ + +/** This example shows how to use evmc INTERFACE library from evmc CMake package. */ + +#include + +int main() +{ + struct evmc_instance instance = {.abi_version = EVMC_ABI_VERSION}; + return instance.abi_version - EVMC_ABI_VERSION; +} diff --git a/examples/use_instructions_in_cmake/CMakeLists.txt b/examples/use_instructions_in_cmake/CMakeLists.txt new file mode 100644 index 000000000..bf6f353ea --- /dev/null +++ b/examples/use_instructions_in_cmake/CMakeLists.txt @@ -0,0 +1,14 @@ +# EVMC: Ethereum Client-VM Connector API. +# Copyright 2018 Pawel Bylica. +# Licensed under the MIT License. See the LICENSE file. + +# This example shows how to use evmc::instructions library from evmc CMake package. + +cmake_minimum_required(VERSION 3.5) + +project(use_instructions_in_cmake) + +find_package(evmc CONFIG REQUIRED) + +add_executable(use_instructions_in_cmake use_instructions_in_cmake.c) +target_link_libraries(use_instructions_in_cmake PRIVATE evmc::instructions) diff --git a/examples/use_instructions_in_cmake/use_instructions_in_cmake.c b/examples/use_instructions_in_cmake/use_instructions_in_cmake.c new file mode 100644 index 000000000..bd007e42e --- /dev/null +++ b/examples/use_instructions_in_cmake/use_instructions_in_cmake.c @@ -0,0 +1,14 @@ +/* EVMC: Ethereum Client-VM Connector API. + * Copyright 2018 Pawel Bylica. + * Licensed under the MIT License. See the LICENSE file. + */ + +/** This example shows how to use evmc::instructions library from evmc CMake package. */ + +#include + +int main() +{ + return evmc_get_instruction_metrics_table(EVMC_LATEST_REVISION)[OP_STOP] + .num_stack_returned_items; +} From 411073934a6d190fba2af80ea956f778f34f992c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Jun 2018 11:41:51 +0200 Subject: [PATCH 3/4] Circle CI: Test CMake package config --- circle.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/circle.yml b/circle.yml index c548aa542..5c2d10952 100644 --- a/circle.yml +++ b/circle.yml @@ -31,6 +31,16 @@ jobs: - store_artifacts: path: ~/package destination: package + - run: + name: "Test CMake package config" + command: | + mkdir ~/build-example-evmc && cd ~/build-example-evmc + cmake ~/project/examples/use_evmc_in_cmake -DCMAKE_PREFIX_PATH=~/install + cmake --build . + + mkdir ~/build-example-instructions && cd ~/build-example-instructions + cmake ~/project/examples/use_instructions_in_cmake -DCMAKE_PREFIX_PATH=~/install + cmake --build . - run: name: "Run evmc-vmtester libevmc-examplevm.so" command: ~/install/bin/evmc-vmtester ~/install/lib/libevmc-examplevm.so From 08d5883ddacc0f1bd457d7bbd5e5600b7537817c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Jun 2018 11:51:22 +0200 Subject: [PATCH 4/4] CMake: Change instructions output name to evmc-instructions --- lib/instructions/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index 117e6c701..10cbca1d7 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -10,6 +10,7 @@ add_library( ) add_library(evmc::instructions ALIAS instructions) +set_target_properties(instructions PROPERTIES OUTPUT_NAME evmc-instructions) target_include_directories(instructions PUBLIC $$) install(TARGETS instructions EXPORT evmcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})