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-format #932

Merged
merged 4 commits into from
Mar 27, 2023
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
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ commands:
name: "Format"
working_directory: ~/project
command: |
cmake -P cmake/format.cmake
pip install --user cmake-format==0.6.13
export "PATH=$HOME/.local/bin:$PATH"
make fmt
if ! git diff --exit-code
then
echo "The formatting style is not compliant. Try to run: cmake -P cmake/format.cmake locally and push the changes"
echo "The formatting style is not compliant. Try to run: 'make fmt' locally and push the changes"
exit 1
fi
- run:
Expand Down
102 changes: 60 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ if(CONAN_PACKAGE_MANAGER) # CMAKE CONAN START
set(CONAN_BINARY_DIR "${CMAKE_BINARY_DIR}/conan")
list(APPEND CMAKE_MODULE_PATH ${CONAN_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CONAN_BINARY_DIR})

if(NOT EXISTS "${CONAN_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
"${CONAN_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
"${CONAN_BINARY_DIR}/conan.cmake" TLS_VERIFY ON
)
endif()

include(${CONAN_BINARY_DIR}/conan.cmake)

# provide a static conanfile.txt instead of generating it with conan_cmake_configure()
Expand All @@ -42,10 +42,12 @@ if(CONAN_PACKAGE_MANAGER) # CMAKE CONAN START
message(FATAL_ERROR "CONAN_PROFILE is not defined")
else()
message(STATUS "CONAN_PROFILE: ${CONAN_PROFILE}")
conan_cmake_install(PATH_OR_REFERENCE "${CONAN_BINARY_DIR}"
INSTALL_FOLDER "${CONAN_BINARY_DIR}"
BUILD missing
PROFILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE})
conan_cmake_install(
PATH_OR_REFERENCE "${CONAN_BINARY_DIR}"
INSTALL_FOLDER "${CONAN_BINARY_DIR}"
BUILD missing
PROFILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/profiles/${CONAN_PROFILE}
)
endif()
endif() # CMAKE CONAN END

Expand All @@ -60,7 +62,10 @@ if(NOT SILKWORM_HAS_PARENT)
cable_set_build_type(DEFAULT Release CONFIGURATION_TYPES Release Debug)

if(NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain/cxx20.cmake CACHE FILEPATH "" FORCE)
set(CMAKE_TOOLCHAIN_FILE
${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain/cxx20.cmake
CACHE FILEPATH "" FORCE
)
endif()

if(CONAN_PACKAGE_MANAGER)
Expand All @@ -71,7 +76,7 @@ if(NOT SILKWORM_HAS_PARENT)

include(third_party/evmone/cmake/cable/HunterGate.cmake)
# https://github.com/cpp-pm/hunter/releases/
HunterGate(
huntergate(
URL "https://github.com/cpp-pm/hunter/archive/v0.24.15.tar.gz"
SHA1 "8010d63d5ae611c564889d5fe12d3cb7a45703ac"
FILEPATH "${HUNTER_CONFIG_PATH}"
Expand Down Expand Up @@ -146,7 +151,7 @@ if(NOT SILKWORM_CORE_ONLY)

# CBOR
add_subdirectory(third_party/cbor-cpp)

# GLAZE
add_subdirectory(third_party/glaze)
endif()
Expand All @@ -156,37 +161,46 @@ if(SILKWORM_WASM_API)
add_compile_definitions(EVMC_LOADER_MOCK)
endif()

find_package(intx REQUIRED) # Required from here below
find_package(intx REQUIRED) # Required from here below
find_package(ethash REQUIRED) # Required from here below

add_subdirectory(third_party/evmone/evmc)

add_library(evmone third_party/evmone/lib/evmone/advanced_analysis.cpp
third_party/evmone/lib/evmone/advanced_analysis.hpp
third_party/evmone/lib/evmone/advanced_execution.cpp
third_party/evmone/lib/evmone/advanced_execution.hpp
third_party/evmone/lib/evmone/advanced_instructions.cpp
third_party/evmone/lib/evmone/baseline_instruction_table.cpp
third_party/evmone/lib/evmone/baseline_instruction_table.hpp
third_party/evmone/lib/evmone/baseline.cpp
third_party/evmone/lib/evmone/baseline.hpp
third_party/evmone/lib/evmone/eof.cpp
third_party/evmone/lib/evmone/eof.hpp
third_party/evmone/lib/evmone/execution_state.hpp
third_party/evmone/lib/evmone/instructions_calls.cpp
third_party/evmone/lib/evmone/instructions_opcodes.hpp
third_party/evmone/lib/evmone/instructions_storage.cpp
third_party/evmone/lib/evmone/instructions_traits.hpp
third_party/evmone/lib/evmone/instructions_xmacro.hpp
third_party/evmone/lib/evmone/instructions.hpp
third_party/evmone/lib/evmone/opcodes_helpers.h
third_party/evmone/lib/evmone/tracing.cpp
third_party/evmone/lib/evmone/tracing.hpp
third_party/evmone/lib/evmone/vm.cpp
third_party/evmone/lib/evmone/vm.hpp)
set_source_files_properties(third_party/evmone/lib/evmone/vm.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="0.10.0-dev")
add_library(
evmone
third_party/evmone/lib/evmone/advanced_analysis.cpp
third_party/evmone/lib/evmone/advanced_analysis.hpp
third_party/evmone/lib/evmone/advanced_execution.cpp
third_party/evmone/lib/evmone/advanced_execution.hpp
third_party/evmone/lib/evmone/advanced_instructions.cpp
third_party/evmone/lib/evmone/baseline_instruction_table.cpp
third_party/evmone/lib/evmone/baseline_instruction_table.hpp
third_party/evmone/lib/evmone/baseline.cpp
third_party/evmone/lib/evmone/baseline.hpp
third_party/evmone/lib/evmone/eof.cpp
third_party/evmone/lib/evmone/eof.hpp
third_party/evmone/lib/evmone/execution_state.hpp
third_party/evmone/lib/evmone/instructions_calls.cpp
third_party/evmone/lib/evmone/instructions_opcodes.hpp
third_party/evmone/lib/evmone/instructions_storage.cpp
third_party/evmone/lib/evmone/instructions_traits.hpp
third_party/evmone/lib/evmone/instructions_xmacro.hpp
third_party/evmone/lib/evmone/instructions.hpp
third_party/evmone/lib/evmone/opcodes_helpers.h
third_party/evmone/lib/evmone/tracing.cpp
third_party/evmone/lib/evmone/tracing.hpp
third_party/evmone/lib/evmone/vm.cpp
third_party/evmone/lib/evmone/vm.hpp
)
set_source_files_properties(
third_party/evmone/lib/evmone/vm.cpp PROPERTIES COMPILE_DEFINITIONS PROJECT_VERSION="0.10.0-dev"
)
target_include_directories(evmone PUBLIC third_party/evmone/include third_party/evmone/lib)
target_link_libraries(evmone PUBLIC evmc intx::intx PRIVATE evmc::instructions)
target_link_libraries(
evmone
PUBLIC evmc intx::intx
PRIVATE evmc::instructions
)

if(MSVC)
target_compile_options(evmone PRIVATE /EHsc /w)
Expand All @@ -205,17 +219,21 @@ if(NOT MSVC)
set(GMP_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gmplib")
set(GMP_INSTALL_DIR "${CMAKE_BINARY_DIR}/third_party/gmplib")

set(GMP_INCLUDE_DIR "${GMP_INSTALL_DIR}" CACHE PATH "")
set(GMP_LIBRARY "${GMP_INSTALL_DIR}/lib/libgmp.a" CACHE FILEPATH "")
set(GMP_INCLUDE_DIR
"${GMP_INSTALL_DIR}"
CACHE PATH ""
)
set(GMP_LIBRARY
"${GMP_INSTALL_DIR}/lib/libgmp.a"
CACHE FILEPATH ""
)

include(ExternalProject)
ExternalProject_Add(
gmplib
SOURCE_DIR "${GMP_SOURCE_DIR}"
BINARY_DIR "${GMP_INSTALL_DIR}"
CONFIGURE_COMMAND "${GMP_SOURCE_DIR}/configure"
"--prefix=${GMP_INSTALL_DIR}"
--with-pic=yes
CONFIGURE_COMMAND "${GMP_SOURCE_DIR}/configure" "--prefix=${GMP_INSTALL_DIR}" --with-pic=yes
PREFIX "${GMP_INSTALL_DIR}"
BUILD_BYPRODUCTS "${GMP_LIBRARY}"
)
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

help:
@echo "Targets:"
@echo "make fmt - reformat everything using clang-format"
@echo "make fmt - reformat the code"
@echo "make lint - run code checks"

fmt:
@cmake -P cmake/cmake_format.cmake
@cmake -P cmake/format.cmake

lint_copyright:
Expand Down
4 changes: 4 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
limitations under the License.
]]

# cmake-format: off

include(hunter_cmake_args)

hunter_cmake_args(
Expand Down Expand Up @@ -82,3 +84,5 @@ hunter_config(
VERSION 0.6.0
CMAKE_ARGS JWT_DISABLE_PICOJSON=ON JWT_BUILD_EXAMPLES=OFF
)

# cmake-format: on
39 changes: 39 additions & 0 deletions cmake/cmake_format.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[[
Copyright 2023 The Silkworm Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]

find_program(CMAKE_FORMAT cmake-format)
if(NOT EXISTS "${CMAKE_FORMAT}")
message(FATAL_ERROR "'cmake-format' command not found in PATH. Please install it using:\n\t"
"pip3 install --user cmake-format==0.6.13"
)
endif()

cmake_policy(SET CMP0009 NEW)
file(
GLOB_RECURSE SRC
LIST_DIRECTORIES false
"cmake/*.cmake"
"cmake/CMakeLists.txt"
"cmd/*.cmake"
"cmd/CMakeLists.txt"
"examples/*.cmake"
"examples/CMakeLists.txt"
"silkworm/*.cmake"
"silkworm/CMakeLists.txt"
)
list(PREPEND SRC "${CMAKE_CURRENT_LIST_DIR}/../CMakeLists.txt")

execute_process(COMMAND "${CMAKE_FORMAT}" --in-place "--config-file=${CMAKE_CURRENT_LIST_DIR}/cmake_format.yaml" ${SRC})
34 changes: 34 additions & 0 deletions cmake/cmake_format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
parse:
additional_commands:
conan_cmake_install:
kwargs:
PATH_OR_REFERENCE: '*'
INSTALL_FOLDER: '*'
BUILD: '*'
PROFILE: '*'
huntergate:
kwargs:
URL: '*'
SHA1: '*'
FILEPATH: '*'
hunter_config:
kwargs:
VERSION: '*'
CMAKE_ARGS: '*'
URL: '*'
SHA1: '*'
hunter_cmake_args:
kwargs:
CMAKE_ARGS: '*'

format:
line_width: 120
tab_size: 2
max_subgroups_hwrap: 2
max_pargs_hwrap: 5
dangle_parens: true
always_wrap:
- hunter_cmake_args

markup:
first_comment_is_literal: true
10 changes: 7 additions & 3 deletions cmake/compiler_settings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
limitations under the License.
]]

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# cmake-format: off

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

message("MSVC_VERSION = ${MSVC_VERSION}")
message("MSVC_CXX_ARCHITECTURE_ID = ${MSVC_CXX_ARCHITECTURE_ID}")
Expand Down Expand Up @@ -113,8 +115,10 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang$")
link_libraries(c++abi)
endif()

else ()
else()

message(WARNING "${CMAKE_CXX_COMPILER_ID} is not tested. Should you stumble into any issue please report at https://github.com/torquem-ch/silkworm/issues")
message(WARNING "${CMAKE_CXX_COMPILER_ID} is not tested. Should you stumble into any issue please report at https://github.com/torquem-ch/silkworm/issues")

endif()

# cmake-format: on
28 changes: 14 additions & 14 deletions cmake/copyright.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
limitations under the License.
]]

SET(COPYRIGHT_HEADER
"/*
set(COPYRIGHT_HEADER
"/*
Copyright 2022 The Silkworm Authors

Licensed under the Apache License, Version 2.0 (the \"License\");
Expand All @@ -30,25 +30,25 @@ SET(COPYRIGHT_HEADER
See the License for the specific language governing permissions and
limitations under the License.
*/
")
"
)

function(check file_path)
string(LENGTH "${COPYRIGHT_HEADER}" header_len)
file(READ "${file_path}" header LIMIT ${header_len})
string(LENGTH "${COPYRIGHT_HEADER}" header_len)
file(READ "${file_path}" header LIMIT ${header_len})

string(REPLACE "2022" "2023" COPYRIGHT_HEADER_23 "${COPYRIGHT_HEADER}")
string(REPLACE "2022" "2023" COPYRIGHT_HEADER_23 "${COPYRIGHT_HEADER}")

if(NOT ((header STREQUAL COPYRIGHT_HEADER) OR (header STREQUAL COPYRIGHT_HEADER_23)))
message(SEND_ERROR "${file_path}: the copyright header differs from the other files")
endif()
if(NOT ((header STREQUAL COPYRIGHT_HEADER) OR (header STREQUAL COPYRIGHT_HEADER_23)))
message(SEND_ERROR "${file_path}: the copyright header differs from the other files")
endif()
endfunction()

cmake_policy(SET CMP0009 NEW)
file(
GLOB_RECURSE SRC
LIST_DIRECTORIES false
"cmd/*.?pp"
"silkworm/*.?pp"
GLOB_RECURSE SRC
LIST_DIRECTORIES false
"cmd/*.?pp" "silkworm/*.?pp"
)
list(FILTER SRC EXCLUDE REGEX "silkworm/core/chain/genesis_[a-z]+\\.cpp\$")
list(FILTER SRC EXCLUDE REGEX "silkworm/core/common/lru_cache(_test)?\\..pp\$")
Expand All @@ -58,5 +58,5 @@ list(FILTER SRC EXCLUDE REGEX "silkworm/node/common/preverified_hashes_[a-z]+\\.
list(FILTER SRC EXCLUDE REGEX "silkworm/node/snapshot/config/[a-z_]+.cpp\$")

foreach(F IN LISTS SRC)
check("${F}")
check("${F}")
endforeach()
Loading