3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-26 13:06:05 +00:00

Document how to use system-installed Z3 with CMake projects (#7809)

* Initial plan

* Add documentation for using system-installed Z3 with CMake

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
Copilot 2025-08-23 14:23:49 -07:00 committed by GitHub
parent 7e6e96f6aa
commit ba068d751c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -119,6 +119,30 @@ target_link_libraries(yourTarget libz3)
``` ```
Note that this is `libz3` not `z3` (`libz3` refers to the library target from `src/CMakeLists.txt`). Note that this is `libz3` not `z3` (`libz3` refers to the library target from `src/CMakeLists.txt`).
#### Using system-installed Z3
If you have Z3 installed on your system (e.g., via package manager or by building and installing Z3 yourself), you can use CMake's `find_package` to locate it:
```cmake
find_package(Z3 REQUIRED CONFIG)
```
Once found, you can use the Z3 include directories and libraries:
```cmake
# For C projects
target_include_directories(yourTarget PRIVATE ${Z3_C_INCLUDE_DIRS})
target_link_libraries(yourTarget PRIVATE ${Z3_LIBRARIES})
# For C++ projects
target_include_directories(yourTarget PRIVATE ${Z3_CXX_INCLUDE_DIRS})
target_link_libraries(yourTarget PRIVATE ${Z3_LIBRARIES})
```
The `find_package(Z3 CONFIG)` approach uses Z3's provided `Z3Config.cmake` file, which is installed to a standard location (typically `<prefix>/lib/cmake/z3/`). If CMake cannot automatically find Z3, you can help it by setting `-DZ3_DIR=<path>` where `<path>` is the directory containing the `Z3Config.cmake` file.
**Note**: This approach requires that Z3 was built and installed using CMake. Z3 installations from the Python build system may not provide the necessary CMake configuration files.
### Ninja ### Ninja