File: FindLDSymVer.cmake

package info (click to toggle)
rdma-core 33.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,844 kB
  • sloc: ansic: 145,804; python: 5,688; sh: 2,761; perl: 1,465; makefile: 73
file content (62 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
# COPYRIGHT (c) 2016 Obsidian Research Corporation.
# Licensed under BSD (MIT variant) or GPLv2. See COPYING.
# find_package helper to detect symbol version support in the compiler and
# linker. If supported then LDSYMVER_MODE will be set to GNU

# Basic sample GNU style map file
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.map" "
IBVERBS_1.0 {
        global:
                ibv_get_device_list;
        local: *;
};

IBVERBS_1.1 {
        global:
                ibv_get_device_list;
} IBVERBS_1.0;
")

# See RDMA_CHECK_C_LINKER_FLAG
set(SAFE_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
set(SAFE_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
if (POLICY CMP0056)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/test.map")
else()
  set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/test.map")
endif()

# And matching source, this also checks that .symver asm works
if (HAVE_FUNC_ATTRIBUTE_SYMVER)
  check_c_source_compiles("
  void ibv_get_device_list_1(void);
  __attribute((__symver__(\"ibv_get_device_list@IBVERBS_1.1\")))
  void ibv_get_device_list_1(void){}
  void ibv_get_device_list_0(void);
  __attribute((__symver__(\"ibv_get_device_list@IBVERBS_1.0\")))
  void ibv_get_device_list_0(void){}
  int main(int argc,const char *argv[]){return 0;}" _LDSYMVER_SUCCESS)
else()
  check_c_source_compiles("
  void ibv_get_device_list_1(void);
  void ibv_get_device_list_1(void){}
  asm(\".symver ibv_get_device_list_1, ibv_get_device_list@IBVERBS_1.1\");
  void ibv_get_device_list_0(void);
  void ibv_get_device_list_0(void){}
  asm(\".symver ibv_get_device_list_0, ibv_get_device_list@@IBVERBS_1.0\");
  int main(int argc,const char *argv[]){return 0;}" _LDSYMVER_SUCCESS)
endif()

file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/test.map")
set(CMAKE_EXE_LINKER_FLAGS "${SAFE_CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_REQUIRED_LIBRARIES "${SAFE_CMAKE_REQUIRED_LIBRARIES}")

if (_LDSYMVER_SUCCESS)
  set(LDSYMVER_MODE "GNU" CACHE INTERNAL "How to set symbol versions on shared libraries")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
  LDSymVer
  REQUIRED_VARS LDSYMVER_MODE
  )