From 195d416e3b1c8dc06980439f6acd3ebd40b6b820 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Jan 2020 00:17:28 -0800 Subject: [PATCH] Add target existence checks to Unwind find module (#518) * Add target existence checks to Unwind find module The build systems of projects depending on Glog may call the Unwind find module multiple times. In these cases, the current unwind find module tries to create a duplicate unwind::unwind target, crashing the build. This patch adds an existence check before target creation to fix this issue. Signed-off-by: Michael Darr * Alphabetize contributor list * Fix inconsistent CMake style Signed-off-by: Michael Darr --- CONTRIBUTORS | 1 + cmake/FindUnwind.cmake | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f4b011f..d90f859 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -34,6 +34,7 @@ Ivan Penkov Jacob Trimble Jim Ray Marco Wang +Michael Darr Michael Tanner MiniLight Peter Collingbourne diff --git a/cmake/FindUnwind.cmake b/cmake/FindUnwind.cmake index ae530df..8941bb0 100644 --- a/cmake/FindUnwind.cmake +++ b/cmake/FindUnwind.cmake @@ -62,15 +62,17 @@ find_package_handle_standard_args (Unwind REQUIRED_VARS Unwind_INCLUDE_DIR Unwind_LIBRARY Unwind_PLATFORM_LIBRARY VERSION_VAR Unwind_VERSION) if (Unwind_FOUND) - add_library (unwind::unwind INTERFACE IMPORTED) + if (NOT TARGET unwind::unwind) + add_library (unwind::unwind INTERFACE IMPORTED) - set_property (TARGET unwind::unwind PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR} - ) - set_property (TARGET unwind::unwind PROPERTY - INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY} ${Unwind_PLATFORM_LIBRARY} - ) - set_property (TARGET unwind::unwind PROPERTY - IMPORTED_CONFIGURATIONS RELEASE - ) + set_property (TARGET unwind::unwind PROPERTY + INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR} + ) + set_property (TARGET unwind::unwind PROPERTY + INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY} ${Unwind_PLATFORM_LIBRARY} + ) + set_property (TARGET unwind::unwind PROPERTY + IMPORTED_CONFIGURATIONS RELEASE + ) + endif (NOT TARGET unwind::unwind) endif (Unwind_FOUND)