Update core library to use real wxBase instead of wx_shim
- Update CMakeLists.txt to link against wxBase WASM build - Move config.h to wasm-config/ to avoid conflicts with wx headers - Add build-core-wasm.sh script for reproducible builds - Core now compiles with actual wxString, wxFile, etc. from wxWidgets Libraries built: - libkicad_core_utils.a (34K) - libkimath.a (969K) - libsexpr.a (45K) - libclipper2.a (169K) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d6e946b101
commit
9305aa5afb
3 changed files with 91 additions and 6 deletions
|
|
@ -14,6 +14,32 @@ endif()
|
|||
|
||||
message(STATUS "Using KiCad source at: ${KICAD_SOURCE}")
|
||||
|
||||
# =============================================================================
|
||||
# wxWidgets Base (pre-built for WASM)
|
||||
# =============================================================================
|
||||
set(WXWIDGETS_SOURCE "${CMAKE_SOURCE_DIR}/../wxwidgets" CACHE PATH "Path to wxWidgets source")
|
||||
set(WXWIDGETS_BUILD "${CMAKE_SOURCE_DIR}/../build-wasm/wxwidgets" CACHE PATH "Path to wxWidgets WASM build")
|
||||
|
||||
# Verify wxWidgets build exists
|
||||
if(NOT EXISTS "${WXWIDGETS_BUILD}/lib/libwx_baseu-3.2-Emscripten.a")
|
||||
message(FATAL_ERROR "wxBase WASM build not found. Run scripts/build-wxbase-wasm.sh first")
|
||||
endif()
|
||||
|
||||
# Create imported wxBase library
|
||||
add_library(wxbase STATIC IMPORTED)
|
||||
set_target_properties(wxbase PROPERTIES
|
||||
IMPORTED_LOCATION "${WXWIDGETS_BUILD}/lib/libwx_baseu-3.2-Emscripten.a"
|
||||
)
|
||||
|
||||
# wxWidgets include directories
|
||||
set(WX_INCLUDE_DIRS
|
||||
"${WXWIDGETS_BUILD}/lib/wx/include/base-unicode-static-3.2" # Platform setup.h
|
||||
"${WXWIDGETS_SOURCE}/include" # Main wx headers
|
||||
)
|
||||
|
||||
message(STATUS "Using wxWidgets source at: ${WXWIDGETS_SOURCE}")
|
||||
message(STATUS "Using wxWidgets build at: ${WXWIDGETS_BUILD}")
|
||||
|
||||
# =============================================================================
|
||||
# Options
|
||||
# =============================================================================
|
||||
|
|
@ -45,20 +71,24 @@ target_include_directories(rtree INTERFACE
|
|||
)
|
||||
|
||||
# =============================================================================
|
||||
# Core utilities library (minimal version without wx_stl_compat)
|
||||
# Core utilities library (with wxBase support)
|
||||
# =============================================================================
|
||||
add_library(kicad_core_utils STATIC
|
||||
${KICAD_SOURCE}/libs/core/base64.cpp
|
||||
${KICAD_SOURCE}/libs/core/observable.cpp
|
||||
${KICAD_SOURCE}/libs/core/profile.cpp
|
||||
# Skip utf8.cpp and wx_stl_compat.cpp - they have heavy wx dependencies
|
||||
${KICAD_SOURCE}/libs/core/utf8.cpp
|
||||
${KICAD_SOURCE}/libs/core/wx_stl_compat.cpp
|
||||
)
|
||||
|
||||
target_include_directories(kicad_core_utils PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm-config # config.h for WASM build
|
||||
${WX_INCLUDE_DIRS}
|
||||
${KICAD_SOURCE}/libs/core/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include # For wx_shim.h
|
||||
)
|
||||
|
||||
target_link_libraries(kicad_core_utils PUBLIC wxbase)
|
||||
|
||||
# =============================================================================
|
||||
# S-expression library (parser for .kicad_pcb files)
|
||||
# =============================================================================
|
||||
|
|
@ -68,9 +98,11 @@ add_library(sexpr STATIC
|
|||
)
|
||||
|
||||
target_include_directories(sexpr PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include # wx_shim.h - FIRST!
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wasm-config # config.h for WASM build
|
||||
${WX_INCLUDE_DIRS}
|
||||
${KICAD_SOURCE}/libs/sexpr/include
|
||||
${KICAD_SOURCE}/libs/core/include
|
||||
${KICAD_SOURCE}/include # string_utils.h, etc.
|
||||
)
|
||||
|
||||
target_link_libraries(sexpr PUBLIC kicad_core_utils)
|
||||
|
|
@ -121,7 +153,7 @@ set(KIMATH_SRCS
|
|||
add_library(kimath STATIC ${KIMATH_SRCS})
|
||||
|
||||
target_include_directories(kimath PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include # wx_shim.h and wx/ stubs - FIRST!
|
||||
${WX_INCLUDE_DIRS}
|
||||
${KICAD_SOURCE}/libs/kimath/include
|
||||
${KICAD_SOURCE}/libs/core/include
|
||||
${KICAD_SOURCE}/include # Main KiCad includes (units, etc.)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
// Platform detection for timing functions
|
||||
#if defined(_WIN32)
|
||||
// Windows uses GetSystemTimeAsFileTime
|
||||
#elif defined(__APPLE__) || defined(__linux__) || defined(__unix__)
|
||||
#elif defined(__EMSCRIPTEN__) || defined(__APPLE__) || defined(__linux__) || defined(__unix__)
|
||||
#define HAVE_CLOCK_GETTIME 1
|
||||
#else
|
||||
#define HAVE_GETTIMEOFDAY_FUNC 1
|
||||
53
scripts/build-core-wasm.sh
Executable file
53
scripts/build-core-wasm.sh
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
# Build KiCad core library for WebAssembly
|
||||
# This builds kimath, sexpr, and core utilities with wxBase
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
BUILD_DIR="$PROJECT_ROOT/build-wasm/core"
|
||||
CORE_SOURCE="$PROJECT_ROOT/core"
|
||||
|
||||
echo "=== Building KiCad Core for WASM ==="
|
||||
echo "Project root: $PROJECT_ROOT"
|
||||
echo "Build dir: $BUILD_DIR"
|
||||
echo "Core source: $CORE_SOURCE"
|
||||
|
||||
# Verify core source exists
|
||||
if [ ! -f "$CORE_SOURCE/CMakeLists.txt" ]; then
|
||||
echo "ERROR: Core source not found at $CORE_SOURCE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify wxBase was built
|
||||
if [ ! -f "$PROJECT_ROOT/build-wasm/wxwidgets/lib/libwx_baseu-3.2-Emscripten.a" ]; then
|
||||
echo "ERROR: wxBase not built. Run scripts/build-wxbase-wasm.sh first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean if requested (must be before mkdir to properly reset CMake cache)
|
||||
if [ "$1" = "--clean" ]; then
|
||||
echo "Cleaning build directory..."
|
||||
rm -rf "$BUILD_DIR"
|
||||
fi
|
||||
|
||||
# Create build directory
|
||||
mkdir -p "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
# Configure with emcmake
|
||||
echo ""
|
||||
echo "=== Configuring ==="
|
||||
emcmake cmake "$CORE_SOURCE" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_TESTS=OFF
|
||||
|
||||
# Build
|
||||
echo ""
|
||||
echo "=== Building ==="
|
||||
emmake make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
|
||||
|
||||
echo ""
|
||||
echo "=== Build complete ==="
|
||||
ls -lh "$BUILD_DIR"/*.a 2>/dev/null || echo "Libraries built in $BUILD_DIR"
|
||||
Loading…
Reference in a new issue