Skip to content

Commit

Permalink
Merge pull request #1923 from pmconrad/replace_build_tools
Browse files Browse the repository at this point in the history
Replace build tools
  • Loading branch information
abitmore authored Sep 12, 2019
2 parents ee58819 + 68f40d5 commit d4f8077
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 412 deletions.
13 changes: 9 additions & 4 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

add_custom_target( build_hardfork_hpp
COMMAND cat-parts "${CMAKE_CURRENT_SOURCE_DIR}/hardfork.d" "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" )
set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" PROPERTIES GENERATED TRUE )

add_dependencies( build_hardfork_hpp cat-parts )

file(GLOB HEADERS "include/graphene/chain/*.hpp")

if( GRAPHENE_DISABLE_UNITY_BUILD )
Expand Down Expand Up @@ -82,6 +78,15 @@ if(MSVC)
set_source_files_properties( db_init.cpp db_block.cpp database.cpp block_database.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
endif(MSVC)

# Support for CMake < 3.7
if (${CMAKE_VERSION} VERSION_LESS "3.7.0")
MESSAGE(STATUS "Configuring for legacy CMake (CMake version ${CMAKE_VERSION} older than 3.7.0)")
MESSAGE(STATUS " Target propertes not supported (SOURCE_DIR, BINARY_DIR)")

set(GRAPHENE_CHAIN_BIN_LEGACY "${PROJECT_BINARY_DIR}")
set(GRAPHENE_CHAIN_SOURCE_LEGACY "${PROJECT_SOURCE_DIR}")
endif ()

INSTALL( TARGETS
graphene_chain

Expand Down
50 changes: 20 additions & 30 deletions libraries/egenesis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,47 @@

add_library( graphene_egenesis_none
egenesis_none.cpp
include/graphene/egenesis/egenesis.hpp
)

target_link_libraries( graphene_egenesis_none graphene_chain fc )
target_include_directories( graphene_egenesis_none
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

add_executable( embed_genesis
embed_genesis.cpp
)

target_link_libraries( embed_genesis graphene_chain graphene_app graphene_egenesis_none fc )

set( embed_genesis_args
-t "${CMAKE_CURRENT_SOURCE_DIR}/egenesis_brief.cpp.tmpl---${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp"
-t "${CMAKE_CURRENT_SOURCE_DIR}/egenesis_full.cpp.tmpl---${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp"
)

MESSAGE( STATUS "egenesis: " ${GRAPHENE_EGENESIS_JSON} )
message( STATUS "Generating egenesis" )

if( GRAPHENE_EGENESIS_JSON )
list( APPEND embed_genesis_args --genesis-json "${GRAPHENE_EGENESIS_JSON}" )
set( embed_genesis_args "${GRAPHENE_EGENESIS_JSON}" )
else( GRAPHENE_EGENESIS_JSON )
set( embed_genesis_args "genesis.json" )
endif( GRAPHENE_EGENESIS_JSON )

MESSAGE( STATUS "embed_genesis_args: " ${embed_genesis_args} )

add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp"
"${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND embed_genesis ${embed_genesis_args}
COMMAND ${CMAKE_COMMAND}
-DINIT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
-DINIT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-Dembed_genesis_args=${embed_genesis_args}
-P ${CMAKE_CURRENT_SOURCE_DIR}/embed_genesis.cmake
DEPENDS
"${GRAPHENE_EGENESIS_JSON}"
"${CMAKE_CURRENT_SOURCE_DIR}/egenesis_brief.cpp.tmpl"
"${CMAKE_CURRENT_SOURCE_DIR}/egenesis_full.cpp.tmpl"
embed_genesis )
)

add_library( graphene_egenesis_brief "${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp" include/graphene/egenesis/egenesis.hpp )
add_library( graphene_egenesis_full "${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp" include/graphene/egenesis/egenesis.hpp )
add_library( graphene_egenesis_none egenesis_none.cpp
include/graphene/egenesis/egenesis.hpp )
add_library( graphene_egenesis_brief "${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp"
include/graphene/egenesis/egenesis.hpp )
add_library( graphene_egenesis_full "${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp"
include/graphene/egenesis/egenesis.hpp )

target_link_libraries( graphene_egenesis_none graphene_chain fc )
target_link_libraries( graphene_egenesis_brief graphene_chain fc )
target_link_libraries( graphene_egenesis_full graphene_chain fc )

target_include_directories( graphene_egenesis_none
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
target_include_directories( graphene_egenesis_brief
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
target_include_directories( graphene_egenesis_full
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

INSTALL( TARGETS
embed_genesis graphene_egenesis_none graphene_egenesis_brief graphene_egenesis_full
graphene_egenesis_none graphene_egenesis_brief graphene_egenesis_full

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
Expand Down
7 changes: 3 additions & 4 deletions libraries/egenesis/egenesis_full.cpp.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace graphene { namespace egenesis {

using namespace graphene::chain;

static const char genesis_json_array[${genesis_json_array_height}][${genesis_json_array_width}+1] =
static const char* genesis_json_array[${genesis_json_array_height}] =
{
${genesis_json_array}
};
Expand All @@ -44,11 +44,10 @@ void compute_egenesis_json( std::string& result )
{
result.reserve( ${genesis_json_length} );
result.resize(0);
for( size_t i=0; i<${genesis_json_array_height}-1; i++ )
for( size_t i=0; i<${genesis_json_array_height}; i++ )
{
result.append( genesis_json_array[i], ${genesis_json_array_width} );
result.append( genesis_json_array[i] );
}
result.append( std::string( genesis_json_array[ ${genesis_json_array_height}-1 ] ) );
}

fc::sha256 get_egenesis_json_hash()
Expand Down
34 changes: 34 additions & 0 deletions libraries/egenesis/embed_genesis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
set( CMAKE_CURRENT_SOURCE_DIR ${INIT_SOURCE_DIR} )
set( CMAKE_CURRENT_BINARY_DIR ${INIT_BINARY_DIR} )

file( SHA256 "${embed_genesis_args}" chain_id )
message( STATUS "Generating egenesis" )

message( STATUS "Chain-id: ${chain_id}" )

set( generated_file_banner "/*** GENERATED FILE - DO NOT EDIT! ***/" )
set( genesis_json_hash "${chain_id}" )
configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/egenesis_brief.cpp.tmpl"
"${CMAKE_CURRENT_BINARY_DIR}/egenesis_brief.cpp" )

file( READ "${embed_genesis_args}" genesis_json )
string( LENGTH "${genesis_json}" genesis_json_length )
string( REGEX REPLACE "(\"|\\\\)" "\\\\\\1" genesis_json_escaped "${genesis_json}" )
string( REPLACE "\n" "\\n" genesis_json_escaped "${genesis_json_escaped}" )
string( REPLACE "\t" "\\t" genesis_json_escaped "${genesis_json_escaped}" )

# Split the escaped JSON string into chunks (each less than max string literal length supported by MSVC).
# Chunks must not end with a backslash to avoid splitting escapes.
string( RANDOM LENGTH 10000 _dots )
string( REGEX REPLACE "." "." _dots "${_dots}" )
string( REGEX MATCHALL "(${_dots}(.|..|...)?[^\\\\])" _chunks "${genesis_json_escaped}" )
string( LENGTH "${_chunks}" _chunks_len )
string( REGEX REPLACE ";" "" _seen "${_chunks}" )
string( LENGTH "${_seen}" _seen )
string( SUBSTRING "${genesis_json_escaped}" ${_seen} -1 _rest )
string( REGEX REPLACE ";" "\",\n\"" genesis_json_array "${_chunks}" )
set( genesis_json_array "\"${genesis_json_array}\",\n\"${_rest}\"" )
set( genesis_json_array_height "${_chunks_len} - ${_seen} + 2" )

configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/egenesis_full.cpp.tmpl"
"${CMAKE_CURRENT_BINARY_DIR}/egenesis_full.cpp" )
Loading

0 comments on commit d4f8077

Please sign in to comment.