Skip to content

Add CMake support (Zephyr Module) #177

@yashi

Description

@yashi

Hi @keith-packard,

I've read this pull-request and I'm very much interested in integrating picolibc as a Zephyr module. In order to proceed I'd like to use this issue to gather requirements for building and integrating piocolibc as a Zephyr module.

To kick this off, let me ask a few questions

  • You said in the PR you are happy to integrate CMake files into picolibc. Does it mean picolibc hosts CMakeLists.txt files all over the source tree?

    • CMake is similar to Meson, meaning that there usually a CMakeLists.txt in most of the directories.
    • Unlike Meson, it needs a template file for generating picolibc.h. So it adds yet another file.
    • Unlike Meson, it doesn't need a option file. All options are declared in CMakeLists.txt.
    • I have prepared and attached a minimum change, which builds strnlen()-only picolibc with CMake. Hoping that the diff gives you an idea.
  • Do you want CMake to be as general as Meson, or be specific to Zephyr? I think there are pros and cons for each direction. I'm happy with either way.

    • CMake only for Zephyr (this is simple, can skip unnecessary features, such as multilib or semi hosting, in CMake)
    • CMake as a second build system (this makes it more complex, but aligned with Meson, and someone from non Zephyr community might find it useful)

The following is the minimum change to build strnlen()-only picolibc with CMake, without Zephyr module glue code.

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 000000000..df0c84408
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,19 @@
+project(PICOLIBC)
+cmake_minimum_required(VERSION 3.20)
+
+add_library(picolibc)
+#target_compile_features(picolibc PRIVATE c_std_18)
+target_compile_options(picolibc PRIVATE -Wall -Wextra)
+
+set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel)
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+  message(STATUS "No build type selected, default to MinSizeRel")
+  set(CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "Build Type" FORCE)
+endif()
+
+target_include_directories(picolibc PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+
+#add_subdirectory(dummyhost)
+add_subdirectory(newlib)
+
+configure_file(picolibc.h.in picolibc.h)
diff --git a/newlib/CMakeLists.txt b/newlib/CMakeLists.txt
new file mode 100644
index 000000000..8dd39ad35
--- /dev/null
+++ b/newlib/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(libc)
diff --git a/newlib/libc/CMakeLists.txt b/newlib/libc/CMakeLists.txt
new file mode 100644
index 000000000..a58143cd8
--- /dev/null
+++ b/newlib/libc/CMakeLists.txt
@@ -0,0 +1,2 @@
+target_include_directories(picolibc PUBLIC include)
+add_subdirectory(string)
diff --git a/newlib/libc/string/CMakeLists.txt b/newlib/libc/string/CMakeLists.txt
new file mode 100644
index 000000000..fb0539b66
--- /dev/null
+++ b/newlib/libc/string/CMakeLists.txt
@@ -0,0 +1 @@
+target_sources(picolibc PRIVATE strnlen.c)
diff --git a/picolibc.h.in b/picolibc.h.in
new file mode 100644
index 000000000..e69de29bb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions