|
| 1 | +# Copyright (c) 2018 Intel Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# |
| 16 | +# |
| 17 | +# |
| 18 | + |
| 19 | +cmake_minimum_required(VERSION 3.1) |
| 20 | + |
| 21 | +set(PARALLELSTL_VERSION_FILE "include/pstl/internal/pstl_config.h") |
| 22 | +file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define PSTL_VERSION .*$") |
| 23 | +string(REGEX MATCH "#define PSTL_VERSION (.*)$" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}") |
| 24 | +math(EXPR VERSION_MAJOR "${PARALLELSTL_VERSION_SOURCE} / 100") |
| 25 | +math(EXPR VERSION_MINOR "${PARALLELSTL_VERSION_SOURCE} % 100") |
| 26 | + |
| 27 | +project(ParallelSTL VERSION ${VERSION_MAJOR}.${VERSION_MINOR} LANGUAGES CXX) |
| 28 | + |
| 29 | +option(PARALLELSTL_USE_PARALLEL_POLICIES "Enable parallel policies" ON) |
| 30 | +set(PARALLELSTL_BACKEND "tbb" CACHE STRING "Threading backend; defaults to TBB") |
| 31 | + |
| 32 | +include(CMakePackageConfigHelpers) |
| 33 | + |
| 34 | +add_library(ParallelSTL INTERFACE) |
| 35 | +add_library(pstl::ParallelSTL ALIAS ParallelSTL) |
| 36 | + |
| 37 | +if (PARALLELSTL_USE_PARALLEL_POLICIES) |
| 38 | + if (PARALLELSTL_BACKEND STREQUAL "tbb") |
| 39 | + find_package(TBB 2018 REQUIRED tbb) |
| 40 | + message(STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})") |
| 41 | + target_link_libraries(ParallelSTL INTERFACE TBB::tbb) |
| 42 | + else() |
| 43 | + if (TARGET ${PARALLELSTL_BACKEND}) |
| 44 | + target_link_libraries(ParallelSTL INTERFACE ${PARALLELSTL_BACKEND}) |
| 45 | + else() |
| 46 | + find_package(${PARALLELSTL_BACKEND} REQUIRED) |
| 47 | + target_link_libraries(ParallelSTL INTERFACE ${${PARALLELSTL_BACKEND}_IMPORTED_TARGETS}) |
| 48 | + endif() |
| 49 | + endif() |
| 50 | +else() |
| 51 | + target_add_definitions(ParallelSTL INTERFACE PSTL_USE_PARALLEL_POLICIES=0) |
| 52 | +endif() |
| 53 | + |
| 54 | +target_include_directories(ParallelSTL |
| 55 | + INTERFACE |
| 56 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> |
| 57 | + $<INSTALL_INTERFACE:include>) |
| 58 | + |
| 59 | +write_basic_package_version_file( |
| 60 | + ${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake |
| 61 | + VERSION ${PROJECT_VERSION} |
| 62 | + COMPATIBILITY AnyNewerVersion) |
| 63 | + |
| 64 | +configure_file( |
| 65 | + ParallelSTLConfig.cmake.in |
| 66 | + ${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake |
| 67 | + @ONLY) |
| 68 | + |
| 69 | +export(TARGETS ParallelSTL NAMESPACE pstl:: FILE ParallelSTLTargets.cmake) |
| 70 | +export(PACKAGE ParallelSTL) |
0 commit comments