Skip to content

Commit

Permalink
Merge pull request #35 from ethereum/cmake-install
Browse files Browse the repository at this point in the history
CMake package config
  • Loading branch information
chfast authored Jun 20, 2018
2 parents cb2288b + 08d5883 commit 71428d0
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 2 deletions.
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 $<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:include>)
install(TARGETS evmc EXPORT evmcTargets)

install(DIRECTORY include/evmc DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/evmcTargets.cmake")
check_required_components(evmc)
14 changes: 14 additions & 0 deletions examples/use_evmc_in_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions examples/use_evmc_in_cmake/use_evmc_in_cmake.c
Original file line number Diff line number Diff line change
@@ -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 <evmc/evmc.h>

int main()
{
struct evmc_instance instance = {.abi_version = EVMC_ABI_VERSION};
return instance.abi_version - EVMC_ABI_VERSION;
}
14 changes: 14 additions & 0 deletions examples/use_instructions_in_cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions examples/use_instructions_in_cmake/use_instructions_in_cmake.c
Original file line number Diff line number Diff line change
@@ -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 <evmc/instructions.h>

int main()
{
return evmc_get_instruction_metrics_table(EVMC_LATEST_REVISION)[OP_STOP]
.num_stack_returned_items;
}
3 changes: 2 additions & 1 deletion lib/instructions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:include>)

install(TARGETS instructions EXPORT evmcTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})

0 comments on commit 71428d0

Please sign in to comment.