From 3545097fe9079053553e9ff89aaedc357295f749 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Mon, 24 Feb 2020 13:45:16 -0600 Subject: [PATCH] Fix CMake/wxWidgets link issue This corrects linking of the wxWidgets libraries when there's multiple copies and the desired one is later in the search path. This can affect any non-Windows system that doesn't have it's wxWidgets in "standard" libraries (like our wxWidgets builds on the Mac). The wrong wxWidgets libraries can be picked up by the linker if other "-L" arguments appear before the wxWidgets specific on. This can happen if you have something like Homebrew installed and CMake finds one of the libraries (like libogg) installed. It will put a "-L/usr/local/lib" in the linker arguments before the "-L/usr/local/x86_64" wxWidgets flag, and if there happens to be wxWidgets libs in /usr/local/lib, the linker will pull the wxWidgets libs from /usr/local/lib...not what was wanted. --- CMakeLists.txt | 3 +++ cmake-proxies/cmake-modules/FindwxWidgets.cmake | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index be5b63aa1..0c2390679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ endif() # Ignore COMPILE_DEFINITIONS_ properties cmake_policy( SET CMP0043 NEW ) +# Link libraries by full path even in implicit directories. +cmake_policy( SET CMP0060 NEW ) + # ``INTERPROCEDURAL_OPTIMIZATION`` is enforced when enabled. cmake_policy( SET CMP0069 NEW ) diff --git a/cmake-proxies/cmake-modules/FindwxWidgets.cmake b/cmake-proxies/cmake-modules/FindwxWidgets.cmake index 116973f28..a8ebdba23 100644 --- a/cmake-proxies/cmake-modules/FindwxWidgets.cmake +++ b/cmake-proxies/cmake-modules/FindwxWidgets.cmake @@ -944,6 +944,7 @@ else() endif() # Check that all libraries are present, as wx-config does not check it +set(_wx_libraries "") set(_wx_lib_missing "") foreach(_wx_lib_ ${wxWidgets_LIBRARIES}) if("${_wx_lib_}" MATCHES "^-l(.*)") @@ -952,10 +953,16 @@ foreach(_wx_lib_ ${wxWidgets_LIBRARIES}) find_library(_wx_lib_found NAMES ${_wx_lib_name} HINTS ${wxWidgets_LIBRARY_DIRS}) if(_wx_lib_found STREQUAL _wx_lib_found-NOTFOUND) list(APPEND _wx_lib_missing ${_wx_lib_name}) + else() + list(APPEND _wx_libraries ${_wx_lib_found}) endif() unset(_wx_lib_found CACHE) + else() + list(APPEND _wx_libraries ${_wx_lib_}) endif() endforeach() +set(wxWidgets_LIBRARIES ${_wx_libraries}) +unset(_wx_libraries) if (_wx_lib_missing) string(REPLACE ";" " " _wx_lib_missing "${_wx_lib_missing}")