option(ETALER_ENABLE_LDGOLD "Use GNU gold linker" ON)

if(ETALER_ENABLE_LDGOLD)
        execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
        if(LD_VERSION MATCHES "GNU gold")
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
                set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
                set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold")
                set(LDGOLD_FOUND TRUE)
                message(STATUS "GNU GOLD Linker found")
        else()
                message(WARNING "GNU GOLD linker not available, falling back to default linker")
        endif()
endif()