Luna/libc/CMakeLists.txt
apio 129e3c434a
Some checks failed
continuous-integration/drone/push Build is failing
Switch to C for userspace, with a very bare-bones libc!!
2023-01-06 13:31:14 +01:00

62 lines
1.6 KiB
CMake

file(GLOB HEADERS include/*.h)
set(SOURCES
${HEADERS}
src/stdio.cpp
src/stdlib.cpp
src/unistd.cpp
)
if(${ARCH} STREQUAL "x86_64")
set(SOURCES
${SOURCES}
src/arch/x86_64/syscall.S
)
endif()
add_library(crt0 STATIC src/arch/${ARCH}/crt0.S)
add_custom_command(
TARGET crt0
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crt0> ${LUNA_BASE}/usr/lib/crt0.o
)
add_library(crti STATIC src/arch/${ARCH}/crti.S)
add_custom_command(
TARGET crti
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crti> ${LUNA_BASE}/usr/lib/crti.o
)
add_library(crtn STATIC src/arch/${ARCH}/crtn.S)
add_custom_command(
TARGET crt0
COMMAND "${CMAKE_COMMAND}" -E copy $<TARGET_OBJECTS:crtn> ${LUNA_BASE}/usr/lib/crtn.o
)
add_library(bare_libc STATIC ${SOURCES})
target_link_libraries(bare_libc PUBLIC luna)
target_include_directories(bare_libc PUBLIC include/)
target_compile_options(bare_libc PRIVATE -Wall -Wextra -Werror -pedantic -nostdlib)
target_link_options(bare_libc PRIVATE -nostdlib)
set_target_properties(bare_libc PROPERTIES CXX_STANDARD 20)
add_custom_target(libc
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:bare_libc>
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:luna>
COMMAND ${CMAKE_AR} -rcs ${CMAKE_CURRENT_BINARY_DIR}/libc.a *.o
COMMAND rm *.o
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS bare_libc luna
)
add_custom_command(
TARGET libc
COMMAND "${CMAKE_COMMAND}" -E copy ${CMAKE_CURRENT_BINARY_DIR}/libc.a ${LUNA_BASE}/usr/lib/libc.a
)
file(WRITE "${LUNA_BASE}/usr/lib/libm.a" "INPUT(libc.a)")