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/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 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/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; +} diff --git a/lib/instructions/CMakeLists.txt b/lib/instructions/CMakeLists.txt index 4d9905e5f..10cbca1d7 100644 --- a/lib/instructions/CMakeLists.txt +++ b/lib/instructions/CMakeLists.txt @@ -10,6 +10,7 @@ add_library( ) add_library(evmc::instructions ALIAS instructions) -target_include_directories(instructions PUBLIC ${include_dir}) +set_target_properties(instructions PROPERTIES OUTPUT_NAME evmc-instructions) +target_include_directories(instructions PUBLIC $$) install(TARGETS instructions EXPORT evmcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})