Merge branch 'use-mold'

Use (faster) mold linker for the CI builds and, optionally, for the
local ones.

See #1106.
This commit is contained in:
Vadim Zeitlin
2023-12-11 15:04:39 +01:00
3 changed files with 35 additions and 15 deletions
+20 -15
View File
@@ -19,6 +19,12 @@ if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Path to additional CMake modules
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(SociUtilities)
###############################################################################
# Build features and variants
##############################################################################
@@ -47,13 +53,7 @@ if (SOCI_LTO)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Check for lld as clang lto works best with its own linker
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fuse-ld=lld" HAS_LLD)
if (HAS_LLD)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
endif()
soci_use_ld_if_supported(lld)
endif()
elseif(supported)
message(STATUS "IPO / LTO is supported but conflicts with ASAN and not enabled")
@@ -82,15 +82,20 @@ else()
set(SOCI_HAVE_VISIBILITY_SUPPORT off)
endif()
###############################################################################
# SOCI CMake modules
###############################################################################
# Allow using alternative linker such as mold, which can be significantly
# faster than GNU ld.
option(SOCI_LD "Use non-default linker, such as 'mold'" "")
if(SOCI_LD)
# -fuse-ld works only with recent gcc (>= 12), but we don't need to support
# this with all gcc versions as this is entirely optional. I.e. if we really
# wanted to, we could use -B option as explained in mold README to make it
# work with any gcc, but for now keep the things simple.
soci_use_ld_if_supported(${SOCI_LD})
endif()
# Path to additional CMake modules
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
include(SociUtilities)
###############################################################################
# SOCI configuration
###############################################################################
include(SociConfig)
colormsg(_HIBLUE_ "Configuring SOCI:")
+10
View File
@@ -424,3 +424,13 @@ function(soci_target_output_name TARGET_NAME OUTPUT_NAME)
set(${OUTPUT_NAME} ${TARGET_NAME}${SUFFIX} PARENT_SCOPE)
endfunction()
# Check if the given linker is supported and use it if it is.
function(soci_use_ld_if_supported ld)
include(CheckCXXCompilerFlag)
set(ld_flag "-fuse-ld=${ld}")
check_cxx_compiler_flag(${ld_flag} can_use_ld)
if (can_use_ld)
add_link_options(${ld_flag})
endif()
endfunction()
+5
View File
@@ -40,6 +40,11 @@ case "$(uname)" in
run_apt update
run_apt install ${packages_to_install}
# Get mold and replace the default linker with it.
wget --quiet -O- https://github.com/rui314/mold/releases/download/v2.4.0/mold-2.4.0-$(uname -m)-linux.tar.gz | \
tar -C /usr/local --strip-components=1 -xzf -
ln -sf /usr/local/bin/mold /usr/bin/ld
;;
FreeBSD)