xref: /oneTBB/cmake/config_generation.cmake (revision 7b927dc4)
1# Copyright (c) 2020-2023 Intel Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Save current location,
16# see for details: https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_LIST_DIR.html
17set(_tbb_gen_cfg_path ${CMAKE_CURRENT_LIST_DIR})
18
19include(CMakeParseArguments)
20
21function(tbb_generate_config)
22    set(options      HANDLE_SUBDIRS)
23    set(oneValueArgs INSTALL_DIR
24                     SYSTEM_NAME
25                     LIB_REL_PATH INC_REL_PATH
26                     VERSION
27                     TBB_BINARY_VERSION
28                     TBBMALLOC_BINARY_VERSION
29                     TBBMALLOC_PROXY_BINARY_VERSION
30                     TBBBIND_BINARY_VERSION)
31
32    cmake_parse_arguments(tbb_gen_cfg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
33
34    get_filename_component(config_install_dir ${tbb_gen_cfg_INSTALL_DIR} ABSOLUTE)
35    file(MAKE_DIRECTORY ${config_install_dir})
36
37    file(TO_CMAKE_PATH "${tbb_gen_cfg_LIB_REL_PATH}" TBB_LIB_REL_PATH)
38    file(TO_CMAKE_PATH "${tbb_gen_cfg_INC_REL_PATH}" TBB_INC_REL_PATH)
39
40    set(TBB_VERSION ${tbb_gen_cfg_VERSION})
41
42    set(_tbb_pc_lib_name tbb)
43    set(_prefix_for_pc_file "\${pcfiledir}/../../")
44    set(_includedir_for_pc_file "\${prefix}/include")
45
46    set(TBB_COMPONENTS_BIN_VERSION "
47set(_tbb_bin_version ${tbb_gen_cfg_TBB_BINARY_VERSION})
48set(_tbbmalloc_bin_version ${tbb_gen_cfg_TBBMALLOC_BINARY_VERSION})
49set(_tbbmalloc_proxy_bin_version ${tbb_gen_cfg_TBBMALLOC_PROXY_BINARY_VERSION})
50set(_tbbbind_bin_version ${tbb_gen_cfg_TBBBIND_BINARY_VERSION})
51")
52
53    if (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Linux")
54        set(TBB_LIB_PREFIX "lib")
55        set(TBB_LIB_EXT "so.\${_\${_tbb_component}_bin_version}")
56
57        set (TBB_HANDLE_IMPLIB "
58            set (_tbb_release_dll \${_tbb_release_lib})
59            set (_tbb_debug_dll \${_tbb_debug_lib})
60")
61        if (tbb_gen_cfg_HANDLE_SUBDIRS)
62            set(TBB_HANDLE_SUBDIRS "set(_tbb_subdir gcc4.8)")
63
64            set(_libdir_for_pc_file "\${prefix}/lib/intel64/gcc4.8")
65            set(_tbb_pc_extra_libdir "-L\${prefix}/lib")
66            configure_file(${_tbb_gen_cfg_path}/../integration/pkg-config/tbb.pc.in ${config_install_dir}/tbb.pc @ONLY)
67
68            set(_libdir_for_pc_file "\${prefix}/lib/ia32/gcc4.8")
69            set(_tbb_pc_extra_libdir "-L\${prefix}/lib32")
70            configure_file(${_tbb_gen_cfg_path}/../integration/pkg-config/tbb.pc.in ${config_install_dir}/tbb32.pc @ONLY)
71        endif()
72    elseif (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Darwin")
73        set(TBB_LIB_PREFIX "lib")
74        set(TBB_LIB_EXT "\${_\${_tbb_component}_bin_version}.dylib")
75
76        set (TBB_HANDLE_IMPLIB "
77            set (_tbb_release_dll \${_tbb_release_lib})
78            set (_tbb_debug_dll \${_tbb_debug_lib})
79")
80        set(_libdir_for_pc_file "\${prefix}/lib")
81        configure_file(${_tbb_gen_cfg_path}/../integration/pkg-config/tbb.pc.in ${config_install_dir}/tbb.pc @ONLY)
82    elseif (tbb_gen_cfg_SYSTEM_NAME STREQUAL "Windows")
83        set(TBB_LIB_PREFIX "")
84        set(TBB_LIB_EXT "lib")
85        set(TBB_COMPILE_DEFINITIONS "
86                                  INTERFACE_COMPILE_DEFINITIONS \"__TBB_NO_IMPLICIT_LINKAGE=1\"")
87
88        # .lib - installed to TBB_LIB_REL_PATH (e.g. <prefix>/lib) and are passed as IMPORTED_IMPLIB_<CONFIG> property to target
89        # .dll - installed to <prefix>/bin or <prefix>/redist and are passed as IMPORTED_LOCATION_<CONFIG> property to target
90        set (TBB_HANDLE_IMPLIB "
91            find_file(_tbb_release_dll
92                NAMES \${_tbb_component}\${_bin_version}.dll
93                PATHS \${_tbb_root}
94                PATH_SUFFIXES \"redist/\${_tbb_intel_arch}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\" \"bin\"
95                NO_DEFAULT_PATH
96            )
97
98            if (EXISTS \"\${_tbb_debug_lib}\")
99                find_file(_tbb_debug_dll
100                    NAMES \${_tbb_component}\${_bin_version}_debug.dll
101                    PATHS \${_tbb_root}
102                    PATH_SUFFIXES \"redist/\${_tbb_intel_arch}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\${_tbb_subdir}\" \"bin\${_tbb_arch_suffix}/\" \"bin\"
103                    NO_DEFAULT_PATH
104                )
105            endif()
106")
107            set(TBB_IMPLIB_RELEASE "
108                                        IMPORTED_IMPLIB_RELEASE \"\${_tbb_release_lib}\"")
109            set(TBB_IMPLIB_DEBUG "
110                                        IMPORTED_IMPLIB_DEBUG \"\${_tbb_debug_lib}\"")
111
112        if (tbb_gen_cfg_HANDLE_SUBDIRS)
113            set(TBB_HANDLE_SUBDIRS "
114set(_tbb_subdir vc14)
115if (WINDOWS_STORE)
116    set(_tbb_subdir \${_tbb_subdir}_uwp)
117endif()
118")
119            set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION})
120
121            set(_libdir_for_pc_file "\${prefix}/lib/intel64/vc14")
122            set(_tbb_pc_extra_libdir "-L\${prefix}/lib")
123            configure_file(${_tbb_gen_cfg_path}/../integration/pkg-config/tbb.pc.in ${config_install_dir}/tbb.pc @ONLY)
124
125            set(_libdir_for_pc_file "\${prefix}/lib/ia32/vc14")
126            set(_tbb_pc_extra_libdir "-L\${prefix}/lib32")
127            configure_file(${_tbb_gen_cfg_path}/../integration/pkg-config/tbb.pc.in ${config_install_dir}/tbb32.pc @ONLY)
128        endif()
129
130        set(TBB_HANDLE_BIN_VERSION "
131    unset(_bin_version)
132    if (_tbb_component STREQUAL tbb)
133        set(_bin_version \${_tbb_bin_version})
134    endif()
135")
136    else()
137        message(FATAL_ERROR "Unsupported OS name: ${tbb_system_name}")
138    endif()
139
140    configure_file(${_tbb_gen_cfg_path}/templates/TBBConfig.cmake.in ${config_install_dir}/TBBConfig.cmake @ONLY)
141    configure_file(${_tbb_gen_cfg_path}/templates/TBBConfigVersion.cmake.in ${config_install_dir}/TBBConfigVersion.cmake @ONLY)
142endfunction()
143