From 164b33b26d232ae660767543031e79740f874c14 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 10 Oct 2021 19:34:46 +0200 Subject: [PATCH] cmake: initial support for shared vhex library Using the previously-tested trick with `ld -shared`. --- CMakeLists.txt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12d00db..c341883 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_INSTALL_MESSAGE LAZY) # Options # * -DFXLIBC_TARGET= -# * -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 # ), 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 ; 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()