fxlibc/CMakeLists.txt

205 lines
5.5 KiB
Text
Raw Normal View History

cmake_minimum_required(VERSION 3.16)
2021-05-09 17:32:28 +02:00
project(FxLibc VERSION 1.0.0 LANGUAGES C ASM)
# Options
# * -DFXLIBC_TARGET=<vhex-sh, vhex-x86, casiowin-fx, casiowin-cg, gint>
# * -DSHARED
option(SHARED "Build a shared library")
option(STANDARD_NAMESPACE "Use libc.a and put headers in global include folder")
set(TARGET_FOLDERS ${FXLIBC_TARGET})
if(FXLIBC_TARGET STREQUAL vhex-sh)
list(APPEND TARGET_FOLDERS vhex-generic sh-generic)
set(FXLIBC_ARCH sh)
add_definitions(-D__SUPPORT_VHEX_KERNEL)
endif()
if(FXLIBC_TARGET STREQUAL vhex-x86)
list(APPEND TARGET_FOLDERS vhex-generic x86-generic)
set(FXLIBC_ARCH x86)
add_definitions(-D__SUPPORT_VHEX_KERNEL)
# TODO: Maybe add -nostdinc (but that removes compiler-provided headers like
# <stddef.h>), or use another compiler than the system one?
endif()
if(FXLIBC_TARGET STREQUAL casiowin-fx)
list(APPEND TARGET_FOLDERS sh-generic)
set(FXLIBC_ARCH sh)
add_definitions(-D__SUPPORT_CASIOWIN_FX9860G)
endif()
if(FXLIBC_TARGET STREQUAL casiowin-cg)
list(APPEND TARGET_FOLDERS sh-generic)
set(FXLIBC_ARCH sh)
add_definitions(-D__SUPPORT_CASIOWIN_FXCG50)
endif()
if(FXLIBC_TARGET STREQUAL gint)
list(APPEND TARGET_FOLDERS sh-generic)
set(FXLIBC_ARCH sh)
add_definitions(-D__SUPPORT_GINT)
endif()
2021-05-20 11:33:22 +02:00
if(sh-generic IN_LIST TARGET_FOLDERS)
add_definitions(-D__SUPPORT_ARCH_SH)
endif()
if(x86-generic IN_LIST TARGET_FOLDERS)
add_definitions(-D__SUPPORT_ARCH_X86)
endif()
# TODO: Preprocessor definitions for configuration
# configure_file()
# libc.{a,so} libfxlibc.{a,so}
add_compile_options(-Wall -Wextra -std=c11 -ffreestanding -Os)
if(FXLIBC_ARCH STREQUAL sh)
add_compile_options(
"$<$<COMPILE_LANGUAGE:C>:-m3;-mb>"
"$<$<COMPILE_LANGUAGE:ASM>:-m4-nofpu;-mb;-Wa,--dsp>")
endif()
# Building
set(SOURCES
# assert
src/libc/assert/assert.c
# ctype
src/libc/ctype/isalnum.c
src/libc/ctype/isalpha.c
src/libc/ctype/isblank.c
src/libc/ctype/iscntrl.c
src/libc/ctype/isdigit.c
src/libc/ctype/isgraph.c
src/libc/ctype/islower.c
src/libc/ctype/isprint.c
src/libc/ctype/ispunct.c
src/libc/ctype/isspace.c
src/libc/ctype/isupper.c
src/libc/ctype/isxdigit.c
src/libc/ctype/tolower.c
src/libc/ctype/toupper.c
# errno
src/libc/errno/errno.c
# inttypes
src/libc/inttypes/imaxabs.c
src/libc/inttypes/imaxdiv.c
2021-05-20 16:05:20 +02:00
src/libc/inttypes/strtoimax.c
src/libc/inttypes/strtoumax.c
# locale
src/libc/locale/setlocale.c
src/libc/locale/localeconv.c
# stdio
src/libc/stdio/vsnprintf.c
src/libc/stdio/sprintf.c
src/libc/stdio/dprintf.c
src/libc/stdio/snprintf.c
src/libc/stdio/puts.c
src/libc/stdio/vsprintf.c
src/libc/stdio/putc.c
src/libc/stdio/internal/printf_actions.c
src/libc/stdio/internal/printf_options.c
src/libc/stdio/internal/printf_common.c
src/libc/stdio/internal/printf.h
src/libc/stdio/vdprintf.c
src/libc/stdio/printf.c
# stdlib
src/libc/stdlib/abs.c
src/libc/stdlib/atof.c
2021-05-20 11:11:24 +02:00
src/libc/stdlib/atoi.c
src/libc/stdlib/atol.c
src/libc/stdlib/atoll.c
src/libc/stdlib/calloc.c
src/libc/stdlib/div.c
src/libc/stdlib/labs.c
src/libc/stdlib/ldiv.c
src/libc/stdlib/llabs.c
src/libc/stdlib/lldiv.c
src/libc/stdlib/reallocarray.c
src/libc/stdlib/strto_fp.c
src/libc/stdlib/strto_int.c
src/libc/stdlib/strtod.c
src/libc/stdlib/strtof.c
src/libc/stdlib/strtol.c
src/libc/stdlib/strtold.c
src/libc/stdlib/strtoll.c
src/libc/stdlib/strtoul.c
2021-05-19 21:39:33 +02:00
src/libc/stdlib/strtoull.c
# string
src/libc/string/strchr.c
src/libc/string/strcpy.c
src/libc/string/memcpy.c
src/libc/string/strcat.c
src/libc/string/memset.c
src/libc/string/strcmp.c
src/libc/string/strdup.c
src/libc/string/strlen.c)
if(vhex-generic IN_LIST TARGET_FOLDERS)
# TODO
endif()
if(vhex-sh IN_LIST TARGET_FOLDERS)
list(APPEND SOURCES
src/libc/signal/target/vhex-sh/kill.S
src/libc/signal/target/vhex-sh/signal.S
src/libc/stdlib/target/vhex-sh/free.S
src/libc/stdlib/target/vhex-sh/malloc.S
src/libc/stdlib/target/vhex-sh/realloc.S
src/posix/fcntl/target/vhex-sh/open.S
src/posix/sys/wait/target/vhex-sh/wait.S
src/posix/sys/wait/target/vhex-sh/waitpid.S
src/posix/unistd/target/vhex-sh/read.S
src/posix/unistd/target/vhex-sh/getppid.S
src/posix/unistd/target/vhex-sh/close.S
src/posix/unistd/target/vhex-sh/fork_execve.S
src/posix/unistd/target/vhex-sh/lseek.S
src/posix/unistd/target/vhex-sh/getpid.S
src/posix/unistd/target/vhex-sh/getpgid.S
src/posix/unistd/target/vhex-sh/setpgid.S
src/posix/unistd/target/vhex-sh/write.S)
endif()
if(sh-generic IN_LIST TARGET_FOLDERS)
list(APPEND SOURCES
src/libc/setjmp/target/sh-generic/setjmp.S
src/libc/setjmp/target/sh-generic/longjmp.S)
endif()
if(casiowin-fx IN_LIST TARGET_FOLDERS)
list(APPEND SOURCES
src/posix/unistd/target/casiowin-fx/close.S)
endif()
# TODO: All targets
add_library(fxlibc ${SOURCES})
target_include_directories(fxlibc PRIVATE include/)
if(sh-generic IN_LIST TARGET_FOLDERS)
target_include_directories(fxlibc PRIVATE "${FXSDK_COMPILER_INSTALL}/include/openlibm")
endif()
2021-05-09 17:34:00 +02:00
foreach(FOLDER IN LISTS TARGET_FOLDERS)
target_include_directories(fxlibc PRIVATE include/target/${FOLDER}/)
endforeach()
2021-05-09 17:32:28 +02:00
set_target_properties(fxlibc PROPERTIES
OUTPUT_NAME "c") # libc.a
2021-05-09 17:32:28 +02:00
# Install
install(TARGETS fxlibc DESTINATION lib/)
install(DIRECTORY include/ DESTINATION include PATTERN "target" EXCLUDE)
2021-05-09 17:32:28 +02:00
foreach(FOLDER IN LISTS TARGET_FOLDERS)
2021-05-09 17:34:00 +02:00
if(EXISTS include/target/${FOLDER}/)
install(DIRECTORY include/target/${FOLDER}/ DESTINATION include)
2021-05-09 17:34:00 +02:00
endif()
2021-05-09 17:32:28 +02:00
endforeach()