Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: add option TBB_INSTALL #800

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ option(TBB_FIND_PACKAGE "Enable search for external oneTBB using find_package in
option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg-config tool" ${CMAKE_CROSSCOMPILING})
option(TBB_ENABLE_IPO "Enable Interprocedural Optimization (IPO) during the compilation" ON)
option(TBB_FUZZ_TESTING "Enable fuzz testing" OFF)
option(TBB_INSTALL "Enable installation" ON)

if (NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
Expand Down Expand Up @@ -255,34 +256,35 @@ else()
else()
add_subdirectory(src/tbbbind)
endif()

# -------------------------------------------------------------------
# Installation instructions
include(CMakePackageConfigHelpers)

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT devel)

install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE TBB::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT devel)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
"include(\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake)\n")

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT devel)

install(FILES "README.md"
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT devel)
# -------------------------------------------------------------------
if (TBB_INSTALL)
# -------------------------------------------------------------------
# Installation instructions
include(CMakePackageConfigHelpers)

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT devel)

install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE TBB::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT devel)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
"include(\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake)\n")

write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
COMPONENT devel)

install(FILES "README.md"
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT devel)
# -------------------------------------------------------------------
endif()
endif()

if (TBB_TEST)
Expand Down
1 change: 1 addition & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ TBBMALLOC_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB)
TBBMALLOC_PROXY_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) memory allocator proxy build (requires TBBMALLOC_BUILD. ON by default)
TBB4PY_BUILD:BOOL - Enable Intel(R) oneAPI Threading Building Blocks (oneTBB) Python module build (OFF by default)
TBB_CPF:BOOL - Enable preview features of the library (OFF by default)
TBB_INSTALL:BOOL - Enable installation (ON by default)
TBB_INSTALL_VARS:BOOL - Enable auto-generated vars installation(packages generated by `cpack` and `make install` will also include the vars script)(OFF by default)
TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by default)
TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default)
Expand Down
44 changes: 23 additions & 21 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,33 @@ macro(tbb_remove_compile_flag flag)
endmacro()

macro(tbb_install_target target)
install(TARGETS ${target}
EXPORT TBBTargets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
COMPONENT runtime
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT runtime
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT devel)

if (BUILD_SHARED_LIBS)
if (TBB_INSTALL)
install(TARGETS ${target}
EXPORT TBBTargets
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
NAMELINK_SKIP
COMPONENT runtime
RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT runtime
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT devel)
endif()
if (MSVC AND BUILD_SHARED_LIBS)
install(FILES $<TARGET_PDB_FILE:${target}>
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT devel
OPTIONAL)

if (BUILD_SHARED_LIBS)
install(TARGETS ${target}
LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT devel)
endif()
if (MSVC AND BUILD_SHARED_LIBS)
install(FILES $<TARGET_PDB_FILE:${target}>
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT devel
OPTIONAL)
endif()
endif()
endmacro()

Expand Down
100 changes: 51 additions & 49 deletions src/tbb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,57 +128,59 @@ target_link_libraries(tbb

tbb_install_target(tbb)

if (MSVC)
# Create a copy of target linker file (tbb<ver>[_debug].lib) with legacy name (tbb[_debug].lib)
# to support previous user experience for linkage.
install(FILES
$<TARGET_LINKER_FILE:tbb>
DESTINATION lib
CONFIGURATIONS RelWithDebInfo Release MinSizeRel
RENAME tbb.lib
COMPONENT devel
)

install(FILES
$<TARGET_LINKER_FILE:tbb>
DESTINATION lib
CONFIGURATIONS Debug
RENAME tbb_debug.lib
COMPONENT devel
)
endif()

set(_tbb_pc_lib_name tbb)

if (WIN32)
set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION})
endif()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TBB_PC_NAME tbb)
else()
set(TBB_PC_NAME tbb32)
endif()

set(_prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")

if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(_libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}")
else()
set(_libdir_for_pc_file "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
if (TBB_INSTALL)
if (MSVC)
# Create a copy of target linker file (tbb<ver>[_debug].lib) with legacy name (tbb[_debug].lib)
# to support previous user experience for linkage.
install(FILES
$<TARGET_LINKER_FILE:tbb>
DESTINATION lib
CONFIGURATIONS RelWithDebInfo Release MinSizeRel
RENAME tbb.lib
COMPONENT devel
)

install(FILES
$<TARGET_LINKER_FILE:tbb>
DESTINATION lib
CONFIGURATIONS Debug
RENAME tbb_debug.lib
COMPONENT devel
)
endif()

set(_tbb_pc_lib_name tbb)

if (WIN32)
set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION})
endif()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TBB_PC_NAME tbb)
else()
set(TBB_PC_NAME tbb32)
endif()

set(_prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")

if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(_libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}")
else()
set(_libdir_for_pc_file "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()

if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(_includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(_includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

configure_file(${PROJECT_SOURCE_DIR}/integration/pkg-config/tbb.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/
COMPONENT devel)
endif()

if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
set(_includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(_includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()

configure_file(${PROJECT_SOURCE_DIR}/integration/pkg-config/tbb.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/
COMPONENT devel)

if (COMMAND tbb_gen_vars)
tbb_gen_vars(tbb)
endif()