summaryrefslogtreecommitdiff
path: root/Toolchain
diff options
context:
space:
mode:
Diffstat (limited to 'Toolchain')
-rw-r--r--Toolchain/CMake/CMakeToolchain.txt33
-rw-r--r--Toolchain/CMake/ClangToolchain.txt.in41
-rw-r--r--Toolchain/CMake/GNUToolchain.txt.in37
-rw-r--r--Toolchain/CMake/Platform/SerenityOS.cmake2
4 files changed, 80 insertions, 33 deletions
diff --git a/Toolchain/CMake/CMakeToolchain.txt b/Toolchain/CMake/CMakeToolchain.txt
deleted file mode 100644
index 6c30b7d98f..0000000000
--- a/Toolchain/CMake/CMakeToolchain.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-set(CMAKE_SYSTEM_NAME SerenityOS)
-
-if (NOT DEFINED ENV{SERENITY_ARCH})
- message(FATAL_ERROR "SERENITY_ARCH not set.")
-endif()
-
-if (NOT DEFINED ENV{SERENITY_SOURCE_DIR})
- message(FATAL_ERROR "SERENITY_SOURCE_DIR not set.")
-endif()
-
-set(SERENITYOS 1)
-
-set(CMAKE_SYSTEM_PROCESSOR "$ENV{SERENITY_ARCH}")
-
-set(SERENITY_BUILD_DIR $ENV{SERENITY_SOURCE_DIR}/Build/$ENV{SERENITY_ARCH})
-
-# where to read from/write to
-set(CMAKE_SYSROOT ${SERENITY_BUILD_DIR}/Root)
-set(CMAKE_STAGING_PREFIX ${SERENITY_BUILD_DIR}/Root/usr/local)
-set(CMAKE_INSTALL_PREFIX ${SERENITY_BUILD_DIR}/Root/usr/local)
-set(CMAKE_INSTALL_DATAROOTDIR ${SERENITY_BUILD_DIR}/Root/usr/local/share)
-
-set(CMAKE_AR $ENV{SERENITY_ARCH}-pc-serenity-gcc-ar)
-set(CMAKE_RANLIB $ENV{SERENITY_ARCH}-pc-serenity-gcc-ranlib)
-set(CMAKE_C_COMPILER $ENV{SERENITY_ARCH}-pc-serenity-gcc)
-set(CMAKE_CXX_COMPILER $ENV{SERENITY_ARCH}-pc-serenity-g++)
-
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
-
-list(APPEND CMAKE_MODULE_PATH "$ENV{SERENITY_SOURCE_DIR}/Toolchain/CMake")
diff --git a/Toolchain/CMake/ClangToolchain.txt.in b/Toolchain/CMake/ClangToolchain.txt.in
new file mode 100644
index 0000000000..10f123bee9
--- /dev/null
+++ b/Toolchain/CMake/ClangToolchain.txt.in
@@ -0,0 +1,41 @@
+list(APPEND CMAKE_MODULE_PATH "@SERENITY_SOURCE_DIR@/Toolchain/CMake")
+
+set(CMAKE_SYSTEM_NAME SerenityOS)
+set(CMAKE_SYSTEM_PROCESSOR "@SERENITY_ARCH@")
+
+set(SERENITYOS 1)
+set(triple @SERENITY_ARCH@-pc-serenity)
+set(TOOLCHAIN_ROOT @SERENITY_SOURCE_DIR@/Toolchain/Local/clang/@SERENITY_ARCH@)
+set(TOOLCHAIN_PATH ${TOOLCHAIN_ROOT}/bin)
+
+# where to read from/write to
+set(CMAKE_SYSROOT @SERENITY_BUILD_DIR@/Root)
+set(CMAKE_STAGING_PREFIX @SERENITY_BUILD_DIR@/Root/usr/local)
+set(CMAKE_INSTALL_PREFIX @SERENITY_BUILD_DIR@/Root/usr/local)
+set(CMAKE_INSTALL_DATAROOTDIR @SERENITY_BUILD_DIR@/Root/usr/local/share)
+
+set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/clang)
+set(CMAKE_C_COMPILER_TARGET ${triple})
+set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/clang++)
+set(CMAKE_CXX_COMPILER_TARGET ${triple})
+set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/clang)
+set(CMAKE_ASM_COMPILER_TARGET ${triple})
+set(CMAKE_LINKER ${TOOLCHAIN_PATH}/ld.lld)
+set(CMAKE_RANLIB ${TOOLCHAIN_PATH}/llvm-ranlib)
+set(CMAKE_STRIP ${TOOLCHAIN_PATH}/llvm-strip)
+set(CMAKE_AR ${TOOLCHAIN_PATH}/llvm-ar)
+set(CMAKE_CXXFILT ${TOOLCHAIN_PATH}/llvm-cxxfilt)
+# FIXME: Persuade LLVM maintainers to add `--update-section` to llvm-objcopy, as it's required for the kernel symbol map.
+set(CMAKE_OBJCOPY ${TOOLCHAIN_ROOT}/binutils/bin/@SERENITY_ARCH@-pc-serenity-objcopy)
+
+set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack,-z,max-page-size=0x1000,-z,separate-code")
+
+# FIXME: We could eliminate this setting by building LibC and support asm files (crti.o, crtn.o)
+# in a separate build stage before the main build to ensure that LibC is available
+# for the try_compile check for the main build.
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
diff --git a/Toolchain/CMake/GNUToolchain.txt.in b/Toolchain/CMake/GNUToolchain.txt.in
new file mode 100644
index 0000000000..9a0a2efdc8
--- /dev/null
+++ b/Toolchain/CMake/GNUToolchain.txt.in
@@ -0,0 +1,37 @@
+list(APPEND CMAKE_MODULE_PATH "@SERENITY_SOURCE_DIR@/Toolchain/CMake")
+
+set(CMAKE_SYSTEM_NAME SerenityOS)
+set(CMAKE_SYSTEM_PROCESSOR "@SERENITY_ARCH@")
+
+set(SERENITYOS 1)
+set(triple @SERENITY_ARCH@-pc-serenity)
+set(TOOLCHAIN_PATH @SERENITY_SOURCE_DIR@/Toolchain/Local/@SERENITY_ARCH@/bin)
+set(TOOLCHAIN_PREFIX ${TOOLCHAIN_PATH}/${triple}-)
+
+# where to read from/write to
+set(CMAKE_SYSROOT @SERENITY_BUILD_DIR@/Root)
+set(CMAKE_STAGING_PREFIX @SERENITY_BUILD_DIR@/Root/usr/local)
+set(CMAKE_INSTALL_PREFIX @SERENITY_BUILD_DIR@/Root/usr/local)
+set(CMAKE_INSTALL_DATAROOTDIR @SERENITY_BUILD_DIR@/Root/usr/local/share)
+
+set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
+set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
+set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc)
+set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}ld)
+set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}gcc-ranlib)
+set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}strip)
+set(CMAKE_AR ${TOOLCHAIN_PREFIX}gcc-ar)
+set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
+set(CMAKE_CXXFILT ${TOOLCHAIN_PREFIX}c++filt)
+
+set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack,-z,max-page-size=0x1000,-z,separate-code")
+
+# FIXME: We could eliminate this setting by building LibC and support asm files (crti.o, crtn.o)
+# in a separate build stage before the main build to ensure that LibC is available
+# for the try_compile check for the main build.
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
diff --git a/Toolchain/CMake/Platform/SerenityOS.cmake b/Toolchain/CMake/Platform/SerenityOS.cmake
index 38dfda3ad1..fecf81df92 100644
--- a/Toolchain/CMake/Platform/SerenityOS.cmake
+++ b/Toolchain/CMake/Platform/SerenityOS.cmake
@@ -5,6 +5,8 @@ set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
set(CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG "-Wl,-rpath-link,")
set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-soname,")
set(CMAKE_EXE_EXPORTS_C_FLAG "-Wl,--export-dynamic")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
+set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-shared -Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack,-z,separate-code")
# Initialize C link type selection flags. These flags are used when
# building a shared library, shared module, or executable that links