Skip to content

Commit

Permalink
Merge pull request #36 from AntelopeIO/add_cmake_leap&cdt_version_checks
Browse files Browse the repository at this point in the history
add `SYSTEM_ENABLE_LEAP_VERSION_CHECK` & `SYSTEM_ENABLE_CDT_VERSION_CHECK` build knobs
  • Loading branch information
spoonincode authored Dec 22, 2023
2 parents a199ba0 + aad1544 commit 10bab0c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ option(SYSTEM_CONFIGURABLE_WASM_LIMITS
option(SYSTEM_BLOCKCHAIN_PARAMETERS
"Enables use of the host functions activated by the BLOCKCHAIN_PARAMETERS protocol feature" ON)

option(SYSTEM_ENABLE_LEAP_VERSION_CHECK
"Enables a configure-time check that the version of Leap's tester library is compatible with this project's unit tests" ON)

option(SYSTEM_ENABLE_CDT_VERSION_CHECK
"Enables a configure-time check that the version of CDT is compatible with this project's contracts" ON)

ExternalProject_Add(
contracts_project
SOURCE_DIR ${CMAKE_SOURCE_DIR}/contracts
Expand Down
34 changes: 18 additions & 16 deletions contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ set(CDT_VERSION_SOFT_MAX "4.0")
# set(CDT_VERSION_HARD_MAX "")

# Check the version of CDT
set(VERSION_MATCH_ERROR_MSG "")
CDT_CHECK_VERSION(VERSION_OUTPUT "${CDT_VERSION}" "${CDT_VERSION_MIN}" "${CDT_VERSION_SOFT_MAX}"
"${CDT_VERSION_HARD_MAX}" VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using CDT version ${CDT_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(
WARNING
"Using CDT version ${CDT_VERSION} even though it exceeds the maximum supported version of ${CDT_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use CDT version ${CDT_VERSION_SOFT_MAX}.x"
)
else() # INVALID OR MISMATCH
message(
FATAL_ERROR
"Found CDT version ${CDT_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use CDT version ${CDT_VERSION_SOFT_MAX}.x"
)
endif(VERSION_OUTPUT STREQUAL "MATCH")
if(SYSTEM_ENABLE_CDT_VERSION_CHECK)
set(VERSION_MATCH_ERROR_MSG "")
CDT_CHECK_VERSION(VERSION_OUTPUT "${CDT_VERSION}" "${CDT_VERSION_MIN}" "${CDT_VERSION_SOFT_MAX}"
"${CDT_VERSION_HARD_MAX}" VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using CDT version ${CDT_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(
WARNING
"Using CDT version ${CDT_VERSION} even though it exceeds the maximum supported version of ${CDT_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use CDT version ${CDT_VERSION_SOFT_MAX}.x"
)
else() # INVALID OR MISMATCH
message(
FATAL_ERROR
"Found CDT version ${CDT_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use CDT version ${CDT_VERSION_SOFT_MAX}.x"
)
endif(VERSION_OUTPUT STREQUAL "MATCH")
endif()

set(ICON_BASE_URL "https://raw.githubusercontent.com/AntelopeIO/reference-contracts/main/contracts/icons")

Expand Down
34 changes: 18 additions & 16 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ set(EOSIO_VERSION_SOFT_MAX "4.1")
find_package(leap)

# Check the version of Leap
set(VERSION_MATCH_ERROR_MSG "")
eosio_check_version(VERSION_OUTPUT "${EOSIO_VERSION}" "${EOSIO_VERSION_MIN}" "${EOSIO_VERSION_SOFT_MAX}"
"${EOSIO_VERSION_HARD_MAX}" VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using Leap version ${EOSIO_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(
WARNING
"Using Leap version ${EOSIO_VERSION} even though it exceeds the maximum supported version of ${EOSIO_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use Leap version ${EOSIO_VERSION_SOFT_MAX}.x"
)
else() # INVALID OR MISMATCH
message(
FATAL_ERROR
"Found Leap version ${EOSIO_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use Leap version ${EOSIO_VERSION_SOFT_MAX}.x"
)
endif(VERSION_OUTPUT STREQUAL "MATCH")
if(SYSTEM_ENABLE_LEAP_VERSION_CHECK)
set(VERSION_MATCH_ERROR_MSG "")
eosio_check_version(VERSION_OUTPUT "${EOSIO_VERSION}" "${EOSIO_VERSION_MIN}" "${EOSIO_VERSION_SOFT_MAX}"
"${EOSIO_VERSION_HARD_MAX}" VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using Leap version ${EOSIO_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(
WARNING
"Using Leap version ${EOSIO_VERSION} even though it exceeds the maximum supported version of ${EOSIO_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use Leap version ${EOSIO_VERSION_SOFT_MAX}.x"
)
else() # INVALID OR MISMATCH
message(
FATAL_ERROR
"Found Leap version ${EOSIO_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use Leap version ${EOSIO_VERSION_SOFT_MAX}.x"
)
endif(VERSION_OUTPUT STREQUAL "MATCH")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/contracts.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/contracts.hpp)

Expand Down

0 comments on commit 10bab0c

Please sign in to comment.