Skip to content

Commit

Permalink
Merge pull request #83 from kabiroberai/kabir/cmake-cli
Browse files Browse the repository at this point in the history
Support building CLI via CMake
  • Loading branch information
kateinoigakukun authored Apr 24, 2024
2 parents c3a08eb + a6154ac commit 3adfdb3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ endif()
# The subdirectory into which host libraries will be installed.
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

set(CMAKE_MACOSX_RPATH YES)

set(BUILD_SHARED_LIBS OFF)

include(AddSwiftHostLibrary)

set(CMAKE_Swift_COMPILER_TARGET ${SWIFT_HOST_TRIPLE})
Expand Down Expand Up @@ -53,5 +55,20 @@ if(NOT SwiftSystem_FOUND)
FetchContent_MakeAvailable(SwiftSystem)
endif()

option(WASMKIT_BUILD_CLI "Build wasmkit-cli" ON)

if(WASMKIT_BUILD_CLI)
set(BUILD_TESTING OFF) # disable ArgumentParser tests
find_package(ArgumentParser CONFIG)
if(NOT ArgumentParser_FOUND)
message("-- Vending ArgumentParser")
FetchContent_Declare(ArgumentParser
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
GIT_TAG 1.2.2
)
FetchContent_MakeAvailable(ArgumentParser)
endif()
endif()

add_subdirectory(Sources)
add_subdirectory(cmake/modules)
10 changes: 10 additions & 0 deletions Sources/CLI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_executable(wasmkit-cli
Run/Run.swift
CLI.swift
)

target_link_wasmkit_libraries(wasmkit-cli PUBLIC
ArgumentParser WasmKitWASI)

install(TARGETS wasmkit-cli
RUNTIME DESTINATION bin)
4 changes: 4 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ add_subdirectory(SystemExtras)
add_subdirectory(WASI)
add_subdirectory(WasmTypes)
add_subdirectory(WasmParser)

if(WASMKIT_BUILD_CLI)
add_subdirectory(CLI)
endif()
2 changes: 1 addition & 1 deletion cmake/modules/AddSwiftHostLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function(add_wasmkit_library name)
install(
DIRECTORY ${module_base}
DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
FILES_MATCHING PATTERN "*.swiftinterface"
FILES_MATCHING PATTERN "*.swiftmodule"
)
else()
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
Expand Down

0 comments on commit 3adfdb3

Please sign in to comment.