mirror of
https://github.com/Z3Prover/z3
synced 2025-08-25 12:35:59 +00:00
[CMake] Implement generation of Z3Config.cmake
and Z3Target.cmake
file for the build and install tree. These files allow users of CMake to use Z3 via a CMake config package. Clients can do `find_package(Z3 CONFIG)` to get use the package from their projects. When generating the files for the install tree we try to generate the files so that they are relocatable so that it shouldn't matter if the installed files aren't in the CMAKE_INSTALL_PREFIX when a user consumes them. As long as the relative locations of the files aren't changed things should still work. A new CMake cache variable `CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR` has been added so that the install location of the Z3 CMake package files can be controlled. This addresses #915 .
This commit is contained in:
parent
e2933350b2
commit
73614abf37
4 changed files with 110 additions and 0 deletions
|
@ -398,10 +398,18 @@ set(CMAKE_INSTALL_PKGCONFIGDIR
|
|||
PATH
|
||||
"Directory to install pkgconfig files"
|
||||
)
|
||||
|
||||
set(CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR
|
||||
"${CMAKE_INSTALL_LIBDIR}/cmake/z3"
|
||||
CACHE
|
||||
PATH
|
||||
"Directory to install Z3 CMake package files"
|
||||
)
|
||||
message(STATUS "CMAKE_INSTALL_LIBDIR: \"${CMAKE_INSTALL_LIBDIR}\"")
|
||||
message(STATUS "CMAKE_INSTALL_BINDIR: \"${CMAKE_INSTALL_BINDIR}\"")
|
||||
message(STATUS "CMAKE_INSTALL_INCLUDEDIR: \"${CMAKE_INSTALL_INCLUDEDIR}\"")
|
||||
message(STATUS "CMAKE_INSTALL_PKGCONFIGDIR: \"${CMAKE_INSTALL_PKGCONFIGDIR}\"")
|
||||
message(STATUS "CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR: \"${CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR}\"")
|
||||
|
||||
################################################################################
|
||||
# Uninstall rule
|
||||
|
@ -449,6 +457,76 @@ include(${CMAKE_SOURCE_DIR}/cmake/z3_add_component.cmake)
|
|||
include(${CMAKE_SOURCE_DIR}/cmake/z3_append_linker_flag_list_to_target.cmake)
|
||||
add_subdirectory(src)
|
||||
|
||||
################################################################################
|
||||
# Create `Z3Config.cmake` and related files for the build tree so clients can
|
||||
# use Z3 via CMake.
|
||||
################################################################################
|
||||
include(CMakePackageConfigHelpers)
|
||||
export(EXPORT Z3_EXPORTED_TARGETS
|
||||
NAMESPACE z3::
|
||||
FILE "${CMAKE_BINARY_DIR}/Z3Targets.cmake"
|
||||
)
|
||||
set(Z3_FIRST_PACKAGE_INCLUDE_DIR "${CMAKE_BINARY_DIR}/src/api")
|
||||
set(Z3_SECOND_PACKAGE_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/api")
|
||||
set(Z3_CXX_PACKAGE_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/api/c++")
|
||||
set(AUTO_GEN_MSG "Automatically generated. DO NOT EDIT")
|
||||
set(CONFIG_FILE_TYPE "build tree")
|
||||
configure_package_config_file("${CMAKE_SOURCE_DIR}/cmake/Z3Config.cmake.in"
|
||||
"Z3Config.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_BINARY_DIR}"
|
||||
PATH_VARS
|
||||
Z3_FIRST_PACKAGE_INCLUDE_DIR
|
||||
Z3_SECOND_PACKAGE_INCLUDE_DIR
|
||||
Z3_CXX_PACKAGE_INCLUDE_DIR
|
||||
INSTALL_PREFIX "${CMAKE_BINARY_DIR}"
|
||||
)
|
||||
unset(Z3_FIRST_PACKAGE_INCLUDE_DIR)
|
||||
unset(Z3_SECOND_PACKAGE_INCLUDE_DIR)
|
||||
unset(Z3_CXX_PACKAGE_INCLUDE_DIR)
|
||||
unset(AUTO_GEN_MSG)
|
||||
unset(CONFIG_FILE_TYPE)
|
||||
# TODO: Provide a `Z3Version.cmake` file so that clients can specify the version
|
||||
# of Z3 they want.
|
||||
|
||||
################################################################################
|
||||
# Create `Z3Config.cmake` and related files for install tree so clients can use
|
||||
# Z3 via CMake.
|
||||
################################################################################
|
||||
install(EXPORT
|
||||
Z3_EXPORTED_TARGETS
|
||||
FILE "Z3Targets.cmake"
|
||||
NAMESPACE z3::
|
||||
DESTINATION "${CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR}"
|
||||
)
|
||||
set(Z3_INSTALL_TREE_CMAKE_CONFIG_FILE "${CMAKE_BINARY_DIR}/cmake/Z3Config.cmake")
|
||||
set(Z3_FIRST_PACKAGE_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
set(Z3_SECOND_INCLUDE_DIR "")
|
||||
set(Z3_CXX_PACKAGE_INCLUDE_DIR "")
|
||||
set(AUTO_GEN_MSG "Automatically generated. DO NOT EDIT")
|
||||
set(CONFIG_FILE_TYPE "install tree")
|
||||
# We use `configure_package_config_file()` to try and create CMake files
|
||||
# that are re-locatable so that it doesn't matter if the files aren't placed
|
||||
# in the original install prefix.
|
||||
configure_package_config_file("${CMAKE_SOURCE_DIR}/cmake/Z3Config.cmake.in"
|
||||
"${Z3_INSTALL_TREE_CMAKE_CONFIG_FILE}"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR}"
|
||||
PATH_VARS Z3_FIRST_PACKAGE_INCLUDE_DIR
|
||||
)
|
||||
unset(Z3_FIRST_PACKAGE_INCLUDE_DIR)
|
||||
unset(Z3_SECOND_PACKAGE_INCLUDE_DIR)
|
||||
unset(Z3_CXX_PACKAGE_INCLUDE_DIR)
|
||||
unset(AUTO_GEN_MSG)
|
||||
unset(CONFIG_FILE_TYPE)
|
||||
|
||||
# Add install rule to install ${Z3_INSTALL_TREE_CMAKE_CONFIG_FILE}
|
||||
install(
|
||||
FILES "${Z3_INSTALL_TREE_CMAKE_CONFIG_FILE}"
|
||||
DESTINATION "${CMAKE_INSTALL_Z3_CMAKE_PACKAGE_DIR}"
|
||||
)
|
||||
|
||||
# TODO: Provide a `Z3Version.cmake` file so that clients can specify the version
|
||||
# of Z3 they want.
|
||||
|
||||
################################################################################
|
||||
# Examples
|
||||
################################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue