File: vtkUndefinedSymbolsAllowed.cmake

package info (click to toggle)
vtk9 9.1.0%2Breally9.1.0%2Bdfsg2-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 153,832 kB
  • sloc: cpp: 1,800,419; ansic: 261,033; python: 86,332; yacc: 4,033; java: 3,977; xml: 3,068; sh: 2,702; perl: 2,189; lex: 1,761; objc: 143; makefile: 139; tcl: 59
file content (56 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (10)
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
# Detect if we've run with these flags before or not.
string(MD5 flags_hash "${CMAKE_SHARED_LINKER_FLAGS}")
if (NOT undefined_symbol_flag_hash STREQUAL flags_hash)
  # If we have a try_compile result, but no validation hash,
  # `-Dvtk_undefined_symbols_allowed` was passed on the command line; trust it.
  # Further changes to CMAKE_SHARED_LINKER_FLAGS will cause a recheck however.
  if (DEFINED undefined_symbol_flag_hash)
    # New (or untested) flags; clear the old result.
    unset(vtk_undefined_symbols_allowed CACHE)
  endif ()
  # Store that we've tested this hash.
  set(undefined_symbol_flag_hash "${flags_hash}"
    CACHE INTERNAL "undefined symbol detection hash")
endif ()

# If we don't have a result, run its test.
if (NOT DEFINED "vtk_undefined_symbols_allowed")
  set(test_project_dir "${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp/vtk_undefined_symbols_allowed")
  file(WRITE "${test_project_dir}/CMakeLists.txt"
"cmake_minimum_required(VERSION 3.8...3.12)
project(undefined C)
add_library(undefined SHARED uses_undefined.c)
add_executable(undefined_exe main.c)
target_link_libraries(undefined_exe PRIVATE undefined)
")
  file(WRITE "${test_project_dir}/uses_undefined.c"
"extern int undefined(void);
int uses_undefined(void) {
  return undefined() + 1;
}
")
  file(WRITE "${test_project_dir}/main.c"
"extern int uses_undefined(void);
int main(void) {
  return uses_undefined();
}
")

  try_compile(vtk_undefined_symbols_allowed
    "${test_project_dir}"
    "${test_project_dir}"
    undefined
    CMAKE_FLAGS
      "-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}"
      ${_rpath_arg}
    OUTPUT_VARIABLE output)

  if (vtk_undefined_symbols_allowed)
    message(STATUS "Performing Test vtk_undefined_symbols_allowed - Success")
  else ()
    message(STATUS "Performing Test vtk_undefined_symbols_allowed - Failed")
    file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
      "Performing Test vtk_undefined_symbols_allowed failed with the "
      "following output:\n${output}\n")
  endif ()
endif ()