|
68 | 68 | # FindTBB helper functions and macros |
69 | 69 | # |
70 | 70 |
|
| 71 | +#==================================================== |
| 72 | +# Fix the library path in case it is a linker script |
| 73 | +#==================================================== |
| 74 | +function(tbb_extract_real_library library real_library) |
| 75 | + if(NOT UNIX OR NOT EXISTS ${library}) |
| 76 | + set(${real_library} "${library}" PARENT_SCOPE) |
| 77 | + return() |
| 78 | + endif() |
| 79 | + |
| 80 | + #Read in the first 4 bytes and see if they are the ELF magic number |
| 81 | + set(_elf_magic "7f454c46") |
| 82 | + file(READ ${library} _hex_data OFFSET 0 LIMIT 4 HEX) |
| 83 | + if(_hex_data STREQUAL _elf_magic) |
| 84 | + #we have opened a elf binary so this is what |
| 85 | + #we should link to |
| 86 | + set(${real_library} "${library}" PARENT_SCOPE) |
| 87 | + return() |
| 88 | + endif() |
| 89 | + |
| 90 | + file(READ ${library} _data OFFSET 0 LIMIT 1024) |
| 91 | + if("${_data}" MATCHES "INPUT \\(([^(]+)\\)") |
| 92 | + #extract out the .so name from REGEX MATCH command |
| 93 | + set(_proper_so_name "${CMAKE_MATCH_1}") |
| 94 | + |
| 95 | + #construct path to the real .so which is presumed to be in the same directory |
| 96 | + #as the input file |
| 97 | + get_filename_component(_so_dir "${library}" DIRECTORY) |
| 98 | + set(${real_library} "${_so_dir}/${_proper_so_name}" PARENT_SCOPE) |
| 99 | + else() |
| 100 | + #unable to determine what this library is so just hope everything works |
| 101 | + #and pass it unmodified. |
| 102 | + set(${real_library} "${library}" PARENT_SCOPE) |
| 103 | + endif() |
| 104 | +endfunction() |
| 105 | + |
71 | 106 | #=============================================== |
72 | 107 | # Do the final processing for the package find. |
73 | 108 | #=============================================== |
74 | 109 | macro(findpkg_finish PREFIX TARGET_NAME) |
75 | | - # skip if already processed during this run |
76 | | - if (NOT ${PREFIX}_FOUND) |
77 | | - if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) |
78 | | - set(${PREFIX}_FOUND TRUE) |
79 | | - set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) |
80 | | - set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) |
81 | | - else () |
82 | | - if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY) |
83 | | - message(FATAL_ERROR "Required library ${PREFIX} not found.") |
84 | | - endif () |
| 110 | + if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY) |
| 111 | + set(${PREFIX}_FOUND TRUE) |
| 112 | + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR}) |
| 113 | + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY}) |
| 114 | + else () |
| 115 | + if (${PREFIX}_FIND_REQUIRED AND NOT ${PREFIX}_FIND_QUIETLY) |
| 116 | + message(FATAL_ERROR "Required library ${PREFIX} not found.") |
85 | 117 | endif () |
| 118 | + endif () |
86 | 119 |
|
87 | | - if (NOT TARGET "TBB::${TARGET_NAME}") |
88 | | - add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED) |
| 120 | + if (NOT TARGET "TBB::${TARGET_NAME}") |
| 121 | + if (${PREFIX}_LIBRARY_RELEASE) |
| 122 | + tbb_extract_real_library(${${PREFIX}_LIBRARY_RELEASE} real_release) |
| 123 | + endif () |
| 124 | + if (${PREFIX}_LIBRARY_DEBUG) |
| 125 | + tbb_extract_real_library(${${PREFIX}_LIBRARY_DEBUG} real_debug) |
| 126 | + endif () |
| 127 | + add_library(TBB::${TARGET_NAME} UNKNOWN IMPORTED) |
| 128 | + set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
| 129 | + INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}") |
| 130 | + if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE) |
| 131 | + set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
| 132 | + IMPORTED_LOCATION "${real_release}" |
| 133 | + IMPORTED_LOCATION_DEBUG "${real_debug}" |
| 134 | + IMPORTED_LOCATION_RELEASE "${real_release}") |
| 135 | + elseif (${PREFIX}_LIBRARY_RELEASE) |
89 | 136 | set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
90 | | - INTERFACE_INCLUDE_DIRECTORIES "${${PREFIX}_INCLUDE_DIR}") |
91 | | - if (${PREFIX}_LIBRARY_DEBUG AND ${PREFIX}_LIBRARY_RELEASE) |
92 | | - set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
93 | | - IMPORTED_LOCATION "${${PREFIX}_LIBRARY_RELEASE}" |
94 | | - IMPORTED_LOCATION_DEBUG "${${PREFIX}_LIBRARY_DEBUG}" |
95 | | - IMPORTED_LOCATION_RELEASE "${${PREFIX}_LIBRARY_RELEASE}") |
96 | | - elseif (${PREFIX}_LIBRARY_RELEASE) |
97 | | - set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
98 | | - IMPORTED_LOCATION "${${PREFIX}_LIBRARY_RELEASE}") |
99 | | - elseif (${PREFIX}_LIBRARY_DEBUG) |
100 | | - set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
101 | | - IMPORTED_LOCATION "${${PREFIX}_LIBRARY_DEBUG}") |
102 | | - endif () |
| 137 | + IMPORTED_LOCATION "${real_release}") |
| 138 | + elseif (${PREFIX}_LIBRARY_DEBUG) |
| 139 | + set_target_properties(TBB::${TARGET_NAME} PROPERTIES |
| 140 | + IMPORTED_LOCATION "${real_debug}") |
103 | 141 | endif () |
104 | | - |
105 | | - #mark the following variables as internal variables |
106 | | - mark_as_advanced(${PREFIX}_INCLUDE_DIR |
107 | | - ${PREFIX}_LIBRARY |
108 | | - ${PREFIX}_LIBRARY_DEBUG |
109 | | - ${PREFIX}_LIBRARY_RELEASE) |
110 | 142 | endif () |
| 143 | + |
| 144 | + #mark the following variables as internal variables |
| 145 | + mark_as_advanced(${PREFIX}_INCLUDE_DIR |
| 146 | + ${PREFIX}_LIBRARY |
| 147 | + ${PREFIX}_LIBRARY_DEBUG |
| 148 | + ${PREFIX}_LIBRARY_RELEASE) |
111 | 149 | endmacro() |
112 | 150 |
|
113 | 151 | #=============================================== |
|
0 commit comments