From 554f861ac11a308e3f00f1cd55d4c9e76015b7ad Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 16 Jan 2020 12:57:58 +0100 Subject: Build: fix Linux linking errors with some combinations of build options Differential Revision: https://developer.blender.org/D6600 --- build_files/cmake/macros.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'build_files/cmake') diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index 3b6b4720a7c..3fe9ae90a79 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -416,6 +416,17 @@ function(setup_liblinks set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}" PARENT_SCOPE) set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${PLATFORM_LINKFLAGS_RELEASE}" PARENT_SCOPE) + # Work around undefined reference errors when disabling certain libraries. + # Finding the right order for all combinations of options is too hard, so + # we use --start-group and --end-group so the linker does not discard symbols + # too early. This appears to have no significant performance impact. + if(UNIX AND NOT APPLE) + target_link_libraries( + ${target} + -Wl,--start-group + ) + endif() + # jemalloc must be early in the list, to be before pthread (see T57998) if(WITH_MEM_JEMALLOC) target_link_libraries(${target} ${JEMALLOC_LIBRARIES}) @@ -592,6 +603,14 @@ function(setup_liblinks # target_link_libraries(${target} ${PLATFORM_LINKLIBS} ${CMAKE_DL_LIBS}) target_link_libraries(${target} ${PLATFORM_LINKLIBS}) + + # See comments above regarding --start-group. + if(UNIX AND NOT APPLE) + target_link_libraries( + ${target} + -Wl,--end-group + ) + endif() endfunction() macro(TEST_SSE_SUPPORT -- cgit v1.2.3