blob: 2461522349ee0e3d524335101cbc1ca55e796663 [file] [log] [blame]
JF Bastiene6376372018-12-19 17:45:321#===-- CMakeLists.txt ----------------------------------------------------===##
2#
Chandler Carruth57b08b02019-01-19 10:56:403# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
JF Bastiene6376372018-12-19 17:45:326#
7#===----------------------------------------------------------------------===##
Louis Dionneafa1afd2020-04-22 15:15:058cmake_minimum_required(VERSION 3.13.4)
JF Bastiene6376372018-12-19 17:45:329
Louis Dionne5e334b52018-12-21 15:59:0410set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
Louis Dionneab385992019-04-11 17:08:5511file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
12string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
13math(EXPR VERSION_MAJOR "(${PARALLELSTL_VERSION_SOURCE} / 1000)")
14math(EXPR VERSION_MINOR "((${PARALLELSTL_VERSION_SOURCE} % 1000) / 10)")
15math(EXPR VERSION_PATCH "(${PARALLELSTL_VERSION_SOURCE} % 10)")
JF Bastiene6376372018-12-19 17:45:3216
Louis Dionneab385992019-04-11 17:08:5517project(ParallelSTL VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES CXX)
JF Bastiene6376372018-12-19 17:45:3218
John Ericsondf31ff12022-01-19 06:45:0719# Must go below project(..)
20include(GNUInstallDirs)
21
Mikhail Dvorskiy6069a6a2021-10-15 12:36:0722set(PSTL_PARALLEL_BACKEND "serial" CACHE STRING "Threading backend to use. Valid choices are 'serial', 'omp', and 'tbb'. The default is 'serial'.")
Louis Dionne1b6d6e52019-08-13 12:49:0023set(PSTL_HIDE_FROM_ABI_PER_TU OFF CACHE BOOL "Whether to constrain ABI-unstable symbols to each translation unit (basically, mark them with C's static keyword).")
24set(_PSTL_HIDE_FROM_ABI_PER_TU ${PSTL_HIDE_FROM_ABI_PER_TU}) # For __pstl_config_site
JF Bastiene6376372018-12-19 17:45:3225
JF Bastiene6376372018-12-19 17:45:3226if (NOT TBB_DIR)
27 get_filename_component(PSTL_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
28 string(REPLACE pstl tbb TBB_DIR_NAME ${PSTL_DIR_NAME})
29 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../${TBB_DIR_NAME}/cmake")
30 get_filename_component(TBB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${TBB_DIR_NAME}/cmake" ABSOLUTE)
31 endif()
32endif()
33
Louis Dionnef7433f92019-04-09 18:35:5634###############################################################################
35# Setup the ParallelSTL library target
36###############################################################################
JF Bastiene6376372018-12-19 17:45:3237add_library(ParallelSTL INTERFACE)
38add_library(pstl::ParallelSTL ALIAS ParallelSTL)
Louis Dionne540e18d2019-04-03 17:17:4039target_compile_features(ParallelSTL INTERFACE cxx_std_17)
JF Bastiene6376372018-12-19 17:45:3240
Louis Dionne5065e782019-08-13 11:50:2641if (PSTL_PARALLEL_BACKEND STREQUAL "serial")
Louis Dionne65a422c2019-04-24 20:12:3642 message(STATUS "Parallel STL uses the serial backend")
Louis Dionnebf480842019-08-08 12:43:0443 set(_PSTL_PAR_BACKEND_SERIAL ON)
Louis Dionne5065e782019-08-13 11:50:2644elseif (PSTL_PARALLEL_BACKEND STREQUAL "tbb")
Louis Dionne65a422c2019-04-24 20:12:3645 find_package(TBB 2018 REQUIRED tbb OPTIONAL_COMPONENTS tbbmalloc)
46 message(STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})")
47 target_link_libraries(ParallelSTL INTERFACE TBB::tbb)
Louis Dionnebf480842019-08-08 12:43:0448 set(_PSTL_PAR_BACKEND_TBB ON)
Mikhail Dvorskiy6069a6a2021-10-15 12:36:0749elseif (PSTL_PARALLEL_BACKEND STREQUAL "omp")
50 message(STATUS "Parallel STL uses the omp backend")
51 target_compile_options(ParallelSTL INTERFACE "-fopenmp=libomp")
52 set(_PSTL_PAR_BACKEND_OPENMP ON)
JF Bastiene6376372018-12-19 17:45:3253else()
Louis Dionne5065e782019-08-13 11:50:2654 message(FATAL_ERROR "Requested unknown Parallel STL backend '${PSTL_PARALLEL_BACKEND}'.")
JF Bastiene6376372018-12-19 17:45:3255endif()
56
Louis Dionnebf480842019-08-08 12:43:0457set(PSTL_GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_headers")
58set(PSTL_CONFIG_SITE_PATH "${PSTL_GENERATED_HEADERS_DIR}/__pstl_config_site")
59configure_file("include/__pstl_config_site.in"
60 "${PSTL_CONFIG_SITE_PATH}"
61 @ONLY)
62
JF Bastiene6376372018-12-19 17:45:3263target_include_directories(ParallelSTL
64 INTERFACE
Louis Dionne5e334b52018-12-21 15:59:0465 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Louis Dionnebf480842019-08-08 12:43:0466 $<BUILD_INTERFACE:${PSTL_GENERATED_HEADERS_DIR}>
JF Bastiene6376372018-12-19 17:45:3267 $<INSTALL_INTERFACE:include>)
68
Louis Dionnef7433f92019-04-09 18:35:5669###############################################################################
70# Setup tests
71###############################################################################
Louis Dionne5e334b52018-12-21 15:59:0472enable_testing()
73add_subdirectory(test)
Louis Dionnef7433f92019-04-09 18:35:5674
75###############################################################################
76# Install the target and the associated CMake files
77###############################################################################
78include(CMakePackageConfigHelpers)
79write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
80 COMPATIBILITY ExactVersion)
81
82configure_file(cmake/ParallelSTLConfig.cmake.in
83 "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
84 @ONLY)
85
86install(TARGETS ParallelSTL
87 EXPORT ParallelSTLTargets)
88install(EXPORT ParallelSTLTargets
89 FILE ParallelSTLTargets.cmake
90 NAMESPACE pstl::
91 DESTINATION lib/cmake/ParallelSTL)
92install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
93 "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
94 DESTINATION lib/cmake/ParallelSTL)
Louis Dionne762e6622019-08-07 20:29:0495install(DIRECTORY include/
John Ericsonc90d1362022-01-16 06:07:1396 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Louis Dionneef14e522020-07-08 18:51:3097 PATTERN "*.in" EXCLUDE)
Louis Dionnebf480842019-08-08 12:43:0498install(FILES "${PSTL_CONFIG_SITE_PATH}"
John Ericsonc90d1362022-01-16 06:07:1399 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
Louis Dionnef7433f92019-04-09 18:35:56100
101add_custom_target(install-pstl
102 COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)