|
| 1 | +diff --git a/CMakeLists.txt b/CMakeLists.txt |
| 2 | +index 1111111..2222222 100644 |
| 3 | +--- a/CMakeLists.txt |
| 4 | ++++ b/CMakeLists.txt |
| 5 | +@@ -186,6 +186,59 @@ endif() |
| 6 | + include(Helper) |
| 7 | + include(GNUInstallDirs) |
| 8 | + |
| 9 | ++# When building under Bazel with rules_foreign_cc, dependencies are provided via EXT_BUILD_DEPS |
| 10 | ++# EXT_BUILD_DEPS environment variable contains the path to the merged dependency directory |
| 11 | ++# created by rules_foreign_cc, with headers in include/ and libraries in lib/ |
| 12 | ++# All dependencies listed in the cmake() rule's deps attribute are merged into a single directory structure |
| 13 | ++# Create IMPORTED targets for fmt and spdlog to prevent CMake FetchContent from trying to download them |
| 14 | ++if(DEFINED ENV{EXT_BUILD_DEPS}) |
| 15 | ++ set(BAZEL_EXT_BUILD_DEPS "$ENV{EXT_BUILD_DEPS}") |
| 16 | ++ message(STATUS "Bazel build detected, using dependencies from: ${BAZEL_EXT_BUILD_DEPS}") |
| 17 | ++ |
| 18 | ++ # Create fmt::fmt IMPORTED target |
| 19 | ++ # fmt is a library with compiled sources (not header-only) |
| 20 | ++ if(NOT TARGET fmt::fmt AND EXISTS "${BAZEL_EXT_BUILD_DEPS}/include/fmt") |
| 21 | ++ # Look for the fmt library file |
| 22 | ++ find_library(FMT_LIBRARY |
| 23 | ++ NAMES fmt libfmt |
| 24 | ++ PATHS "${BAZEL_EXT_BUILD_DEPS}/lib" |
| 25 | ++ NO_DEFAULT_PATH |
| 26 | ++ ) |
| 27 | ++ |
| 28 | ++ if(FMT_LIBRARY) |
| 29 | ++ # Create STATIC IMPORTED library |
| 30 | ++ add_library(fmt::fmt STATIC IMPORTED) |
| 31 | ++ set_target_properties(fmt::fmt PROPERTIES |
| 32 | ++ IMPORTED_LOCATION "${FMT_LIBRARY}" |
| 33 | ++ INTERFACE_INCLUDE_DIRECTORIES "${BAZEL_EXT_BUILD_DEPS}/include" |
| 34 | ++ ) |
| 35 | ++ message(STATUS "Created fmt::fmt IMPORTED target from Bazel deps: ${FMT_LIBRARY}") |
| 36 | ++ else() |
| 37 | ++ message(WARNING "fmt headers found at ${BAZEL_EXT_BUILD_DEPS}/include/fmt but compiled library not found in ${BAZEL_EXT_BUILD_DEPS}/lib. Check that fmt dependency is properly configured in Bazel BUILD file.") |
| 38 | ++ endif() |
| 39 | ++ |
| 40 | ++ # Create non-namespaced alias for backward compatibility with code that references fmt without the namespace |
| 41 | ++ if(TARGET fmt::fmt) |
| 42 | ++ add_library(fmt ALIAS fmt::fmt) |
| 43 | ++ endif() |
| 44 | ++ endif() |
| 45 | ++ |
| 46 | ++ # Create spdlog::spdlog IMPORTED target |
| 47 | ++ # spdlog is header-only when using external fmt |
| 48 | ++ if(NOT TARGET spdlog::spdlog AND EXISTS "${BAZEL_EXT_BUILD_DEPS}/include/spdlog") |
| 49 | ++ add_library(spdlog::spdlog INTERFACE IMPORTED) |
| 50 | ++ set_target_properties(spdlog::spdlog PROPERTIES |
| 51 | ++ INTERFACE_INCLUDE_DIRECTORIES "${BAZEL_EXT_BUILD_DEPS}/include" |
| 52 | ++ INTERFACE_COMPILE_DEFINITIONS "SPDLOG_FMT_EXTERNAL" |
| 53 | ++ ) |
| 54 | ++ # spdlog depends on fmt |
| 55 | ++ if(TARGET fmt::fmt) |
| 56 | ++ set_property(TARGET spdlog::spdlog APPEND PROPERTY INTERFACE_LINK_LIBRARIES fmt::fmt) |
| 57 | ++ endif() |
| 58 | ++ message(STATUS "Created spdlog::spdlog IMPORTED target from Bazel deps") |
| 59 | ++ endif() |
| 60 | ++endif() |
| 61 | ++ |
| 62 | + set(CPACK_PACKAGE_VENDOR Second State LLC) |
| 63 | + set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}") |
| 64 | + set(CPACK_STRIP_FILES ON) |
| 65 | +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt |
| 66 | +index 1111111..2222222 100644 |
| 67 | +--- a/include/CMakeLists.txt |
| 68 | ++++ b/include/CMakeLists.txt |
| 69 | +@@ -39,6 +39,8 @@ configure_file(common/enum_configure.h api/wasmedge/enum_configure.h COPYONLY) |
| 70 | + configure_file(common/enum_errcode.h api/wasmedge/enum_errcode.h COPYONLY) |
| 71 | + configure_file(common/enum_types.h api/wasmedge/enum_types.h COPYONLY) |
| 72 | + configure_file(common/version.h.in common/version.h) |
| 73 | ++install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/api/wasmedge |
| 74 | ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 75 | + unset(WASMEDGE_VERSION_STRING) |
| 76 | + unset(WASMEDGE_VERSION_LIST) |
| 77 | + unset(WASMEDGE_VERSION_MAJOR) |
| 78 | +diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt |
| 79 | +index 1111111..2222222 100644 |
| 80 | +--- a/lib/api/CMakeLists.txt |
| 81 | ++++ b/lib/api/CMakeLists.txt |
| 82 | +@@ -151,8 +151,15 @@ if(WASMEDGE_BUILD_SHARED_LIB) |
| 83 | + endif() |
| 84 | + |
| 85 | + if(WASMEDGE_BUILD_STATIC_LIB) |
| 86 | +- wasmedge_add_static_lib_component_command(fmt::fmt) |
| 87 | +- wasmedge_add_static_lib_component_command(spdlog::spdlog) |
| 88 | ++ # When using Bazel, skip packaging fmt/spdlog into libwasmedge.a |
| 89 | ++ # Bazel will handle linking these dependencies directly from the deps attribute |
| 90 | ++ # This allows fmt to be either static or shared, and avoids the need to extract |
| 91 | ++ # object files from libraries (which fails for shared libraries) |
| 92 | ++ if(NOT DEFINED ENV{EXT_BUILD_DEPS}) |
| 93 | ++ # In non-Bazel builds, package fmt and spdlog into the static library |
| 94 | ++ wasmedge_add_static_lib_component_command(fmt::fmt) |
| 95 | ++ wasmedge_add_static_lib_component_command(spdlog::spdlog) |
| 96 | ++ endif() |
| 97 | + wasmedge_add_static_lib_component_command(wasmedgeSystem) |
| 98 | + wasmedge_add_static_lib_component_command(wasmedgeCommon) |
| 99 | + wasmedge_add_static_lib_component_command(wasmedgePO) |
0 commit comments