Skip to content

Commit

Permalink
Feature/shared model cmake (hyperledger-iroha#1018)
Browse files Browse the repository at this point in the history
* rework shared model cmake as a separate project

fix import, remove unnecessary code

refactor

remove unnecessary import

* remove optional from dependencies

* Add tests to shared_model

* add git ignore

* fix python and java tests

Signed-off-by: Victor Drobny <[email protected]>
  • Loading branch information
vdrobnyi authored and x3medima17 committed Mar 30, 2018
1 parent 8e7a2b8 commit 2f7e92a
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 51 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ if(SHARED_MODEL_DISABLE_COMPATIBILITY)
add_definitions(-DDISABLE_BACKWARD)
endif()

SET(IROHA_ROOT_PROJECT ON)

add_subdirectory(schema)
add_subdirectory(libs)
add_subdirectory(irohad)
Expand Down
3 changes: 0 additions & 3 deletions libs/generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
add_library(generator generator.cpp)
target_link_libraries(generator
common
)
83 changes: 45 additions & 38 deletions schema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ compile_proto_to_cpp(primitive.proto)
compile_proto_to_cpp(commands.proto)
compile_proto_to_cpp(queries.proto)
compile_proto_to_cpp(responses.proto)
compile_proto_to_grpc_cpp(endpoint.proto)
compile_proto_to_grpc_cpp(yac.proto)
compile_proto_to_grpc_cpp(ordering.proto)
compile_proto_to_grpc_cpp(loader.proto)
compile_proto_to_cpp(endpoint.proto)

if (IROHA_ROOT_PROJECT)
compile_proto_to_grpc_cpp(endpoint.proto)
compile_proto_to_grpc_cpp(yac.proto)
compile_proto_to_grpc_cpp(ordering.proto)
compile_proto_to_grpc_cpp(loader.proto)
endif ()

add_library(schema
block.pb.cc
Expand All @@ -35,46 +39,49 @@ add_library(schema
endpoint.pb.cc
proposal.pb.cc
)

target_link_libraries(schema
protobuf
)
target_include_directories(schema PUBLIC
.
${CMAKE_CURRENT_SOURCE_DIR}
)

add_library(endpoint
endpoint.pb.cc
endpoint.grpc.pb.cc
)
target_link_libraries(endpoint
protobuf
grpc++
schema
)
if (IROHA_ROOT_PROJECT)
add_library(endpoint
endpoint.pb.cc
endpoint.grpc.pb.cc
)
target_link_libraries(endpoint
protobuf
grpc++
schema
)

add_library(yac_grpc
yac.pb.cc
yac.grpc.pb.cc
)
target_link_libraries(yac_grpc
protobuf
grpc++
)
add_library(yac_grpc
yac.pb.cc
yac.grpc.pb.cc
)
target_link_libraries(yac_grpc
protobuf
grpc++
)

add_library(ordering_grpc
ordering.pb.cc
ordering.grpc.pb.cc
)
target_link_libraries(ordering_grpc
schema
grpc++
)
add_library(ordering_grpc
ordering.pb.cc
ordering.grpc.pb.cc
)
target_link_libraries(ordering_grpc
schema
grpc++
)

add_library(loader_grpc
loader.pb.cc
loader.grpc.pb.cc
)
target_link_libraries(loader_grpc
schema
grpc++
)
add_library(loader_grpc
loader.pb.cc
loader.grpc.pb.cc
)
target_link_libraries(loader_grpc
schema
grpc++
)
endif ()
2 changes: 2 additions & 0 deletions shared_model/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/*
external/*
49 changes: 44 additions & 5 deletions shared_model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 Soramitsu Co., Ltd.
# Copyright 2018 Soramitsu Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,13 +12,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.5.1)

project(shared_model C CXX)

set(IROHA_SCHEMA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../schema")
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../libs
${IROHA_SCHEMA_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

if (NOT IROHA_ROOT_PROJECT)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_CXX_FLAGS "-std=c++14 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wextra -Wno-unused-parameter -Wno-deprecated-declarations -O0")

option(TESTING "Build tests" ON)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules)

set(SHARED_MODEL_DISABLE_COMPATIBILITY ON)
add_definitions(-DDISABLE_BACKWARD)

include(FeatureSummary)
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/functions.cmake)
include(cmake/dependencies.cmake)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../schema schema)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libs/generator generator)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libs/amount amount)
endif ()
add_library(old_model INTERFACE)

if (NOT SHARED_MODEL_DISABLE_COMPATIBILITY)
target_link_libraries(old_model INTERFACE
model
)
endif()
target_link_libraries(old_model INTERFACE
model
)
endif ()

add_subdirectory(backend)
add_subdirectory(bindings)
Expand All @@ -27,3 +59,10 @@ add_subdirectory(converters)
add_subdirectory(cryptography)
add_subdirectory(interfaces)
add_subdirectory(validators)

if (NOT IROHA_ROOT_PROJECT)
if (TESTING)
enable_testing()
add_subdirectory(test)
endif ()
endif ()
1 change: 1 addition & 0 deletions shared_model/backend/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ add_library(shared_model_proto_backend
target_link_libraries(shared_model_proto_backend
schema
model_interfaces
iroha_amount
)
1 change: 0 additions & 1 deletion shared_model/backend/protobuf/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "backend/protobuf/util.hpp"
#include "common_objects/trivial_proto.hpp"
#include "interfaces/common_objects/types.hpp"
#include "model/block.hpp"

#include "block.pb.h"
#include "utils/lazy_initializer.hpp"
Expand Down
1 change: 0 additions & 1 deletion shared_model/backend/protobuf/proposal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <boost/range/numeric.hpp>
#include "common_objects/trivial_proto.hpp"
#include "model/proposal.hpp"

#include "block.pb.h"
#include "interfaces/common_objects/types.hpp"
Expand Down
4 changes: 4 additions & 0 deletions shared_model/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
rm ../schema/*.{cc,h}
rm -rf external
rm -rf build
38 changes: 38 additions & 0 deletions shared_model/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
find_package(PackageHandleStandardArgs)

include(ExternalProject)
set(EP_PREFIX "${PROJECT_SOURCE_DIR}/external")
set_directory_properties(PROPERTIES
EP_PREFIX ${EP_PREFIX}
)

# Project dependencies.
find_package(Threads REQUIRED)

################################
# protobuf #
################################
option(FIND_PROTOBUF "Try to find protobuf in system" ON)
find_package(protobuf)

##########################
# boost #
##########################
find_package(Boost 1.65.0 REQUIRED)
add_library(boost INTERFACE IMPORTED)
set_target_properties(boost PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS}
)

###################################
# ed25519/sha3 #
###################################
find_package(ed25519)

##########################
# gtest #
##########################
# testing is an option. Look at the main CMakeLists.txt for details.
if (TESTING)
find_package(gtest)
endif ()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_library(hash
)

target_link_libraries(hash
common
ed25519
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "interfaces/base/primitive.hpp"
#include "interfaces/common_objects/account_asset.hpp"
#include "interfaces/common_objects/types.hpp"
#include "model/queries/responses/account_detail_response.hpp"
#include "utils/string_builder.hpp"
#include "utils/visitor_apply_for_all.hpp"

Expand Down
7 changes: 7 additions & 0 deletions shared_model/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test_bin)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../../test
)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../test/module/shared_model shared_model_test)
1 change: 0 additions & 1 deletion test/module/shared_model/backend_proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ target_link_libraries(shared_proto_transaction_test
shared_model_proto_backend
shared_model_cryptography
shared_model_stateless_validation
iroha_amount
)

addtest(shared_proto_queries_test
Expand Down

0 comments on commit 2f7e92a

Please sign in to comment.