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

Extend the contract build cmake script to include custom libraries and headers #496

Merged
merged 2 commits into from
Sep 16, 2024
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
29 changes: 22 additions & 7 deletions contracts/wawaka/contract-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,41 @@ LIST(APPEND WASM_LIBRARIES "${WASI_SDK_DIR}/share/wasi-sysroot/lib/wasm32-wasi/l
## -----------------------------------------------------------------
# Define the function for building contracts
#
# Intention is that the contract writer add to the WASM_BUILD_OPTIONS,
# Parameters:
# SRC -- contract source, implicit
# PLUGINS -- list of files to be installed in the plugins directory
# SCRIPTS -- list of files to be installed in the script directory
# HEADERS -- list of directories to be included in the build path
# LIBRARIES -- list of additional libraries to be included during link
#
# Intention is that the contract writer can configure options across
# all contracts by extending the WASM_BUILD_OPTIONS,
# WASM_LINK_OPTIONS, WASM_INCLUDES and WASM_LIBRARIES to add custom
# files and link options
# files and link options.
## -----------------------------------------------------------------
FUNCTION(BUILD_CONTRACT contract)
STRING(REPLACE ";" " " WASM_BUILD_OPTIONS "${WASM_BUILD_OPTIONS}")
STRING(REPLACE ";" " " WASM_LINK_OPTIONS "${WASM_LINK_OPTIONS}")
STRING(REPLACE ";" " " LOCAL_BUILD_OPTIONS "${WASM_BUILD_OPTIONS}")
STRING(REPLACE ";" " " LOCAL_LINK_OPTIONS "${WASM_LINK_OPTIONS}")

SET(MultiValueArgs SRC PLUGINS SCRIPTS)
SET(MultiValueArgs SRC PLUGINS SCRIPTS HEADERS LIBRARIES)
CMAKE_PARSE_ARGUMENTS(BC "" "" "${MultiValueArgs}" ${ARGN})

SET(BC_SRC ${BC_SRC} ${BC_UNPARSED_ARGUMENTS})

ADD_EXECUTABLE( ${contract} ${BC_SRC})

SET(CMAKE_CXX_FLAGS ${WASM_BUILD_OPTIONS} CACHE INTERNAL "")
SET(CMAKE_CXX_FLAGS ${LOCAL_BUILD_OPTIONS} CACHE INTERNAL "")
SET(CMAKE_CXX_COMPILER_TARGET "wasm32-wasi")

TARGET_INCLUDE_DIRECTORIES(${contract} PUBLIC ${WASM_INCLUDES})
IF (DEFINED BC_HEADERS)
TARGET_INCLUDE_DIRECTORIES(${contract} PUBLIC ${BC_HEADERS})
ENDIF()

TARGET_LINK_LIBRARIES(${contract} LINK_PUBLIC ${WASM_LIBRARIES})
IF (DEFINED BC_LIBRARIES)
TARGET_LINK_LIBRARIES(${contract} LINK_PUBLIC ${BC_LIBRARIES})
ENDIF()

SET(b64contract ${CMAKE_CURRENT_BINARY_DIR}/_${contract}.b64)
ADD_CUSTOM_COMMAND(
Expand All @@ -104,7 +119,7 @@ FUNCTION(BUILD_CONTRACT contract)
SET_DIRECTORY_PROPERTIES(PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${b64contract})

# this can be replaced in later versions of CMAKE with target_link_options
SET_PROPERTY(TARGET ${contract} APPEND_STRING PROPERTY LINK_FLAGS "${WASM_LINK_OPTIONS}")
SET_PROPERTY(TARGET ${contract} APPEND_STRING PROPERTY LINK_FLAGS "${LOCAL_LINK_OPTIONS}")
INSTALL(FILES ${b64contract} DESTINATION ${CONTRACT_INSTALL_DIRECTORY})
INSTALL(FILES ${BC_PLUGINS} DESTINATION ${CONTRACT_INSTALL_DIRECTORY}/plugins)
INSTALL(FILES ${BC_SCRIPTS} DESTINATION ${CONTRACT_INSTALL_DIRECTORY}/scripts)
Expand Down
10 changes: 9 additions & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ PDO_USER_UID ?= $(shell id -u)
PDO_GROUP_UID ?= $(shell id -g)

DOCKER_COMMAND ?= docker
DOCKER_COMPOSE_COMMAND ?= docker-compose

ifndef DOCKER_COMPOSE_COMMAND
DOCKER_COMPOSE_COMMAND := $(shell command -v docker-compose 2> /dev/null)
ifndef DOCKER_COMPOSE_COMMAND
$(warning "docker-compose command is not available")
DOCKER_COMPOSE_COMMAND := $(DOCKER_COMMAND) compose
endif
endif

# to work with upstream docker and docker compose plugin, redefine above
# as `DOCKER_COMPOSE_COMMAND=docker compose` in your `make.loc`

Expand Down
Loading