Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Build evmone-standalone library on Linux #95

Merged
merged 6 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ endif()
# INSTALL

set(install_targets evmone)
if(TARGET evmone-standalone)
list(APPEND install_targets evmone-standalone)
endif()
if(TARGET evm-test)
list(APPEND install_targets evm-test)
endif()

set_target_properties(
${install_targets} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
)

install(TARGETS ${install_targets} EXPORT evmoneTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
5 changes: 4 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ commands:
- run:
name: "Build Package"
working_directory: ~/package
command: cpack --config ~/build/CPackConfig.cmake
command: cmake --build ~/build --target package && mv ~/build/evmone*.tar.gz* .
- store_artifacts:
path: ~/package
destination: package
- persist_to_workspace:
root: ~/package
paths:
Expand Down
45 changes: 45 additions & 0 deletions cmake/LibraryTools.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

# For given target of a static library creates a custom target with -standalone suffix
# that merges the given target and all its static library depenednecies
# into a single static library.
#
# It silently ignores non-static library target and unsupported platforms.
function(add_standalone_library TARGET)
get_target_property(type ${TARGET} TYPE)
if(NOT type STREQUAL STATIC_LIBRARY)
return()
endif()

set(name ${TARGET}-standalone)

if(CMAKE_AR)
# Generate ar linker script.
set(script_file ${name}.mri)
set(script "OPEN $<TARGET_FILE:${name}>\n")
string(APPEND script "ADDLIB $<TARGET_FILE:${TARGET}>\n")

get_target_property(link_libraries ${TARGET} LINK_LIBRARIES)
foreach(lib ${link_libraries})
get_target_property(type ${lib} TYPE)
if(NOT type STREQUAL INTERFACE_LIBRARY)
string(APPEND script "ADDLIB $<TARGET_FILE:${lib}>\n")
endif()
endforeach()

string(APPEND script "SAVE\n")
file(GENERATE OUTPUT ${script_file} CONTENT ${script})

# Add -standalone static library.
add_library(${name} STATIC)
target_sources(${name} PRIVATE ${script_file})
add_custom_command(TARGET ${name} POST_BUILD COMMAND ${CMAKE_AR} -M < ${script_file})
add_dependencies(${name} ${TARGET})

get_property(enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
list(GET enabled_languages -1 lang)
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE ${lang})
endif()
endfunction()
18 changes: 11 additions & 7 deletions lib/evmone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

include(LibraryTools)

hunter_add_package(intx)
find_package(intx CONFIG REQUIRED)

Expand All @@ -14,14 +16,16 @@ add_library(evmone
execution.hpp
instructions.cpp
)
target_link_libraries(evmone PUBLIC evmc::evmc intx::intx PRIVATE evmc::instructions ethash::keccak)
target_link_libraries(evmone PUBLIC evmc::evmc PRIVATE intx::intx evmc::instructions ethash::keccak)
target_include_directories(evmone PUBLIC
$<BUILD_INTERFACE:${include_dir}>$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(
evmone PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
)

if(NOT SANITIZE)
# On Linux, check if all symbols in evmone are resolved during linking.
target_link_options(evmone PRIVATE $<$<PLATFORM_ID:Linux>:LINKER:--no-undefined>)
endif()

set_source_files_properties(evmone.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}")

add_standalone_library(evmone)
4 changes: 3 additions & 1 deletion test/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright 2019 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.

find_package(intx CONFIG REQUIRED)

add_library(testutils STATIC
bytecode.hpp
host_mock.hpp
Expand All @@ -13,5 +15,5 @@ target_link_libraries(testutils PRIVATE evmc::instructions)
target_include_directories(testutils PUBLIC ${PROJECT_SOURCE_DIR})

add_library(testutils-dump STATIC dump.cpp)
target_link_libraries(testutils-dump PRIVATE testutils evmone)
target_link_libraries(testutils-dump PRIVATE testutils evmone intx::intx)
target_include_directories(testutils-dump PRIVATE ${evmone_private_include_dir})