Added support for using different linkers within make projects

Better cmake support for linkers
This commit is contained in:
Alvin Moore 2019-07-29 16:41:42 -07:00
parent e52d34e93a
commit 397ad77532
2 changed files with 29 additions and 12 deletions

View File

@ -1,21 +1,35 @@
#!/bin/bash
set -e
OPTIONS=''
# Add linker, if specified and valid
# The linker to use for building:
# can be LD (system default, default choice), GOLD, LLD, or BFD
if [ "${PLATFORM}" == "linux" ] && [ -n "${USE_LD}" ]; then
if [ "${USE_LD}" == "BFD" ]; then
OPTIONS+='-fuse-ld=bfd -Wl,--disable-new-dtags'
elif [ "${USE_LD}" == "GOLD" ]; then
OPTIONS+='-fuse-ld=gold -Wl,--disable-new-dtags'
elif [ "${USE_LD}" == "LLD" ]; then
OPTIONS+='-fuse-ld=lld -Wl,--disable-new-dtags'
elif [ "${USE_LD}" != "DEFAULT" ] && [ "${USE_LD}" != "LD" ]; then
echo 'USE_LD must be set to DEFAULT, LD, BFD, GOLD, or LLD!'
exit 1
fi
fi
case $1 in
Application | DynamicLibrary)
echo "Linking $3"
if [ "$1" = "DynamicLibrary" ]; then
OPTIONS="-shared"
if [ "$PLATFORM" = "linux" ]; then
OPTIONS="$OPTIONS -Wl,-z,noexecstack -Wl,-soname,$( basename $3 )"
fi
if [ "$PLATFORM" = "osx" ]; then
OPTIONS="$OPTIONS -Wl,-dylib_install_name -Wl,$( basename $3 )"
fi
else
OPTIONS=
OPTIONS+=" -shared"
if [ "$PLATFORM" = "linux" ]; then
OPTIONS+=" -Wl,-z,noexecstack -Wl,-soname,$( basename $3 )"
elif [ "$PLATFORM" = "osx" ]; then
OPTIONS+=" -Wl,-dylib_install_name -Wl,$( basename $3 )"
fi
fi
OPTIONS=$( eval echo "$OPTIONS $LDFLAGS \$$2_OBJECTS \$$2_LIBS \$$2_STATIC_LIBS_REAL \$$2_LDFLAGS -o $3" )
@ -33,7 +47,8 @@ case $1 in
fi
;;
*)
$CC $OPTIONS
echo "Linker: $CC -v $OPTIONS"
$CC -v $OPTIONS
;;
esac

View File

@ -4,7 +4,7 @@ set(ALLOC_INSTRUMENTATION OFF CACHE BOOL "Instrument alloc")
set(WITH_UNDODB OFF CACHE BOOL "Use rr or undodb")
set(USE_ASAN OFF CACHE BOOL "Compile with address sanitizer")
set(FDB_RELEASE OFF CACHE BOOL "This is a building of a final release")
set(USE_LD "DEFAULT" CACHE STRING "The linker to use for building: can be LD (system default, default choice), GOLD, LLD, or BFD")
set(USE_LD "DEFAULT" CACHE STRING "The linker to use for building: can be LD (system default, default choice), BFD, GOLD, or LLD")
set(USE_LIBCXX OFF CACHE BOOL "Use libc++")
set(USE_CCACHE OFF CACHE BOOL "Use ccache for compilation if available")
set(RELATIVE_DEBUG_PATHS OFF CACHE BOOL "Use relative file paths in debug info")
@ -94,6 +94,8 @@ else()
string(TOUPPER "$ENV{USE_LD}" USE_LDENV)
if (("${USE_LDENV}" STREQUAL "LD") OR ("${USE_LDENV}" STREQUAL "GOLD") OR ("${USE_LDENV}" STREQUAL "LLD") OR ("${USE_LDENV}" STREQUAL "BFD"))
set(USE_LD "${USE_LDENV}")
else()
message (FATAL_ERROR "USE_LD must be set to DEFAULT, LD, BFD, GOLD, or LLD!")
endif()
endif()
@ -102,7 +104,7 @@ else()
set(USE_LD "LD")
else()
if ((NOT (USE_LD STREQUAL "LD")) AND (NOT (USE_LD STREQUAL "GOLD")) AND (NOT (USE_LD STREQUAL "LLD")) AND (NOT (USE_LD STREQUAL "BFD")))
message (FATAL_ERROR "USE_LD must be set to LD, GOLD, or LLD!")
message (FATAL_ERROR "USE_LD must be set to DEFAULT, LD, BFD, GOLD, or LLD!")
endif()
endif()