From 1f92ccfe727196408237545de1ed1d5fa4efdd58 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 Aug 2025 02:01:41 +0000 Subject: [PATCH] Fix FetchContent C++ header include path issue Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> --- README-CMake.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/README-CMake.md b/README-CMake.md index f3434ab53..774aa9c7b 100644 --- a/README-CMake.md +++ b/README-CMake.md @@ -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 + $ + ) +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 + $ + ) + endif() + # Create an alias to match the system install target name if(NOT TARGET z3::libz3) add_library(z3::libz3 ALIAS libz3)