-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathwhole_archive.cmake
53 lines (49 loc) · 2.11 KB
/
whole_archive.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
#[[
function links static library without removing any symbol from it.
ov_target_link_whole_archive(<target name> <lib1> [<lib2> ...])
Example:
ov_target_link_whole_archive("FunctionalTests" "CommonLib" "AnotherLib")
#]]
function(ov_target_link_whole_archive targetName)
foreach(staticLib IN LISTS ARGN)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# CMake does not support generator expression in LINK_FLAGS, so we workaround it a little bit:
# passing same static library as normal link (to get build deps working, and includes too), than using WHOLEARCHIVE option
# it's important here to not use slash '/' for option !
if(CMAKE_GENERATOR MATCHES "Visual Studio")
# MSBuild is unhappy when parsing double quotes in combination with WHOLEARCHIVE flag.
# remove quotes from path - so build path with spaces not supported, but it's better than nothing.
list(APPEND libs ${staticLib}
"-WHOLEARCHIVE:$<TARGET_FILE:${staticLib}>"
)
if(CMAKE_CURRENT_BINARY_DIR MATCHES " ")
message(WARNING "Visual Studio CMake generator may cause problems if your build directory contains spaces. "
"Remove spaces from path or select different generator.")
endif()
else()
list(APPEND libs ${staticLib}
"-WHOLEARCHIVE:\"$<TARGET_FILE:${staticLib}>\""
)
endif()
elseif(OV_COMPILER_IS_APPLECLANG)
list(APPEND libs
"-Wl,-all_load"
${staticLib}
"-Wl,-noall_load"
)
else()
# non-Apple Clang and GCC / MinGW
list(APPEND libs
"-Wl,--whole-archive"
${staticLib}
"-Wl,--no-whole-archive"
)
endif()
endforeach()
if(libs)
target_link_libraries(${targetName} PRIVATE ${libs})
endif()
endfunction()