cmake_minimum_required(VERSION 3.15) project(FxLibc VERSION 1.4.0 LANGUAGES C ASM) set(CMAKE_INSTALL_MESSAGE LAZY) # Options # * -DFXLIBC_TARGET= # * -DFXLIBC_SHARED=1 option(SHARED "Build a shared library") option(STANDARD_NAMESPACE "Use libc.a and put headers in global include folder") set(TARGET_FOLDERS ${FXLIBC_TARGET}) # Install paths set(LIBDIR "lib") set(INCDIR "include") if(FXLIBC_TARGET STREQUAL vhex-sh) list(APPEND TARGET_FOLDERS vhex-generic sh-generic) set(FXLIBC_ARCH sh) add_definitions(-D__SUPPORT_VHEX_KERNEL) set(CMAKE_INSTALL_PREFIX "${FXSDK_COMPILER_INSTALL}" CACHE PATH "..." FORCE) 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) # Default to fxSDK install path if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${FXSDK_COMPILER_INSTALL}" CACHE PATH "..." FORCE) endif() if(CMAKE_INSTALL_PREFIX STREQUAL "${FXSDK_COMPILER_INSTALL}") set(LIBDIR ".") set(INCDIR "include") endif() endif() 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_PIC) add_compile_options(-fpic) endif() if(FXLIBC_ARCH STREQUAL sh) add_compile_options( "$<$:-m3;-mb>" "$<$:-m4-nofpu;-mb;-Wa,--dsp>") endif() # Building set(SOURCES # 3rdparty 3rdparty/grisu2b_59_56/grisu2b_59_56.c 3rdparty/tinymt32/rand.c 3rdparty/tinymt32/tinymt32.c # 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 src/libc/inttypes/strtoimax.c src/libc/inttypes/strtoumax.c # locale src/libc/locale/setlocale.c src/libc/locale/localeconv.c # signal src/libc/signal/signal.c src/libc/signal/raise.c # stdio src/libc/stdio/asprintf.c src/libc/stdio/clearerr.c src/libc/stdio/dprintf.c src/libc/stdio/fclose.c src/libc/stdio/fdopen.c src/libc/stdio/ferror.c src/libc/stdio/feof.c src/libc/stdio/fflush.c src/libc/stdio/fgetc.c src/libc/stdio/fgetpos.c src/libc/stdio/fgets.c src/libc/stdio/fileutil.c src/libc/stdio/fopen.c src/libc/stdio/fprintf.c src/libc/stdio/fputc.c src/libc/stdio/fputs.c src/libc/stdio/fread.c src/libc/stdio/freopen.c src/libc/stdio/fseek.c src/libc/stdio/fsetpos.c src/libc/stdio/ftell.c src/libc/stdio/fwrite.c src/libc/stdio/getc.c src/libc/stdio/getchar.c src/libc/stdio/gets.c src/libc/stdio/perror.c src/libc/stdio/printf.c src/libc/stdio/printf/format_fixed.c src/libc/stdio/printf/format_fp.c src/libc/stdio/printf/format_usual.c src/libc/stdio/printf/print.c src/libc/stdio/printf/util.c src/libc/stdio/putc.c src/libc/stdio/putchar.c src/libc/stdio/puts.c src/libc/stdio/remove.c src/libc/stdio/rewind.c src/libc/stdio/setbuf.c src/libc/stdio/setvbuf.c src/libc/stdio/snprintf.c src/libc/stdio/sprintf.c src/libc/stdio/streams.c src/libc/stdio/ungetc.c src/libc/stdio/vasprintf.c src/libc/stdio/vdprintf.c src/libc/stdio/vfprintf.c src/libc/stdio/vprintf.c src/libc/stdio/vsnprintf.c src/libc/stdio/vsprintf.c # stdlib src/libc/stdlib/abort.c src/libc/stdlib/abs.c src/libc/stdlib/atof.c 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/exit.c src/libc/stdlib/labs.c src/libc/stdlib/ldiv.c src/libc/stdlib/llabs.c src/libc/stdlib/lldiv.c src/libc/stdlib/qsort.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 src/libc/stdlib/strtoull.c # string src/libc/string/memchr.c src/libc/string/memcmp.c src/libc/string/memcpy.c src/libc/string/memmove.c src/libc/string/memrchr.c src/libc/string/memset.c src/libc/string/strcasecmp.c src/libc/string/strcasestr.c src/libc/string/strcat.c src/libc/string/strchr.c src/libc/string/strchrnul.c src/libc/string/strcmp.c src/libc/string/strcoll.c src/libc/string/strcpy.c src/libc/string/strcspn.c src/libc/string/strdup.c src/libc/string/strerror.c src/libc/string/strlen.c src/libc/string/strncasecmp.c src/libc/string/strncat.c src/libc/string/strncmp.c src/libc/string/strncpy.c src/libc/string/strndup.c src/libc/string/strnlen.c src/libc/string/strpbrk.c src/libc/string/strrchr.c src/libc/string/strspn.c src/libc/string/strstr.c src/libc/string/strstr_base.c src/libc/string/strtok.c src/libc/string/strxfrm.c # time src/libc/time/asctime.c src/libc/time/ctime.c src/libc/time/difftime.c src/libc/time/gmtime.c src/libc/time/localtime.c src/libc/time/mktime.c src/libc/time/strftime.c) # Silence extended warnings on Grisu2b code set_source_files_properties(3rdparty/grisu2b_59_56/grisu2b_59_56.c PROPERTIES COMPILE_OPTIONS "-Wno-all;-Wno-extra") 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/_Exit.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 src/libc/string/target/sh-generic/memchr.S src/libc/string/target/sh-generic/memcmp.S src/libc/string/target/sh-generic/memcpy.S src/libc/string/target/sh-generic/memmove.S src/libc/string/target/sh-generic/memset.S src/libc/string/target/sh-generic/strlen.S src/target/sh-generic/cpucap.c) endif() if(gint IN_LIST TARGET_FOLDERS) list(APPEND SOURCES # stdlib src/libc/stdlib/target/gint/free.c src/libc/stdlib/target/gint/malloc.c src/libc/stdlib/target/gint/realloc.c # time src/libc/time/target/gint/clock.c src/libc/time/target/gint/time.c) 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() if(FXLIBC_SHARED) target_compile_options(fxlibc PRIVATE -fPIC) if("${FXLIBC_ARCH}" STREQUAL "sh") # Original command: "ar qc ; ranlib " set(CMAKE_C_CREATE_STATIC_LIBRARY "sh-elf-ld -shared -o ") else() message(SEND_ERROR "TODO: Shared vhex on non-SuperH not available yet") endif() endif() foreach(FOLDER IN LISTS TARGET_FOLDERS) target_include_directories(fxlibc PRIVATE include/target/${FOLDER}/) endforeach() set_target_properties(fxlibc PROPERTIES OUTPUT_NAME "c") # libc.a # Install install(TARGETS fxlibc DESTINATION ${LIBDIR}) install(DIRECTORY include/ DESTINATION ${INCDIR} PATTERN "target" EXCLUDE) foreach(FOLDER IN LISTS TARGET_FOLDERS) if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/target/${FOLDER}") install(DIRECTORY include/target/${FOLDER}/ DESTINATION ${INCDIR}) endif() endforeach()