File: Workaround-missing-Z3-cmake-files.patch

package info (click to toggle)
slic3r-prusa 2.9.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 198,004 kB
  • sloc: cpp: 535,565; ansic: 71,269; yacc: 1,311; makefile: 256; lex: 241; sh: 113
file content (161 lines) | stat: -rw-r--r-- 6,165 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
From: Chow Loong Jin <hyperair@debian.org>
Date: Tue, 11 Mar 2025 01:06:33 +0800
Subject: Workaround missing Z3 cmake files

Needed until https://bugs.debian.org/1098281 is resolved.
---
 cmake/modules/FindZ3.cmake       | 126 +++++++++++++++++++++++++++++++++++++++
 src/libseqarrange/CMakeLists.txt |   5 +-
 2 files changed, 128 insertions(+), 3 deletions(-)
 create mode 100644 cmake/modules/FindZ3.cmake

diff --git a/cmake/modules/FindZ3.cmake b/cmake/modules/FindZ3.cmake
new file mode 100644
index 0000000..2981753
--- /dev/null
+++ b/cmake/modules/FindZ3.cmake
@@ -0,0 +1,126 @@
+INCLUDE(CheckCXXSourceRuns)
+
+# Function to check Z3's version
+function(check_z3_version z3_include z3_lib)
+  # Get lib path
+  set(z3_link_libs "${z3_lib}")
+
+  # Try to find a threading module in case Z3 was built with threading support.
+  # Threads are required elsewhere in LLVM, but not marked as required here because
+  # Z3 could have been compiled without threading support.
+  find_package(Threads)
+  # CMAKE_THREAD_LIBS_INIT may be empty if the thread functions are provided by the 
+  # system libraries and no special flags are needed.
+  if(CMAKE_THREAD_LIBS_INIT)
+    list(APPEND z3_link_libs "${CMAKE_THREAD_LIBS_INIT}")
+  endif()
+
+  # The program that will be executed to print Z3's version.
+  file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
+       "#include <assert.h>
+        #include <stdio.h> 
+        #include <z3.h>
+        int main(void) {
+          unsigned int major, minor, build, rev;
+          Z3_get_version(&major, &minor, &build, &rev);
+          printf(\"%u.%u.%u\", major, minor, build);
+          return 0;
+       }")
+
+  try_run(
+    Z3_RETURNCODE
+    Z3_COMPILED
+    ${CMAKE_BINARY_DIR}
+    ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testz3.cpp
+    COMPILE_DEFINITIONS -I"${z3_include}"
+    LINK_LIBRARIES ${z3_link_libs}
+    COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT
+    RUN_OUTPUT_VARIABLE SRC_OUTPUT
+  )
+
+  if(Z3_COMPILED)
+    string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)" "\\1"
+           z3_version "${SRC_OUTPUT}")
+    set(Z3_VERSION_STRING ${z3_version} PARENT_SCOPE)
+  else()
+    message(NOTICE "${COMPILE_OUTPUT}")
+    message(WARNING "Failed to compile Z3 program that is used to determine library version.")
+  endif()
+endfunction(check_z3_version)
+
+# Looking for Z3 in LLVM_Z3_INSTALL_DIR
+find_path(Z3_INCLUDE_DIR NAMES z3.h
+  NO_DEFAULT_PATH
+  PATHS ${LLVM_Z3_INSTALL_DIR}/include
+  PATH_SUFFIXES libz3 z3
+  )
+
+find_library(Z3_LIBRARIES NAMES z3 libz3
+  NO_DEFAULT_PATH
+  PATHS ${LLVM_Z3_INSTALL_DIR}
+  PATH_SUFFIXES lib bin
+  )
+
+# If Z3 has not been found in LLVM_Z3_INSTALL_DIR look in the default directories
+find_path(Z3_INCLUDE_DIR NAMES z3.h
+  PATH_SUFFIXES libz3 z3
+  )
+
+find_library(Z3_LIBRARIES NAMES z3 libz3
+  PATH_SUFFIXES lib bin
+  )
+
+# Searching for the version of the Z3 library is a best-effort task
+unset(Z3_VERSION_STRING)
+
+# First, try to check it dynamically, by compiling a small program that
+# prints Z3's version
+if(Z3_INCLUDE_DIR AND Z3_LIBRARIES AND NOT CMAKE_CROSSCOMPILING)
+  # We do not have the Z3 binary to query for a version. Try to use
+  # a small C++ program to detect it via the Z3_get_version() API call.
+  check_z3_version(${Z3_INCLUDE_DIR} ${Z3_LIBRARIES})
+endif()
+
+# If the dynamic check fails, we might be cross compiling: if that's the case,
+# check the version in the headers, otherwise, fail with a message
+if(NOT Z3_VERSION_STRING AND (CMAKE_CROSSCOMPILING AND
+                              Z3_INCLUDE_DIR AND
+                              EXISTS "${Z3_INCLUDE_DIR}/z3_version.h"))
+  # TODO: print message warning that we couldn't find a compatible lib?
+
+  # Z3 4.8.1+ has the version is in a public header.
+  file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
+       z3_version_str REGEX "^#define[\t ]+Z3_MAJOR_VERSION[\t ]+.*")
+  string(REGEX REPLACE "^.*Z3_MAJOR_VERSION[\t ]+([0-9]+).*$" "\\1"
+         Z3_MAJOR "${z3_version_str}")
+
+  file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
+       z3_version_str REGEX "^#define[\t ]+Z3_MINOR_VERSION[\t ]+.*")
+  string(REGEX REPLACE "^.*Z3_MINOR_VERSION[\t ]+([0-9]+).*$" "\\1"
+         Z3_MINOR "${z3_version_str}")
+
+  file(STRINGS "${Z3_INCLUDE_DIR}/z3_version.h"
+       z3_version_str REGEX "^#define[\t ]+Z3_BUILD_NUMBER[\t ]+.*")
+  string(REGEX REPLACE "^.*Z3_BUILD_NUMBER[\t ]+([0-9]+).*$" "\\1"
+         Z3_BUILD "${z3_version_str}")
+
+  set(Z3_VERSION_STRING ${Z3_MAJOR}.${Z3_MINOR}.${Z3_BUILD})
+  unset(z3_version_str)
+endif()
+
+if(NOT Z3_VERSION_STRING)
+  # Give up: we are unable to obtain a version of the Z3 library. Be
+  # conservative and force the found version to 0.0.0 to make version
+  # checks always fail.
+  set(Z3_VERSION_STRING "0.0.0")
+  message(WARNING "Failed to determine Z3 library version, defaulting to 0.0.0.")
+endif()
+
+# handle the QUIETLY and REQUIRED arguments and set Z3_FOUND to TRUE if
+# all listed variables are TRUE
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Z3
+                                  REQUIRED_VARS Z3_LIBRARIES Z3_INCLUDE_DIR
+                                  VERSION_VAR Z3_VERSION_STRING)
+
+mark_as_advanced(Z3_INCLUDE_DIR Z3_LIBRARIES)
diff --git a/src/libseqarrange/CMakeLists.txt b/src/libseqarrange/CMakeLists.txt
index 416f84a..a19e93c 100644
--- a/src/libseqarrange/CMakeLists.txt
+++ b/src/libseqarrange/CMakeLists.txt
@@ -1,11 +1,10 @@
 find_package(Z3 REQUIRED)
-slic3r_remap_configs("z3::libz3" RelWithDebInfo Release)
 
 
 
 add_library(libseqarrange STATIC src/seq_interface.cpp src/seq_preprocess.cpp src/seq_sequential.cpp src/seq_utilities.cpp)
-target_include_directories(libseqarrange PUBLIC include PRIVATE src )
-target_link_libraries(libseqarrange PUBLIC libslic3r PRIVATE z3::libz3)
+target_include_directories(libseqarrange PUBLIC include PRIVATE src ${Z3_INCLUDE_DIR})
+target_link_libraries(libseqarrange PUBLIC libslic3r PRIVATE ${Z3_LIBRARIES})
 
 add_executable(sequential_decimator src/sequential_decimator.cpp)
 target_include_directories(sequential_decimator PRIVATE include)