2018-12-20 01:45:32 +08:00
#===-- CMakeLists.txt ----------------------------------------------------===##
#
2019-01-19 18:56:40 +08:00
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2018-12-20 01:45:32 +08:00
#
#===----------------------------------------------------------------------===##
2018-12-21 23:59:04 +08:00
cmake_minimum_required ( VERSION 3.4.3 )
2018-12-20 01:45:32 +08:00
2018-12-21 23:59:04 +08:00
set ( PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h" )
2019-04-12 01:08:55 +08:00
file ( STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$" )
string ( REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}" )
math ( EXPR VERSION_MAJOR "(${PARALLELSTL_VERSION_SOURCE} / 1000)" )
math ( EXPR VERSION_MINOR "((${PARALLELSTL_VERSION_SOURCE} % 1000) / 10)" )
math ( EXPR VERSION_PATCH "(${PARALLELSTL_VERSION_SOURCE} % 10)" )
2018-12-20 01:45:32 +08:00
2019-04-12 01:08:55 +08:00
project ( ParallelSTL VERSION ${ VERSION_MAJOR } . ${ VERSION_MINOR } . ${ VERSION_PATCH } LANGUAGES CXX )
2018-12-20 01:45:32 +08:00
2019-08-13 19:50:26 +08:00
set ( PSTL_PARALLEL_BACKEND "serial" CACHE STRING "Threading backend to use. Valid choices are 'serial' and 'tbb'. The default is 'serial'." )
2019-08-13 20:49:00 +08:00
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)." )
set ( _PSTL_HIDE_FROM_ABI_PER_TU ${ PSTL_HIDE_FROM_ABI_PER_TU } ) # For __pstl_config_site
2018-12-20 01:45:32 +08:00
if ( NOT TBB_DIR )
get_filename_component ( PSTL_DIR_NAME ${ CMAKE_CURRENT_SOURCE_DIR } NAME )
string ( REPLACE pstl tbb TBB_DIR_NAME ${ PSTL_DIR_NAME } )
if ( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../${TBB_DIR_NAME}/cmake" )
get_filename_component ( TBB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../${TBB_DIR_NAME}/cmake" ABSOLUTE )
endif ( )
endif ( )
2019-04-10 02:35:56 +08:00
###############################################################################
# Setup the ParallelSTL library target
###############################################################################
2018-12-20 01:45:32 +08:00
add_library ( ParallelSTL INTERFACE )
add_library ( pstl::ParallelSTL ALIAS ParallelSTL )
2019-04-04 01:17:40 +08:00
target_compile_features ( ParallelSTL INTERFACE cxx_std_17 )
2018-12-20 01:45:32 +08:00
2019-08-13 19:50:26 +08:00
if ( PSTL_PARALLEL_BACKEND STREQUAL "serial" )
2019-04-25 04:12:36 +08:00
message ( STATUS "Parallel STL uses the serial backend" )
2019-08-08 20:43:04 +08:00
set ( _PSTL_PAR_BACKEND_SERIAL ON )
2019-08-13 19:50:26 +08:00
elseif ( PSTL_PARALLEL_BACKEND STREQUAL "tbb" )
2019-04-25 04:12:36 +08:00
find_package ( TBB 2018 REQUIRED tbb OPTIONAL_COMPONENTS tbbmalloc )
message ( STATUS "Parallel STL uses TBB ${TBB_VERSION} (interface version: ${TBB_INTERFACE_VERSION})" )
target_link_libraries ( ParallelSTL INTERFACE TBB::tbb )
2019-08-08 20:43:04 +08:00
set ( _PSTL_PAR_BACKEND_TBB ON )
2018-12-20 01:45:32 +08:00
else ( )
2019-08-13 19:50:26 +08:00
message ( FATAL_ERROR "Requested unknown Parallel STL backend '${PSTL_PARALLEL_BACKEND}'." )
2018-12-20 01:45:32 +08:00
endif ( )
2019-08-08 20:43:04 +08:00
set ( PSTL_GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_headers" )
set ( PSTL_CONFIG_SITE_PATH "${PSTL_GENERATED_HEADERS_DIR}/__pstl_config_site" )
configure_file ( "include/__pstl_config_site.in"
" $ { P S T L _ C O N F I G _ S I T E _ P A T H } "
@ O N L Y )
2018-12-20 01:45:32 +08:00
target_include_directories ( ParallelSTL
I N T E R F A C E
2018-12-21 23:59:04 +08:00
$ < B U I L D _ I N T E R F A C E : $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / i n c l u d e >
2019-08-08 20:43:04 +08:00
$ < B U I L D _ I N T E R F A C E : $ { P S T L _ G E N E R A T E D _ H E A D E R S _ D I R } >
2018-12-20 01:45:32 +08:00
$ < I N S T A L L _ I N T E R F A C E : i n c l u d e > )
2019-04-10 02:35:56 +08:00
###############################################################################
# Setup tests
###############################################################################
enable_testing ( )
add_subdirectory ( test )
###############################################################################
# Install the target and the associated CMake files
###############################################################################
2019-03-25 22:45:21 +08:00
include ( CMakePackageConfigHelpers )
2019-04-10 02:35:56 +08:00
write_basic_package_version_file ( "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
C O M P A T I B I L I T Y E x a c t V e r s i o n )
2018-12-20 01:45:32 +08:00
2019-04-10 02:35:56 +08:00
configure_file ( cmake/ParallelSTLConfig.cmake.in
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / P a r a l l e l S T L C o n f i g . c m a k e "
@ O N L Y )
2018-12-20 01:45:32 +08:00
2019-04-10 02:35:56 +08:00
install ( TARGETS ParallelSTL
E X P O R T P a r a l l e l S T L T a r g e t s )
install ( EXPORT ParallelSTLTargets
F I L E P a r a l l e l S T L T a r g e t s . c m a k e
N A M E S P A C E p s t l : :
D E S T I N A T I O N l i b / c m a k e / P a r a l l e l S T L )
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfig.cmake"
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / P a r a l l e l S T L C o n f i g V e r s i o n . c m a k e "
D E S T I N A T I O N l i b / c m a k e / P a r a l l e l S T L )
2019-08-08 04:29:04 +08:00
install ( DIRECTORY include/
2020-07-09 02:51:30 +08:00
D E S T I N A T I O N i n c l u d e
P A T T E R N " * . i n " E X C L U D E )
2019-08-08 20:43:04 +08:00
install ( FILES "${PSTL_CONFIG_SITE_PATH}"
D E S T I N A T I O N i n c l u d e )
2018-12-21 23:59:04 +08:00
2019-04-10 02:35:56 +08:00
add_custom_target ( install-pstl
C O M M A N D " $ { C M A K E _ C O M M A N D } " - P " $ { P R O J E C T _ B I N A R Y _ D I R } / c m a k e _ i n s t a l l . c m a k e " - D C O M P O N E N T = P a r a l l e l S T L )