Changeset View
Changeset View
Standalone View
Standalone View
build_files/cmake/platform/platform_unix.cmake
| Show First 20 Lines • Show All 682 Lines • ▼ Show 20 Lines | if("${LD_VERSION}" MATCHES "LLD") | ||||
| string(APPEND CMAKE_C_FLAGS " -fuse-ld=lld") | string(APPEND CMAKE_C_FLAGS " -fuse-ld=lld") | ||||
| string(APPEND CMAKE_CXX_FLAGS " -fuse-ld=lld") | string(APPEND CMAKE_CXX_FLAGS " -fuse-ld=lld") | ||||
| else() | else() | ||||
| message(STATUS "LLD linker isn't available, using the default system linker.") | message(STATUS "LLD linker isn't available, using the default system linker.") | ||||
| endif() | endif() | ||||
| unset(LD_VERSION) | unset(LD_VERSION) | ||||
| endif() | endif() | ||||
| # NOTE(@campbellbarton): Eventually mold will be able to use `-fuse-ld=mold`, | |||||
| # however at the moment this only works for GCC 12.1+ (unreleased at time of writing). | |||||
| # So a workaround is used here "-B" which points to another path to find system commands | |||||
| # such as `ld`. | |||||
| if(WITH_LINKER_MOLD) | |||||
| find_program(MOLD_BIN "mold" NO_CACHE) | |||||
| if(NOT MOLD_BIN) | |||||
| message(STATUS "The \"mold\" binary could not be found, using system linker!") | |||||
| set(WITH_LINKER_MOLD OFF) | |||||
| else() | |||||
| # By default mold installs the binary to: | |||||
| # - `{PREFIX}/bin/mold` as well as a symbolic-link in... | |||||
| # - `{PREFIX}/lib/mold/ld`. | |||||
| # (where `PREFIX` is typically `/usr/`). | |||||
| # | |||||
| # This block of code finds `{PREFIX}/lib/mold` from the `mold` binary. | |||||
| # Other methods of searching for the path could also be made to work, | |||||
| # we could even make our own directory and symbolic-link, however it's more | |||||
| # convenient to use the one provided by mold. | |||||
| # | |||||
| # Use the binary path to "mold", to find the common prefix which contains "lib/mold". | |||||
| # The parent directory: e.g. `/usr/bin/mold` -> `/usr/bin/`. | |||||
| get_filename_component(MOLD_PREFIX "${MOLD_BIN}" DIRECTORY) | |||||
| # The common prefix path: e.g. `/usr/bin/` -> `/usr/` to use as a hint. | |||||
sergey: Why this is needed? From the sounds of the description it seems that it's enough to find `mold`… | |||||
Done Inline ActionsThis is done because mold provides it's own bin directory (/usr/lib/mold on my system), that contains /usr/lib/mold/ld which can be used to override the systems ld. Updated the comment to explain this better. campbellbarton: This is done because mold provides it's own bin directory (`/usr/lib/mold` on my system), that… | |||||
| get_filename_component(MOLD_PREFIX "${MOLD_PREFIX}" DIRECTORY) | |||||
| # Find `{PREFIX}/lib/mold/ld`, store the directory component (without the `ld`). | |||||
| # Then pass `-B {PREFIX}/lib/mold` to GCC so the `ld` located there overrides the default. | |||||
| find_path( | |||||
| MOLD_BIN_DIR "ld" | |||||
| HINTS "${MOLD_PREFIX}" | |||||
| PATH_SUFFIXES "lib/mold" "lib64/mold" | |||||
| NO_DEFAULT_PATH | |||||
| NO_CACHE | |||||
| ) | |||||
| if(NOT MOLD_BIN_DIR) | |||||
| message(STATUS | |||||
| "The mold linker could not find the directory containing the linker command " | |||||
| "(typically \"${MOLD_PREFIX}/lib/mold\"), using system linker!") | |||||
| set(WITH_LINKER_MOLD OFF) | |||||
| endif() | |||||
| unset(MOLD_PREFIX) | |||||
| endif() | |||||
| if(WITH_LINKER_MOLD) | |||||
| # GCC will search for `ld` in this directory first. | |||||
| string(APPEND CMAKE_CXX_FLAGS " -B \"${MOLD_BIN_DIR}\"") | |||||
| string(APPEND CMAKE_C_FLAGS " -B \"${MOLD_BIN_DIR}\"") | |||||
| endif() | |||||
| unset(MOLD_BIN) | |||||
| unset(MOLD_BIN_DIR) | |||||
| endif() | |||||
| # CLang is the same as GCC for now. | # CLang is the same as GCC for now. | ||||
| elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") | elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") | ||||
| set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing") | set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing") | ||||
| # Intel C++ Compiler | # Intel C++ Compiler | ||||
| elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") | elseif(CMAKE_C_COMPILER_ID MATCHES "Intel") | ||||
| # think these next two are broken | # think these next two are broken | ||||
| find_program(XIAR xiar) | find_program(XIAR xiar) | ||||
| if(XIAR) | if(XIAR) | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||
Why this is needed? From the sounds of the description it seems that it's enough to find mold binary get its directory and pass via -B.