Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p4tool: Fix build with Z3 installed in non-standard path #3932

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions backends/p4tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ project(P4TOOLS VERSION ${P4C_SEM_VERSION_STRING})
# inherit FindLibGc.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# We need a fairly recent version of Z3.
set(Z3_MIN_VERSION "4.8.14")
# But 4.12+ is currently broken with libGC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kinda unfortunate. Is this issue reported somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fabian would know more, see also #3930 (comment).

set(Z3_MAX_VERSION_EXCL "4.12")
find_package(Z3 ${Z3_MIN_VERSION} REQUIRED)

if(NOT DEFINED Z3_VERSION_STRING OR ${Z3_VERSION_STRING} VERSION_LESS ${Z3_MIN_VERSION})
message(FATAL_ERROR "The minimum required Z3 version is ${Z3_MIN_VERSION}. Has ${Z3_VERSION_STRING}.")
endif()
if (${Z3_VERSION_STRING} VERSION_GREATER_EQUAL ${Z3_MAX_VERSION_EXCL})
message(FATAL_ERROR "The Z3 version has to be lower than ${Z3_MAX_VERSION_EXCL} (the latter currently does no work with libGC). Has ${Z3_VERSION_STRING}.")
endif()

# GSL-lite is needed for testgen.
add_subdirectory(submodules/gsl-lite EXCLUDE_FROM_ALL)

Expand Down
4 changes: 3 additions & 1 deletion backends/p4tools/cmake/FindZ3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ find_path(
NAMES z3++.h
HINTS ${PC_Z3_INCLUDEDIR} ${PC_Z3_INCLUDE_DIRS}
PATH_SUFFIXES z3 Z3
DOC "A path to the directory that contain Z3 include files (e.g. z3.h & z3++.h)."
)

find_library(
Z3_LIBRARY
NAMES z3
HINTS ${PC_Z3_LIBDIR} ${PC_Z3_LIBRARY_DIRS}
DOC "A path to the library file of Z3 (i.e. libz3). This can be dynamic or static library."
)

find_program(
Expand Down Expand Up @@ -51,7 +53,7 @@ if(Z3_FOUND)
endif()

message(STATUS "Z3 version: ${Z3_VERSION_STRING}")
message(STATUS "Z3 lib dir: ${Z3_LIBRARY}")
message(STATUS "Z3 library: ${Z3_LIBRARY}")
message(STATUS "Z3 include dir: ${Z3_INCLUDE_DIR}")

# create imported target z3::z3
Expand Down
10 changes: 1 addition & 9 deletions backends/p4tools/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ include(common)

project(p4tools-common)

# We need a fairly recent version of Z3.
set(Z3_MIN_VERSION "4.8.14")
find_package(Z3 ${Z3_MIN_VERSION} REQUIRED)

if(NOT DEFINED Z3_VERSION_STRING OR ${Z3_VERSION_STRING} VERSION_LESS ${Z3_MIN_VERSION})
message(FATAL_ERROR "The minimum required Z3 version is ${Z3_MIN_VERSION}. Has ${Z3_VERSION_STRING}.")
endif()

# Boost filesystem is required for path handling.
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -64,7 +56,7 @@ target_link_libraries(
PUBLIC gsl-lite
PUBLIC ${Boost_SYSTEM_LIBRARY}
PUBLIC ${Boost_FILESYSTEM_LIBRARY}
PUBLIC ${Z3_LIBRARY}
PUBLIC z3::z3
)

target_include_directories(
Expand Down