[SCEV] Use context to strengthen flags of BinOps
[platform/upstream/llvm.git] / pstl / CMakeLists.txt
1 #===-- CMakeLists.txt ----------------------------------------------------===##
2 #
3 # 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
6 #
7 #===----------------------------------------------------------------------===##
8 cmake_minimum_required(VERSION 3.13.4)
9
10 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
11 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
12 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
13 math(EXPR VERSION_MAJOR "(${PARALLELSTL_VERSION_SOURCE} / 1000)")
14 math(EXPR VERSION_MINOR "((${PARALLELSTL_VERSION_SOURCE} % 1000) / 10)")
15 math(EXPR VERSION_PATCH "(${PARALLELSTL_VERSION_SOURCE} % 10)")
16
17 project(ParallelSTL VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} LANGUAGES CXX)
18
19 # Must go below project(..)
20 include(GNUInstallDirs)
21
22 set(PSTL_PARALLEL_BACKEND "serial" CACHE STRING "Threading backend to use. Valid choices are 'serial', 'omp', and 'tbb'. The default is 'serial'.")
23 set(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).")
24 set(_PSTL_HIDE_FROM_ABI_PER_TU ${PSTL_HIDE_FROM_ABI_PER_TU}) # For __pstl_config_site
25
26 if (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()
32 endif()
33
34 ###############################################################################
35 # Setup the ParallelSTL library target
36 ###############################################################################
37 add_library(ParallelSTL INTERFACE)
38 add_library(pstl::ParallelSTL ALIAS ParallelSTL)
39 target_compile_features(ParallelSTL INTERFACE cxx_std_17)
40
41 if (PSTL_PARALLEL_BACKEND STREQUAL "serial")
42     message(STATUS "Parallel STL uses the serial backend")
43     set(_PSTL_PAR_BACKEND_SERIAL ON)
44 elseif (PSTL_PARALLEL_BACKEND STREQUAL "tbb")
45     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)
48     set(_PSTL_PAR_BACKEND_TBB ON)
49 elseif (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)
53 else()
54     message(FATAL_ERROR "Requested unknown Parallel STL backend '${PSTL_PARALLEL_BACKEND}'.")
55 endif()
56
57 set(PSTL_GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_headers")
58 set(PSTL_CONFIG_SITE_PATH "${PSTL_GENERATED_HEADERS_DIR}/__pstl_config_site")
59 configure_file("include/__pstl_config_site.in"
60                "${PSTL_CONFIG_SITE_PATH}"
61                @ONLY)
62
63 target_include_directories(ParallelSTL
64     INTERFACE
65     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
66     $<BUILD_INTERFACE:${PSTL_GENERATED_HEADERS_DIR}>
67     $<INSTALL_INTERFACE:include>)
68
69 ###############################################################################
70 # Setup tests
71 ###############################################################################
72 enable_testing()
73 add_subdirectory(test)
74
75 ###############################################################################
76 # Install the target and the associated CMake files
77 ###############################################################################
78 include(CMakePackageConfigHelpers)
79 write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
80                                  COMPATIBILITY ExactVersion)
81
82 configure_file(cmake/ParallelSTLConfig.cmake.in
83                "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
84                @ONLY)
85
86 install(TARGETS ParallelSTL
87         EXPORT ParallelSTLTargets)
88 install(EXPORT ParallelSTLTargets
89         FILE ParallelSTLTargets.cmake
90         NAMESPACE pstl::
91         DESTINATION lib/cmake/ParallelSTL)
92 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
93               "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
94         DESTINATION lib/cmake/ParallelSTL)
95 install(DIRECTORY include/
96         DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
97         PATTERN "*.in" EXCLUDE)
98 install(FILES "${PSTL_CONFIG_SITE_PATH}"
99         DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
100
101 add_custom_target(install-pstl
102                   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)