mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
b38dd3f894
Previously FXSDK_COMPILER_INSTALL would be stored as the install prefix. However, this prefix is subject to unannounced changes when the compiler version is upgraded without reconfiguring the fxlibc, which happens in the GiteaPC workflow. This commit avoids the use of CMAKE_INSTALL_PREFIX when using gint with no specified prefix, and instead uses another cached variable which leaves the prefix to be dynamically resolved based on the uncached variable FXSDK_COMPILER_INSTALL, like most repositories do (eg. gint). We need the cached indicator because we frequently reconfigure and CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT is not persistent.
287 lines
6.9 KiB
CMake
287 lines
6.9 KiB
CMake
cmake_minimum_required(VERSION 3.15)
|
|
project(FxLibc VERSION 1.4.3 LANGUAGES C ASM)
|
|
|
|
set(CMAKE_INSTALL_MESSAGE LAZY)
|
|
|
|
# Options
|
|
|
|
# * -DFXLIBC_TARGET=<vhex-sh, vhex-x86, casiowin-fx, casiowin-cg, gint>
|
|
# * -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 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 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(FXLIBC_PREFIX_IS_FXSDK 1 CACHE PATH "..." FORCE)
|
|
endif()
|
|
|
|
if(FXLIBC_PREFIX_IS_FXSDK)
|
|
# Use the fxSDK paths; these variables are uncached so we are always up-to-
|
|
# date, even if the compiler is upgraded without removing the fxlibc build
|
|
# folder (which happens with GiteaPC)
|
|
execute_process(
|
|
COMMAND fxsdk path include
|
|
OUTPUT_VARIABLE INCDIR
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
execute_process(
|
|
COMMAND fxsdk path lib
|
|
OUTPUT_VARIABLE LIBDIR
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
endif()
|
|
endif()
|
|
|
|
if(sh-generic IN_LIST TARGET_FOLDERS)
|
|
add_definitions(-D__SUPPORT_ARCH_SH)
|
|
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(
|
|
"$<$<COMPILE_LANGUAGE:C>:-m3;-mb>"
|
|
"$<$<COMPILE_LANGUAGE:ASM>:-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/assert/assert.c
|
|
# ctype
|
|
src/ctype/isalnum.c
|
|
src/ctype/isalpha.c
|
|
src/ctype/isblank.c
|
|
src/ctype/iscntrl.c
|
|
src/ctype/isdigit.c
|
|
src/ctype/isgraph.c
|
|
src/ctype/islower.c
|
|
src/ctype/isprint.c
|
|
src/ctype/ispunct.c
|
|
src/ctype/isspace.c
|
|
src/ctype/isupper.c
|
|
src/ctype/isxdigit.c
|
|
src/ctype/tolower.c
|
|
src/ctype/toupper.c
|
|
# errno
|
|
src/errno/errno.c
|
|
# inttypes
|
|
src/inttypes/imaxabs.c
|
|
src/inttypes/imaxdiv.c
|
|
src/inttypes/strtoimax.c
|
|
src/inttypes/strtoumax.c
|
|
# locale
|
|
src/locale/setlocale.c
|
|
src/locale/localeconv.c
|
|
# signal
|
|
src/signal/signal.c
|
|
src/signal/raise.c
|
|
# stdio
|
|
src/stdio/asprintf.c
|
|
src/stdio/clearerr.c
|
|
src/stdio/dprintf.c
|
|
src/stdio/fclose.c
|
|
src/stdio/fdopen.c
|
|
src/stdio/ferror.c
|
|
src/stdio/feof.c
|
|
src/stdio/fflush.c
|
|
src/stdio/fgetc.c
|
|
src/stdio/fgetpos.c
|
|
src/stdio/fgets.c
|
|
src/stdio/fileutil.c
|
|
src/stdio/fopen.c
|
|
src/stdio/fprintf.c
|
|
src/stdio/fputc.c
|
|
src/stdio/fputs.c
|
|
src/stdio/fread.c
|
|
src/stdio/freopen.c
|
|
src/stdio/fseek.c
|
|
src/stdio/fsetpos.c
|
|
src/stdio/ftell.c
|
|
src/stdio/fwrite.c
|
|
src/stdio/getc.c
|
|
src/stdio/getchar.c
|
|
src/stdio/gets.c
|
|
src/stdio/getline.c
|
|
src/stdio/getdelim.c
|
|
src/stdio/perror.c
|
|
src/stdio/printf.c
|
|
src/stdio/printf/format_fixed.c
|
|
src/stdio/printf/format_fp.c
|
|
src/stdio/printf/format_usual.c
|
|
src/stdio/printf/print.c
|
|
src/stdio/printf/util.c
|
|
src/stdio/putc.c
|
|
src/stdio/putchar.c
|
|
src/stdio/puts.c
|
|
src/stdio/remove.c
|
|
src/stdio/rewind.c
|
|
src/stdio/setbuf.c
|
|
src/stdio/setvbuf.c
|
|
src/stdio/snprintf.c
|
|
src/stdio/sprintf.c
|
|
src/stdio/streams.c
|
|
src/stdio/ungetc.c
|
|
src/stdio/vasprintf.c
|
|
src/stdio/vdprintf.c
|
|
src/stdio/vfprintf.c
|
|
src/stdio/vprintf.c
|
|
src/stdio/vsnprintf.c
|
|
src/stdio/vsprintf.c
|
|
# stdlib
|
|
src/stdlib/abort.c
|
|
src/stdlib/abs.c
|
|
src/stdlib/atof.c
|
|
src/stdlib/atoi.c
|
|
src/stdlib/atol.c
|
|
src/stdlib/atoll.c
|
|
src/stdlib/calloc.c
|
|
src/stdlib/div.c
|
|
src/stdlib/exit.c
|
|
src/stdlib/labs.c
|
|
src/stdlib/ldiv.c
|
|
src/stdlib/llabs.c
|
|
src/stdlib/lldiv.c
|
|
src/stdlib/qsort.c
|
|
src/stdlib/reallocarray.c
|
|
src/stdlib/strto_fp.c
|
|
src/stdlib/strto_int.c
|
|
src/stdlib/strtod.c
|
|
src/stdlib/strtof.c
|
|
src/stdlib/strtol.c
|
|
src/stdlib/strtold.c
|
|
src/stdlib/strtoll.c
|
|
src/stdlib/strtoul.c
|
|
src/stdlib/strtoull.c
|
|
# string
|
|
src/string/memchr.c
|
|
src/string/memcmp.c
|
|
src/string/memcpy.c
|
|
src/string/memmove.c
|
|
src/string/memrchr.c
|
|
src/string/memset.c
|
|
src/string/strcasecmp.c
|
|
src/string/strcasestr.c
|
|
src/string/strcat.c
|
|
src/string/strchr.c
|
|
src/string/strchrnul.c
|
|
src/string/strcmp.c
|
|
src/string/strcoll.c
|
|
src/string/strcpy.c
|
|
src/string/strcspn.c
|
|
src/string/strdup.c
|
|
src/string/strerror.c
|
|
src/string/strlen.c
|
|
src/string/strncasecmp.c
|
|
src/string/strncat.c
|
|
src/string/strncmp.c
|
|
src/string/strncpy.c
|
|
src/string/strndup.c
|
|
src/string/strnlen.c
|
|
src/string/strpbrk.c
|
|
src/string/strrchr.c
|
|
src/string/strspn.c
|
|
src/string/strstr.c
|
|
src/string/strstr_base.c
|
|
src/string/strtok.c
|
|
src/string/strxfrm.c
|
|
# time
|
|
src/time/asctime.c
|
|
src/time/ctime.c
|
|
src/time/difftime.c
|
|
src/time/gmtime.c
|
|
src/time/localtime.c
|
|
src/time/mktime.c
|
|
src/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-sh IN_LIST TARGET_FOLDERS)
|
|
list(APPEND SOURCES
|
|
src/stdlib/target/vhex-sh/free.c
|
|
src/stdlib/target/vhex-sh/malloc.c
|
|
src/stdlib/target/vhex-sh/realloc.c
|
|
)
|
|
endif()
|
|
|
|
if(sh-generic IN_LIST TARGET_FOLDERS)
|
|
list(APPEND SOURCES
|
|
src/setjmp/target/sh-generic/setjmp.S
|
|
src/setjmp/target/sh-generic/longjmp.S
|
|
src/string/target/sh-generic/memchr.S
|
|
src/string/target/sh-generic/memcmp.S
|
|
src/string/target/sh-generic/memcpy.S
|
|
src/string/target/sh-generic/memmove.S
|
|
src/string/target/sh-generic/memset.S
|
|
src/string/target/sh-generic/strlen.S
|
|
src/target/sh-generic/cpucap.c)
|
|
endif()
|
|
|
|
if(gint IN_LIST TARGET_FOLDERS)
|
|
list(APPEND SOURCES
|
|
# stdlib
|
|
src/stdlib/target/gint/free.c
|
|
src/stdlib/target/gint/malloc.c
|
|
src/stdlib/target/gint/realloc.c
|
|
# time
|
|
src/time/target/gint/clock.c
|
|
src/time/target/gint/time.c)
|
|
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()
|
|
|
|
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()
|