diff options
author | Andrew Kaster <akaster@serenityos.org> | 2021-09-07 02:21:36 -0600 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-15 19:04:52 +0430 |
commit | b5c98ede084e5d29b8586f3bb2bf134184d372be (patch) | |
tree | 7f4ece17df372bbe5dd27c5063b67195e1f578ea /Toolchain | |
parent | 904a268872416dc9b9f26c83fd0b1bd8b715c511 (diff) | |
download | serenity-b5c98ede084e5d29b8586f3bb2bf134184d372be.zip |
Meta: Switch to a SuperBuild that splits host and target builds
Replace the old logic where we would start with a host build, and swap
all the CMake compiler and target variables underneath it to trick
CMake into building for Serenity after we configured and built the Lagom
code generators.
The SuperBuild creates two ExternalProjects, one for Lagom and one for
Serenity. The Serenity project depends on the install stage for the
Lagom build. The SuperBuild also generates a CMakeToolchain file for the
Serenity build to use that replaces the old toolchain file that was only
used for Ports.
To ensure that code generators are rebuilt when core libraries such as
AK and LibCore are modified, developers will need to direct their manual
`ninja` invocations to the SuperBuild's binary directory instead of the
Serenity binary directory.
This commit includes warning coalescing and option style cleanup for the
affected CMakeLists in the Kernel, top level, and runtime support
libraries. A large part of the cleanup is replacing USE_CLANG_TOOLCHAIN
with the proper CMAKE_CXX_COMPILER_ID variable, which will no longer be
confused by a host clang compiler.
Diffstat (limited to 'Toolchain')
-rw-r--r-- | Toolchain/CMake/CMakeToolchain.txt | 33 | ||||
-rw-r--r-- | Toolchain/CMake/ClangToolchain.txt.in | 41 | ||||
-rw-r--r-- | Toolchain/CMake/GNUToolchain.txt.in | 37 | ||||
-rw-r--r-- | Toolchain/CMake/Platform/SerenityOS.cmake | 2 |
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 |