diff --git a/CMakeLists.txt b/CMakeLists.txt index dd9c8d332f..cc589e752c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/circle.yml b/circle.yml index 6250590b72..ef7e329847 100644 --- a/circle.yml +++ b/circle.yml @@ -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: diff --git a/cmake/LibraryTools.cmake b/cmake/LibraryTools.cmake new file mode 100644 index 0000000000..b0ec29a1ab --- /dev/null +++ b/cmake/LibraryTools.cmake @@ -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 $\n") + string(APPEND script "ADDLIB $\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 $\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() diff --git a/lib/evmone/CMakeLists.txt b/lib/evmone/CMakeLists.txt index 3d76af1682..bc3953a9f5 100644 --- a/lib/evmone/CMakeLists.txt +++ b/lib/evmone/CMakeLists.txt @@ -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) @@ -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 $$ ) -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 $<$:LINKER:--no-undefined>) +endif() + set_source_files_properties(evmone.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="${PROJECT_VERSION}") + +add_standalone_library(evmone) diff --git a/test/utils/CMakeLists.txt b/test/utils/CMakeLists.txt index 13e6dfae8c..accf3f1a7f 100644 --- a/test/utils/CMakeLists.txt +++ b/test/utils/CMakeLists.txt @@ -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 @@ -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})