3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-10-20 14:20:31 +00:00

Fix FetchContent C++ header include path issue

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-08-26 02:01:41 +00:00
parent 6a356f78c1
commit 1f92ccfe72

View file

@ -105,6 +105,13 @@ FetchContent_Declare(Z3
GIT_TAG z3-4.12.1
)
FetchContent_MakeAvailable(Z3)
# Add the C++ API include directory for z3++.h
if(TARGET libz3)
target_include_directories(libz3 INTERFACE
$<BUILD_INTERFACE:${z3_SOURCE_DIR}/src/api/c++>
)
endif()
```
Once fetched, you can link the z3 library to your target:
@ -113,9 +120,12 @@ Once fetched, you can link the z3 library to your target:
target_link_libraries(yourTarget PRIVATE libz3)
```
**Note**: The target name is `libz3` (referring to the library target from `src/CMakeLists.txt`). The target automatically provides the necessary include directories, so no manual `include_directories()` call is needed.
**Important notes for FetchContent approach**:
- The target name is `libz3` (referring to the library target from `src/CMakeLists.txt`)
- An additional include directory for `src/api/c++` is added to enable `#include "z3++.h"` in C++ code
- Without the additional include directory, you would need `#include "c++/z3++.h"` instead
**Alternative using target alias** (for consistency with system installs):
**Recommended: Create an alias for consistency with system installs**:
```cmake
# Create an alias for consistency with system install
@ -179,6 +189,13 @@ else()
)
FetchContent_MakeAvailable(Z3)
# Add the C++ API include directory for z3++.h
if(TARGET libz3)
target_include_directories(libz3 INTERFACE
$<BUILD_INTERFACE:${z3_SOURCE_DIR}/src/api/c++>
)
endif()
# Create an alias to match the system install target name
if(NOT TARGET z3::libz3)
add_library(z3::libz3 ALIAS libz3)