From 86380bb177b9e18e345bc302efb3a84b2c5758a9 Mon Sep 17 00:00:00 2001
From: Aleric Inglewood <Aleric.Inglewood@gmail.com>
Date: Wed, 15 Dec 2010 20:55:10 +0100
Subject: [PATCH] VWR-24254: Add support for using ld.gold on linux.

To use ld.gold configure with:
  -DCMAKE_EXE_LINKER_FLAGS:STRING="-Wl,-use-gold".
ld.gold links the viewer on my machine in 8 seconds, as
opposed to 19 seconds with ld.bfd. Moreover, it uses a
LOT less memory during linking (about 750 MB instead of
2.5 GB!).

VWR-24254: Don't link with fontconfig on non-linux.

While we already added fontconfig in the above patch,
that code turned out to also be used by Windows and
Darwin (contrary to the comments in the code).
After looking at the history of commits and a
discussion on IRC it was decided that the original
coder (Kyle Ambroff <ambroff@lindenlab.com>) really
meant (LINUX AND VIEWER) instead of (NOT LINUX OR VIEWER).
---
 doc/contributions.txt         | 1 +
 indra/cmake/BerkeleyDB.cmake  | 7 ++++++-
 indra/cmake/LLCommon.cmake    | 9 ++++++++-
 indra/cmake/LLPlugin.cmake    | 8 +++++++-
 indra/llwindow/CMakeLists.txt | 5 +++--
 5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index d4252f9ff51..67f611ced60 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -77,6 +77,7 @@ Aleric Inglewood
 	VWR-24247
 	VWR-24251
 	VWR-24252
+	VWR-24254
 	VWR-24261
 	SNOW-84
 	SNOW-477
diff --git a/indra/cmake/BerkeleyDB.cmake b/indra/cmake/BerkeleyDB.cmake
index d98e79179d9..e3ca0fd77d6 100644
--- a/indra/cmake/BerkeleyDB.cmake
+++ b/indra/cmake/BerkeleyDB.cmake
@@ -6,6 +6,11 @@ set(DB_FIND_REQUIRED ON)
 if (STANDALONE)
   include(FindBerkeleyDB)
 else (STANDALONE)
-  set(DB_LIBRARIES db-4.2)
+  if (LINUX)
+    # Need to add dependency pthread explicitely to support ld.gold.
+    set(DB_LIBRARIES db-4.2 pthread)
+  else (LINUX)
+    set(DB_LIBRARIES db-4.2)
+  endif (LINUX)
   set(DB_INCLUDE_DIRS ${LIBS_PREBUILT_DIR}/include)
 endif (STANDALONE)
diff --git a/indra/cmake/LLCommon.cmake b/indra/cmake/LLCommon.cmake
index d1ab264a413..17e211cb993 100644
--- a/indra/cmake/LLCommon.cmake
+++ b/indra/cmake/LLCommon.cmake
@@ -13,7 +13,14 @@ set(LLCOMMON_INCLUDE_DIRS
     ${Boost_INCLUDE_DIRS}
     )
 
-set(LLCOMMON_LIBRARIES llcommon)
+if (LINUX)
+    # In order to support using ld.gold on linux, we need to explicitely
+    # specify all libraries that llcommon uses.
+    # llcommon uses `clock_gettime' which is provided by librt on linux.
+    set(LLCOMMON_LIBRARIES llcommon rt)
+else (LINUX)
+    set(LLCOMMON_LIBRARIES llcommon)
+endif (LINUX)
 
 add_definitions(${TCMALLOC_FLAG})
 
diff --git a/indra/cmake/LLPlugin.cmake b/indra/cmake/LLPlugin.cmake
index 9722f16c3c3..7ee404b9bdf 100644
--- a/indra/cmake/LLPlugin.cmake
+++ b/indra/cmake/LLPlugin.cmake
@@ -5,4 +5,10 @@ set(LLPLUGIN_INCLUDE_DIRS
     ${LIBS_OPEN_DIR}/llplugin
     )
 
-set(LLPLUGIN_LIBRARIES llplugin)
+if (LINUX)
+    # In order to support using ld.gold on linux, we need to explicitely
+    # specify all libraries that llplugin uses.
+	set(LLPLUGIN_LIBRARIES llplugin pthread)
+else (LINUX)
+	set(LLPLUGIN_LIBRARIES llplugin)
+endif (LINUX)
diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt
index bf3233f3862..4d2677fd91f 100644
--- a/indra/llwindow/CMakeLists.txt
+++ b/indra/llwindow/CMakeLists.txt
@@ -59,12 +59,13 @@ set(viewer_HEADER_FILES
 
 # Libraries on which this library depends, needed for Linux builds
 # Sort by high-level to low-level
-if (NOT LINUX OR VIEWER)
+if (LINUX AND VIEWER)
   set(llwindow_LINK_LIBRARIES
       ${UI_LIBRARIES}     # for GTK
       ${SDL_LIBRARY}
+      fontconfig          # For FCInit and other FC* functions.
       )
-endif (NOT LINUX OR VIEWER)
+endif (LINUX AND VIEWER)
 
 if (DARWIN)
   list(APPEND llwindow_SOURCE_FILES
-- 
GitLab