Skip to content

Commit

Permalink
ENH: Provide a cmake script for build & install from source
Browse files Browse the repository at this point in the history
The cmake/TBBBuildInstallScript.cmake allows for building TBB
in a temporary build directory under the mandated TBB build
heirarchy.  From the tempory build directory the headers, libraries,
and CMake package config files are installed in relocatable directory
heirachy that mimics the common unix scheme of

{install_prefix}/lib/lib*.[so|dylib|a]
{install_prefix}/lib/cmake/TBB/*.cmake
{install_prefix}include/tbb/*.h

NOTE: The {install_prefix}/lib/cmake/TBB/*.cmake files use relative
      paths, so these files are relocatable to any {install_prefix}
      after the initial install occurs.

NOTE: The TBBConfigForSource.cmake.in and TBBConfig.cmake.in files
      were merged as they only differed in how they set the
      _tbb_release_lib_dir, _tbb_debug_lib_dir, _tbb_include_dir
      variables, so that is now managed by a simple if() statement
      where the argument of the if is hard-coded at configure time.

NOTE: A test case that builds a minimal program from the installed
      directory has been added.

NOTE: TBBBiuld now exposes options to support more flexible building
      while maintaining backwards compatiblity with the default
      settings.

NOTE: Moved platform default values to TBBPlatformDefaults.cmake
      so that they are used consistently across units.

Example invocation to configure, build, install, and test against
installed binaries.

cmake  \
     -DCMAKE_INSTALL_PREFIX=/tmp/tbbinstall                   \
     -DTBB_BUILD_DIR:PATH=/tmp/buildtbb                       \
     -DTBB_BUILD_PREFIX:STRING=unix_cmake_build               \
     -DTBB_RELATIVE_CMAKE_CONFIG_PATH:PATH=lib/cmake/TBB      \
     -DTBB_LIBDIR_NAME:STRING=lib                             \
     -DTBB_COMPILER:STRING=clang                              \
     -DTBB_BUILD_STATIC:BOOL=ON                               \
     -DTBB_BUILD_SHARED:BOOL=ON                               \
     -DTBB_DO_EXTERNAL_CMAKE_BUILD_TEST:BOOL=ON               \
     -P cmake/TBBBuildInstallScript.cmake
  • Loading branch information
hjmjohnson committed Jan 29, 2019
1 parent 010ae25 commit 6e9402d
Show file tree
Hide file tree
Showing 10 changed files with 496 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Handling of TBB_VERSION is in TBBConfigVersion.cmake.

if (NOT TBB_FIND_COMPONENTS)
set(TBB_FIND_COMPONENTS "@TBB_DEFAULT_COMPONENTS@")
set(TBB_FIND_COMPONENTS "tbb;tbbmalloc;tbbmalloc_proxy")
foreach (_tbb_component ${TBB_FIND_COMPONENTS})
set(TBB_FIND_REQUIRED_${_tbb_component} 1)
endforeach()
Expand All @@ -36,30 +36,54 @@ if (NOT _tbbmalloc_proxy_ix EQUAL -1)
endif()
endif()

set(TBB_INTERFACE_VERSION @TBB_INTERFACE_VERSION@)
set(TBB_INTERFACE_VERSION 11003)

get_filename_component(_tbb_root "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_tbb_root "${_tbb_root}" PATH)
set(TBB_CONFIG_FOR_SOURCE OFF)
if( TBB_CONFIG_FOR_SOURCE ) # When TBB_CONFIG_FOR_SOURCE:BOOL=ON hard-code the binary directies from source build directories.
get_filename_component(_tbb_release_lib_dir "" ABSOLUTE)
get_filename_component(_tbb_debug_lib_dir "" ABSOLUTE)
get_filename_component(_tbb_include_dir "/include" ABSOLUTE)
else()
set(_tbb_compiler_subdir .)
set(_tbb_x32_subdir .)
set(_tbb_x64_subdir .)

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_tbb_arch_subdir ${_tbb_x64_subdir})
else()
set(_tbb_arch_subdir ${_tbb_x32_subdir})
endif()
unset(_tbb_x32_subdir)
unset(_tbb_x64_subdir)

set(_tbb_config_to_lib_relative_path "${CMAKE_CURRENT_LIST_DIR}/../../../../../../../../../../../../../tmp/tbbbuild")
get_filename_component(_tbb_release_lib_dir "${_tbb_config_to_lib_relative_path}/lib/${_tbb_arch_subdir}/${_tbb_compiler_subdir}" ABSOLUTE)
get_filename_component(_tbb_debug_lib_dir "${_tbb_config_to_lib_relative_path}/lib/${_tbb_arch_subdir}/${_tbb_compiler_subdir}" ABSOLUTE)
get_filename_component(_tbb_include_dir "${_tbb_config_to_lib_relative_path}/include" ABSOLUTE)

unset(_tbb_arch_subdir)
unset(_tbb_compiler_subdir)
endif()

foreach (_tbb_component ${TBB_FIND_COMPONENTS})
set(_tbb_release_lib "@TBB_RELEASE_DIR@/@TBB_LIB_PREFIX@${_tbb_component}.@TBB_LIB_EXT@")
set(_tbb_debug_lib "@TBB_DEBUG_DIR@/@TBB_LIB_PREFIX@${_tbb_component}_debug.@TBB_LIB_EXT@")
set(_tbb_release_lib "${_tbb_release_lib_dir}/lib${_tbb_component}.dylib")
set(_tbb_debug_lib "${_tbb_debug_lib_dir}/lib${_tbb_component}_debug.dylib")

if (EXISTS "${_tbb_release_lib}" OR EXISTS "${_tbb_debug_lib}")
add_library(TBB::${_tbb_component} SHARED IMPORTED)
set_target_properties(TBB::${_tbb_component} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_tbb_root}/include"@TBB_COMPILE_DEFINITIONS@)
INTERFACE_INCLUDE_DIRECTORIES "${_tbb_include_dir}")


if (EXISTS "${_tbb_release_lib}")
set_target_properties(TBB::${_tbb_component} PROPERTIES
IMPORTED_LOCATION_RELEASE "${_tbb_release_lib}"@TBB_IMPLIB_RELEASE@)
IMPORTED_LOCATION_RELEASE "${_tbb_release_lib}")
set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
endif()

if (EXISTS "${_tbb_debug_lib}")
set_target_properties(TBB::${_tbb_component} PROPERTIES
IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}"@TBB_IMPLIB_DEBUG@)
IMPORTED_LOCATION_DEBUG "${_tbb_debug_lib}")
set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
endif()

Expand All @@ -71,7 +95,12 @@ foreach (_tbb_component ${TBB_FIND_COMPONENTS})
list(APPEND TBB_IMPORTED_TARGETS TBB::${_tbb_component})
set(TBB_${_tbb_component}_FOUND 1)
elseif (TBB_FIND_REQUIRED AND TBB_FIND_REQUIRED_${_tbb_component})
message(FATAL_ERROR "Missed required Intel TBB component: ${_tbb_component}")
message(STATUS "Missed required Intel TBB component: ${_tbb_component} in ${_tbb_release_lib} or ${_tbb_debug_lib_dir}")
# Do not use FATAL_ERROR message as that
# breaks find_package(TBB QUIET) behavior
set(TBB_FOUND FALSE) # Set TBB_FOUND considered to be NOT FOUND if
# required components missing
set(TBB_${_tbb_component}_FOUND 0)
endif()
endforeach()

Expand All @@ -80,3 +109,6 @@ unset(_tbbmalloc_ix)
unset(_tbb_lib_path)
unset(_tbb_release_lib)
unset(_tbb_debug_lib)
unset(_tbb_release_lib_dir)
unset(_tbb_debug_lib_dir)
unset(_tbb_include_dir)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
#

set(PACKAGE_VERSION 2019.0)

if ("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
15 changes: 12 additions & 3 deletions cmake/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,19 @@ Provides the following functions:
==================================== ====================================
Parameter Description
==================================== ====================================
``TBB_ROOT <variable>`` path to Intel TBB root
``TBB_ROOT <variable>`` path to Intel TBB root source code
``SAVE_TO <relative path>`` Relative path where the cmake TBBConfig.cmake package files are created
``CONFIG_DIR <variable>`` a variable to store location of the created configuration files
``SYSTEM_NAME Linux|Windows|Darwin`` operating system name of the binary Intel TBB package,
value of `CMAKE_SYSTEM_NAME <https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html>`_ is used by default
``TBB_BUILD_DIR <path>`` Where installed packages are located (mutually exclusive of CONFIG_FOR_SOURCE)
``CONFIG_FOR_SOURCE`` Reference the source from TBBConfig.cmake (mutually exclusive of TBB_BUILD_DIR)
`` TBB_RELEASE_DIR <path>`` Source build release binaries directory
`` TBB_DEBUG_DIR <path>`` Source build debug binaries directory

==================================== ====================================


TBBBuild
^^^^^^^^

Expand All @@ -263,9 +270,12 @@ Provides the following functions:
===================================== ====================================
Parameter Description
===================================== ====================================
``TBB_ROOT <variable>`` path to Intel TBB root
``TBB_ROOT <directory>`` path to Intel TBB root source code
``SYSTEM_NAME <string>`` The system name for the binaries (i.e. Darwin/Linux/Windows/Android)
``CONFIG_DIR <variable>`` a variable to store location of the created configuration files,
``<variable>-NOTFOUND`` will be provided in case ``tbb_build`` is unsuccessful
``TBB_CMAKE_PACKAGE_CONFIG_DIR<path>`` The path to use for defining where teh package config dir should be.
``CONFIG_FOR_INSTALL`` Whether to config to point to the install directory (ON) or the source directory (OFF)
``MAKE_ARGS <custom_make_arguments>`` custom arguments to be passed to ``make`` tool.

The following arguments are always passed with automatically detected values to
Expand All @@ -277,7 +287,6 @@ Provides the following functions:
- ``-j<n>``
===================================== ====================================


------------

Intel and the Intel logo are trademarks of Intel Corporation or its subsidiaries in the U.S. and/or other countries.
Expand Down
60 changes: 40 additions & 20 deletions cmake/TBBBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
# Usage:
# include(TBBBuild.cmake)
# tbb_build(ROOT <tbb_root> MAKE_ARGS <arg1> [... <argN>])
# tbb_build(TBB_ROOT <tbb_root> MAKE_ARGS <arg1> [... <argN>])
# find_package(TBB <options>)
#

Expand All @@ -33,10 +33,12 @@ set(_tbb_cmake_module_path ${CMAKE_CURRENT_LIST_DIR})
# Builds Intel TBB.
#
# Parameters:
# TBB_ROOT <directory> - path to Intel TBB root directory (with sources);
# TBB_ROOT <directory> - path to Intel TBB root directory (with sources); #store <variable>-NOTFOUND otherwise.
# SYSTEM_NAME - The system name for the binaries (i.e. Darwin/Linux/Windows/Android)
# MAKE_ARGS <list> - user-defined arguments to be passed to make-tool;
# CONFIG_DIR <variable> - store location of the created TBBConfig if the build was ok, store <variable>-NOTFOUND otherwise.
#
# CONFIG_DIR <variable> - store location of the created TBBConfig if the build was ok in the specified variable
# TBB_CMAKE_PACKAGE_CONFIG_DIR:PATH - The path to use for defining where teh package config dir should be. ${TBB_DIR}/cmake
# CONFIG_FOR_INSTALL - Whether to config to point to the install directory (ON) or the source directory (OFF)
function(tbb_build)
# NOTE: internal function are used to hide them from user.

Expand Down Expand Up @@ -111,8 +113,9 @@ function(tbb_build)
# RELEASE_DIR <variable> - store normalized (CMake) path to release directory
# DEBUG_DIR <variable> - store normalized (CMake) path to debug directory
#
#
function(tbb_get_build_paths_from_make_args)
set(oneValueArgs RELEASE_DIR DEBUG_DIR)
set(oneValueArgs RELEASE_DIR DEBUG_DIR BUILD_DIR)
set(multiValueArgs MAKE_ARGS)
cmake_parse_arguments(tbb_GBPFMA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

Expand All @@ -132,27 +135,31 @@ function(tbb_build)

set(${tbb_GBPFMA_RELEASE_DIR} ${tbb_release_dir} PARENT_SCOPE)
set(${tbb_GBPFMA_DEBUG_DIR} ${tbb_debug_dir} PARENT_SCOPE)
set(${tbb_GBPFMA_BUILD_DIR} ${tbb_build_dir} PARENT_SCOPE)
endfunction()

# -------------------- #
# Function entry point #
# -------------------- #
set(oneValueArgs TBB_ROOT CONFIG_DIR)
set(options CONFIG_FOR_INSTALL)
set(oneValueArgs TBB_ROOT SYSTEM_NAME CONFIG_DIR TBB_CMAKE_PACKAGE_CONFIG_DIR)
set(multiValueArgs MAKE_ARGS)
cmake_parse_arguments(tbb_build "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if (NOT EXISTS "${tbb_build_TBB_ROOT}/Makefile" OR NOT EXISTS "${tbb_build_TBB_ROOT}/src")
message(STATUS "Intel TBB can not be built: Makefile or src directory was not found in ${tbb_build_TBB_ROOT}")
set(${tbb_build_CONFIG_DIR} ${tbb_build_CONFIG_DIR}-NOTFOUND PARENT_SCOPE)
set(${tbb_build_TBB_ROOT} ${tbb_build_TBB_ROOT}-NOTFOUND PARENT_SCOPE)
return()
endif()
if ( NOT tbb_build_TBB_CMAKE_PACKAGE_CONFIG_DIR )
set(tbb_build_TBB_CMAKE_PACKAGE_CONFIG_DIR ${tbb_build_TBB_ROOT}/cmake )
endif()

set(make_tool_name make)
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(make_tool_name gmake)
elseif (CMAKE_SYSTEM_NAME MATCHES "Android")
set(make_tool_name ndk-build)
set(tbb_system_name ${CMAKE_SYSTEM_NAME})
if (tbb_build_SYSTEM_NAME)
set(tbb_system_name ${tbb_build_SYSTEM_NAME})
endif()
include(${CMAKE_CURRENT_LIST_DIR}/TBBPlatformDefaults.cmake)

find_program(TBB_MAKE_TOOL ${make_tool_name} DOC "Make-tool to build Intel TBB.")
mark_as_advanced(TBB_MAKE_TOOL)
Expand Down Expand Up @@ -183,15 +190,28 @@ function(tbb_build)

tbb_get_build_paths_from_make_args(MAKE_ARGS ${tbb_make_args}
RELEASE_DIR tbb_release_dir
DEBUG_DIR tbb_debug_dir)
DEBUG_DIR tbb_debug_dir
BUILD_DIR tbb_build_dir)

include(${_tbb_cmake_module_path}/TBBMakeConfig.cmake)
tbb_make_config(TBB_ROOT ${tbb_build_TBB_ROOT}
SYSTEM_NAME ${CMAKE_SYSTEM_NAME}
CONFIG_DIR tbb_config_dir
CONFIG_FOR_SOURCE
if (tbb_build_CONFIG_FOR_INSTALL )
message(STATUS "Generating TBBConfig.cmake for installed reference")
tbb_make_config(TBB_ROOT ${tbb_build_TBB_ROOT}
TBB_BUILD_DIR ${tbb_build_dir}
SYSTEM_NAME ${CMAKE_SYSTEM_NAME}
CONFIG_DIR tbb_config_dir
SAVE_TO ${tbb_build_TBB_CMAKE_PACKAGE_CONFIG_DIR}
)
else()
message(STATUS "Generating TBBConfig.cmake for source reference")
tbb_make_config(TBB_ROOT ${tbb_build_TBB_ROOT}
SYSTEM_NAME ${CMAKE_SYSTEM_NAME}
CONFIG_DIR tbb_config_dir
SAVE_TO ${tbb_build_TBB_CMAKE_PACKAGE_CONFIG_DIR}
CONFIG_FOR_SOURCE
TBB_RELEASE_DIR ${tbb_release_dir}
TBB_DEBUG_DIR ${tbb_debug_dir})

set(${tbb_build_CONFIG_DIR} ${tbb_config_dir} PARENT_SCOPE)
TBB_DEBUG_DIR ${tbb_debug_dir}
)
endif()
set(${tbb_build_CONFIG_DIR} ${tbb_build_TBB_CMAKE_PACKAGE_CONFIG_DIR} PARENT_SCOPE)
endfunction()
Loading

0 comments on commit 6e9402d

Please sign in to comment.