Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit f22c61e

Browse files
Merge pull request #1039 from lukaszstolarczuk/ease-finding-custom-TBB
cmake: prioritize TBB_DIR to find TBB module
2 parents f7acc37 + d8b79cc commit f22c61e

1 file changed

Lines changed: 39 additions & 12 deletions

File tree

cmake/tbb.cmake

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
# SPDX-License-Identifier: BSD-3-Clause
2-
# Copyright 2017-2020, Intel Corporation
2+
# Copyright 2017-2021, Intel Corporation
33

44
message(STATUS "Checking for module 'tbb'")
55

6-
if(PKG_CONFIG_FOUND)
7-
pkg_check_modules(TBB QUIET tbb)
8-
endif()
6+
# TBB was found without pkg-config:
7+
# print status message and set global variable with tbb libs.
8+
function(handle_tbb_found_no_pkgconf)
9+
set(TBB_LIBRARIES ${TBB_IMPORTED_TARGETS} PARENT_SCOPE)
10+
message(STATUS " Found in dir '${TBB_DIR}' using CMake's find_package (ver: ${TBB_VERSION})")
11+
endfunction()
12+
13+
# Fail cmake build if TBB not found and TBB tests are enabled.
14+
function(fail_tbb_not_found)
15+
message(FATAL_ERROR "TBB tests are enabled by cmake TESTS_TBB option, but Intel TBB library was not found.")
16+
endfunction()
17+
18+
# CMake param TBB_DIR is priortized. This is the best to use
19+
# while developing/testing pmemkv with custom TBB installation.
20+
if(TBB_DIR)
21+
message(STATUS " CMake param TBB_DIR is set, look ONLY in there (${TBB_DIR})!")
22+
find_package(TBB QUIET COMPONENTS tbb NO_DEFAULT_PATH)
23+
if(TBB_FOUND)
24+
handle_tbb_found_no_pkgconf()
25+
else()
26+
message(WARNING "TBB_DIR is set, but does not contain a path to TBB. "
27+
"Either set this var to a dir with TBBConfig.cmake (or tbb-config.cmake), "
28+
"or unset it and let CMake find TBB in the system (using e.g. pkg-config).")
29+
if(TESTS_TBB)
30+
fail_tbb_not_found()
31+
endif()
32+
endif()
33+
else()
34+
if(PKG_CONFIG_FOUND)
35+
pkg_check_modules(TBB QUIET tbb)
36+
if(TBB_FOUND)
37+
message(STATUS " Found in dir '${TBB_LIBDIR}' using pkg-config (ver: ${TBB_VERSION})")
38+
return()
39+
endif()
40+
endif()
941

10-
# Now, if needed, try to find it without pkg-config..
11-
if(NOT TBB_FOUND)
12-
# find_package without unsetting this var is not working correctly
42+
# find_package (run after pkg-config) without unsetting this var is not working correctly
1343
unset(TBB_FOUND CACHE)
1444

1545
find_package(TBB COMPONENTS tbb)
1646
if(TBB_FOUND)
17-
set(TBB_LIBRARIES ${TBB_IMPORTED_TARGETS})
18-
message(STATUS " Found in: ${TBB_DIR} using CMake's find_package (ver: ${TBB_VERSION})")
47+
handle_tbb_found_no_pkgconf()
1948
elseif(TESTS_TBB)
20-
message(FATAL_ERROR "TBB tests are enabled by cmake TESTS_TBB option, but Intel TBB library was not found.")
49+
fail_tbb_not_found()
2150
endif()
22-
else()
23-
message(STATUS " Found in: ${TBB_LIBDIR} using pkg-config (ver: ${TBB_VERSION})")
2451
endif()

0 commit comments

Comments
 (0)