It compiles now
This commit is contained in:
parent
c1c54277a7
commit
642c277388
|
|
@ -4,3 +4,4 @@ build_pico/
|
|||
*.o
|
||||
*.pdb
|
||||
CMakeLists.txt
|
||||
pico_arm_gcc_toolchain.cmake
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ TEST_TARGET = BIN_DIR / "sls_tests"
|
|||
# Platform-specific settings
|
||||
PICO_SDK_PATH = os.environ.get("PICO_SDK_PATH", Path.home() / "pico/pico-sdk")
|
||||
PICO_BUILD_DIR = Path("build_pico")
|
||||
PICO_TOOLCHAIN_PATH = Path("pico_arm_gcc_toolchain.cmake")
|
||||
|
||||
# Unix gcc/clang flags
|
||||
COMMON_FLAGS = ["-std=c99", "-Wall", "-Wextra", "-Werror", "-Iinclude", "-g"]
|
||||
|
|
@ -34,6 +35,33 @@ MACOS_FLAGS = ["-std=c99", "-Wall", "-Wextra", "-Werror", "-Iinclude", "-g",
|
|||
MSVC_FLAGS = ["/std:c11", "/Zi", "/Iinclude"]
|
||||
MSVC_TEST_FLAGS = MSVC_FLAGS + []
|
||||
|
||||
# RP2040 toolchain file template
|
||||
PICO_TOOLCHAIN_TEMPLATE = """set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
|
||||
|
||||
# Specify the cross compiler
|
||||
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
|
||||
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
||||
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
|
||||
|
||||
# Compiler flags for Cortex-M0+
|
||||
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb")
|
||||
set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb")
|
||||
set(CMAKE_ASM_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb")
|
||||
|
||||
# Don't run the linker on compiler check
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
# Adjust the default behavior of the FIND_XXX() commands:
|
||||
# search programs in the host environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
|
||||
# Search headers and libraries in the target environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
"""
|
||||
|
||||
# RP2040 settings
|
||||
RP2040_CMAKE_TEMPLATE = """cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
|
|
@ -52,6 +80,12 @@ add_executable({project_name}
|
|||
{source_files}
|
||||
)
|
||||
|
||||
# Set output name with .elf extension
|
||||
set_target_properties({project_name} PROPERTIES
|
||||
OUTPUT_NAME "{project_name}.elf"
|
||||
SUFFIX ""
|
||||
)
|
||||
|
||||
# Add include directories
|
||||
target_include_directories({project_name} PRIVATE
|
||||
${{CMAKE_CURRENT_LIST_DIR}}/include
|
||||
|
|
@ -247,9 +281,25 @@ def check_pico_sdk():
|
|||
print(f"ERROR: Pico SDK not found at {sdk_path}")
|
||||
print("Please set PICO_SDK_PATH environment variable or install SDK at ~/pico/pico-sdk")
|
||||
return False
|
||||
|
||||
# Check for ARM toolchain
|
||||
if not shutil.which("arm-none-eabi-gcc"):
|
||||
print("ERROR: ARM toolchain not found!")
|
||||
print("Please install arm-none-eabi-gcc:")
|
||||
print(" Ubuntu/Debian: sudo apt install gcc-arm-none-eabi")
|
||||
print(" macOS: brew install arm-none-eabi-gcc")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def generate_pico_toolchain():
|
||||
"""Generate ARM GCC toolchain file for CMake"""
|
||||
with open(PICO_TOOLCHAIN_PATH, "w") as f:
|
||||
f.write(PICO_TOOLCHAIN_TEMPLATE)
|
||||
print(f"Generated {PICO_TOOLCHAIN_PATH}")
|
||||
|
||||
|
||||
def generate_pico_cmake(project_name="sls"):
|
||||
"""Generate CMakeLists.txt for RP2040 build"""
|
||||
sources = list(SRC_DIR.glob("*.c"))
|
||||
|
|
@ -279,17 +329,21 @@ def build_rp2040():
|
|||
|
||||
print("\n=== Building for RP2040 ===\n")
|
||||
|
||||
# Generate toolchain file
|
||||
generate_pico_toolchain()
|
||||
|
||||
# Generate CMakeLists.txt
|
||||
generate_pico_cmake()
|
||||
|
||||
# Create build directory
|
||||
mkdir(PICO_BUILD_DIR)
|
||||
|
||||
# Run CMake (no need to pass PICO_SDK_PATH since it's in CMakeLists.txt)
|
||||
# Run CMake with explicit toolchain
|
||||
cmake_cmd = [
|
||||
"cmake",
|
||||
"-B", str(PICO_BUILD_DIR),
|
||||
"-S", "."
|
||||
"-S", ".",
|
||||
f"-DCMAKE_TOOLCHAIN_FILE={PICO_TOOLCHAIN_PATH}"
|
||||
]
|
||||
run(cmake_cmd)
|
||||
|
||||
|
|
@ -354,6 +408,9 @@ def clean():
|
|||
cmake_file = Path("CMakeLists.txt")
|
||||
if cmake_file.exists():
|
||||
cmake_file.unlink()
|
||||
toolchain_file = PICO_TOOLCHAIN_PATH
|
||||
if toolchain_file.exists():
|
||||
toolchain_file.unlink()
|
||||
print("Cleaned.")
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue