Fix potential for mismatched release/debug TBB libraries

- Protect against the case when the user has multiple installs of TBB
  in their search paths and the first install does not contain debug
  libraries.  In this case it is possible to get mismatched versions
  of TBB inserted into TBB_LIBRARIES.
- Also suppresses warning about use of TBB_ROOT on modern versions of
  CMake due to CMP0074.
Copied from 4e69a475cd
This commit is contained in:
loqs 2021-05-26 04:15:41 +01:00 committed by theofficialgman
parent bfaa805874
commit d6d5939b28
No known key found for this signature in database
GPG Key ID: C8F203A956638A41

View File

@ -49,20 +49,44 @@
# free to make use of it in any way you like. # free to make use of it in any way you like.
#------------------------------------------------------------------- #-------------------------------------------------------------------
# #
#============================================================================= # =========================================================================
# Copyright 2010-2012 Kitware, Inc. # Taken from Copyright.txt in the root of the VTK source tree as per
# Copyright 2012 Rolf Eike Beer <eike@sf-mail.de> # instructions to substitute the full license in place of the summary
# reference when distributing outside of VTK
# =========================================================================
# #
# Distributed under the OSI-approved BSD License (the "License"); # Program: Visualization Toolkit
# see accompanying file Copyright.txt for details. # Module: Copyright.txt
# #
# This software is distributed WITHOUT ANY WARRANTY; without even the # Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # All rights reserved.
# See the License for more information. #
#============================================================================= # Redistribution and use in source and binary forms, with or without
# (To distribute this file outside of CMake, substitute the full # modification, are permitted provided that the following conditions are met:
# License text for the above reference.) #
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
# of any contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# =========================================================================*/
#============================================================================= #=============================================================================
# FindTBB helper functions and macros # FindTBB helper functions and macros
@ -207,6 +231,32 @@ macro(make_library_set PREFIX)
endif () endif ()
endmacro() endmacro()
#===============================================
# Ensure that the release & debug libraries found are from the same installation.
#===============================================
macro(find_tbb_library_verifying_release_debug_locations PREFIX)
find_library(${PREFIX}_RELEASE
NAMES ${${PREFIX}_NAMES}
HINTS ${TBB_LIB_SEARCH_PATH})
if (${PREFIX}_RELEASE)
# To avoid finding a mismatched set of release & debug libraries from
# different installations if the first found does not have debug libraries
# by forcing the search for debug to only occur within the detected release
# library directory (if found). Although this would break detection if the
# release & debug libraries were shipped in different directories, this is
# not the case in the official TBB releases for any platform.
get_filename_component(
FOUND_RELEASE_LIB_DIR "${${PREFIX}_RELEASE}" DIRECTORY)
find_library(${PREFIX}_DEBUG
NAMES ${${PREFIX}_NAMES_DEBUG}
HINTS ${FOUND_RELEASE_LIB_DIR}
NO_DEFAULT_PATH)
else()
find_library(${PREFIX}_DEBUG
NAMES ${${PREFIX}_NAMES_DEBUG}
HINTS ${TBB_LIB_SEARCH_PATH})
endif()
endmacro()
#============================================================================= #=============================================================================
# Now to actually find TBB # Now to actually find TBB
@ -362,17 +412,10 @@ endforeach ()
set(TBB_LIBRARY_NAMES tbb) set(TBB_LIBRARY_NAMES tbb)
get_debug_names(TBB_LIBRARY_NAMES) get_debug_names(TBB_LIBRARY_NAMES)
find_path(TBB_INCLUDE_DIR find_path(TBB_INCLUDE_DIR
NAMES tbb/tbb.h NAMES tbb/tbb.h
PATHS ${TBB_INC_SEARCH_PATH}) HINTS ${TBB_INC_SEARCH_PATH})
find_tbb_library_verifying_release_debug_locations(TBB_LIBRARY)
find_library(TBB_LIBRARY_RELEASE
NAMES ${TBB_LIBRARY_NAMES}
PATHS ${TBB_LIB_SEARCH_PATH})
find_library(TBB_LIBRARY_DEBUG
NAMES ${TBB_LIBRARY_NAMES_DEBUG}
PATHS ${TBB_LIB_SEARCH_PATH})
make_library_set(TBB_LIBRARY) make_library_set(TBB_LIBRARY)
findpkg_finish(TBB tbb) findpkg_finish(TBB tbb)
@ -389,14 +432,8 @@ get_debug_names(TBB_MALLOC_LIBRARY_NAMES)
find_path(TBB_MALLOC_INCLUDE_DIR find_path(TBB_MALLOC_INCLUDE_DIR
NAMES tbb/tbb.h NAMES tbb/tbb.h
PATHS ${TBB_INC_SEARCH_PATH}) HINTS ${TBB_INC_SEARCH_PATH})
find_tbb_library_verifying_release_debug_locations(TBB_MALLOC_LIBRARY)
find_library(TBB_MALLOC_LIBRARY_RELEASE
NAMES ${TBB_MALLOC_LIBRARY_NAMES}
PATHS ${TBB_LIB_SEARCH_PATH})
find_library(TBB_MALLOC_LIBRARY_DEBUG
NAMES ${TBB_MALLOC_LIBRARY_NAMES_DEBUG}
PATHS ${TBB_LIB_SEARCH_PATH})
make_library_set(TBB_MALLOC_LIBRARY) make_library_set(TBB_MALLOC_LIBRARY)
findpkg_finish(TBB_MALLOC tbbmalloc) findpkg_finish(TBB_MALLOC tbbmalloc)
@ -408,14 +445,8 @@ get_debug_names(TBB_MALLOC_PROXY_LIBRARY_NAMES)
find_path(TBB_MALLOC_PROXY_INCLUDE_DIR find_path(TBB_MALLOC_PROXY_INCLUDE_DIR
NAMES tbb/tbbmalloc_proxy.h NAMES tbb/tbbmalloc_proxy.h
PATHS ${TBB_INC_SEARCH_PATH}) HINTS ${TBB_INC_SEARCH_PATH})
find_tbb_library_verifying_release_debug_locations(TBB_MALLOC_PROXY_LIBRARY)
find_library(TBB_MALLOC_PROXY_LIBRARY_RELEASE
NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES}
PATHS ${TBB_LIB_SEARCH_PATH})
find_library(TBB_MALLOC_PROXY_LIBRARY_DEBUG
NAMES ${TBB_MALLOC_PROXY_LIBRARY_NAMES_DEBUG}
PATHS ${TBB_LIB_SEARCH_PATH})
make_library_set(TBB_MALLOC_PROXY_LIBRARY) make_library_set(TBB_MALLOC_PROXY_LIBRARY)
findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy) findpkg_finish(TBB_MALLOC_PROXY tbbmalloc_proxy)