cmake: initial support for shared vhex library

Using the previously-tested trick with `ld -shared`.
This commit is contained in:
Lephenixnoir 2021-10-10 19:34:46 +02:00
parent df4c13b007
commit 164b33b26d
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -6,7 +6,7 @@ set(CMAKE_INSTALL_MESSAGE LAZY)
# Options
# * -DFXLIBC_TARGET=<vhex-sh, vhex-x86, casiowin-fx, casiowin-cg, gint>
# * -DSHARED
# * -DFXLIBC_SHARED=1
option(SHARED "Build a shared library")
option(STANDARD_NAMESPACE "Use libc.a and put headers in global include folder")
@ -20,12 +20,14 @@ 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(FXLIBC_SHARED ON)
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)
set(FXLIBC_SHARED ON)
# TODO: Maybe add -nostdinc (but that removes compiler-provided headers like
# <stddef.h>), or use another compiler than the system one?
endif()
@ -246,16 +248,27 @@ if(casiowin-fx IN_LIST TARGET_FOLDERS)
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 <TARGET> <OBJECTS>; ranlib <TARGET>"
set(CMAKE_C_CREATE_STATIC_LIBRARY
"sh-elf-ld -shared <OBJECTS> -o <TARGET>")
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()