Skip to content

Commit

Permalink
Toolchain: Allow building using CMake on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagghiu authored and awesomekling committed Jul 13, 2020
1 parent 617655d commit a1e1aa9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}ranlib)
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)

foreach(lang ASM C CXX OBJC OBJCXX)
unset(CMAKE_${lang}_OSX_COMPATIBILITY_VERSION_FLAG)
unset(CMAKE_${lang}_OSX_CURRENT_VERSION_FLAG)
unset(CMAKE_${lang}_LINK_FLAGS)
unset(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS)
unset(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS)
unset(CMAKE_SHARED_MODULE_LOADER_${lang}_FLAG )
unset(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG)
unset(CMAKE_${lang}_SYSROOT_FLAG)
unset(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG)
endforeach()

set(CMAKE_INSTALL_NAME_TOOL "true")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared")

#FIXME: -fstack-protector

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Wno-sized-deallocation -fno-sized-deallocation -fno-exceptions -fno-rtti -Wno-address-of-packed-member -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -Wno-nonnull-compare -Wno-deprecated-copy -Wno-expansion-to-defined")
Expand Down
7 changes: 6 additions & 1 deletion Libraries/LibC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ set(ELF_SOURCES ${ELF_SOURCES} ../LibELF/Arch/i386/plt_trampoline.S)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSERENITY_LIBC_BUILD")

find_program(INSTALL_COMMAND ginstall)
if(NOT INSTALL_COMMAND)
set(INSTALL_COMMAND install)
endif()

add_library(crt0 STATIC crt0.cpp)
add_custom_command(
TARGET crt0
COMMAND install -D $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
COMMAND ${INSTALL_COMMAND} -D $<TARGET_OBJECTS:crt0> ${CMAKE_INSTALL_PREFIX}/usr/lib/crt0.o
)

set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES})
Expand Down
14 changes: 10 additions & 4 deletions Toolchain/BuildIt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
set -e
shopt -s globstar
# This file will need to be run in bash, for now.


Expand All @@ -24,6 +23,12 @@ NPROC="nproc"
# It seems that Travis starts having trouble at 35 entries, so I think this is a good amount.
KEEP_CACHE_COUNT=8

if command -v ginstall &>/dev/null; then
INSTALL=ginstall
else
INSTALL=install
fi

if [ "$(uname -s)" = "OpenBSD" ]; then
MAKE=gmake
MD5SUM="md5 -q"
Expand Down Expand Up @@ -230,11 +235,12 @@ pushd "$DIR/Build/"
pushd "$BUILD"
CXXFLAGS="-DBUILDING_SERENITY_TOOLCHAIN" cmake ..
cmake --build . --target LibC
install -D Libraries/LibC/libc.a Libraries/LibM/libm.a Root/usr/lib/
"$INSTALL" -D Libraries/LibC/libc.a Libraries/LibM/libm.a Root/usr/lib/
SRC_ROOT=$(realpath "$DIR"/..)
for header in "$SRC_ROOT"/Libraries/Lib{C,M}/**/*.h; do
FILES=$(find "$SRC_ROOT"/Libraries/LibC "$SRC_ROOT"/Libraries/LibM -name '*.h' -print)
for header in $FILES; do
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Libraries/LibC@@" -e "s@$SRC_ROOT/Libraries/LibM@@")
install -D "$header" "Root/usr/include/$target"
$INSTALL -D "$header" "Root/usr/include/$target"
done
unset SRC_ROOT
popd
Expand Down

0 comments on commit a1e1aa9

Please sign in to comment.