Skip to content

Commit

Permalink
Do not install phasar's dependencies to the global namespace anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 committed Mar 4, 2024
1 parent 49ad944 commit fb19922
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 34 deletions.
50 changes: 20 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ else()
message(STATUS "Dynamic log disabled")
endif()

# RPATH
if (NOT PHASAR_IN_TREE)
# RPATH
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

if (NOT "${CMAKE_INSTALL_LIBDIR}" STREQUAL "lib")
Expand All @@ -217,6 +217,13 @@ if (NOT PHASAR_IN_TREE)
endif()

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Export set
set(PHASAR_DEPS_EXPORT_SET PhasarDepsExports)
set(PHASAR_DEPS_INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/phasar/deps)
else()
# Export set
set(PHASAR_DEPS_EXPORT_SET LLVMExports)
endif()

# Filesystem
Expand Down Expand Up @@ -257,30 +264,11 @@ find_package(Boost 1.65.1 COMPONENTS graph REQUIRED)
set(CMAKE_CXX_CLANG_TIDY "")

# Nlohmann JSON
set(JSON_BuildTests OFF)
set(JSON_Install ON)
add_subdirectory(external/json)

# We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here
# The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator
# is not installed, leading to linker error. But just including nlohmann_json is not sufficient, as
# in the installed state the nlohmann_json_schema_validator needs the nlohmann_json package which needs
# to be installed.
# The following workaround may collapse or become unnecessary once the issue is
# changed or fixed in nlohmann_json_schema_validator.

# Override option of nlohmann_json_schema_validator to not build its tests
set(BUILD_TESTS OFF CACHE BOOL "Build json-schema-validator-tests")

if (PHASAR_IN_TREE)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json_schema_validator)
include(add_nlohmann_json)

set (PHASAR_USE_Z3 OFF)
endif()

# Json Schema Validator
set(JSON_VALIDATOR_INSTALL ON)
add_subdirectory(external/json-schema-validator)
add_nlohmann_json()
add_json_schema_validator()

# Googletest
if (NOT PHASAR_IN_TREE)
Expand Down Expand Up @@ -350,7 +338,10 @@ if(NOT LLVM_ENABLE_RTTI AND NOT PHASAR_IN_TREE)
endif()

# Z3 Solver
if(PHASAR_USE_Z3)
if(PHASAR_IN_TREE)
set (PHASAR_USE_Z3 OFF)
endif()
if(PHASAR_USE_Z3 AND NOT PHASAR_IN_TREE)
# This z3-version is the same version LLVM requires; however, we cannot just use Z3 via the LLVM interface
# as it lacks some functionality (such as z3::expr::simplify()) that we require
find_package(Z3 4.7.1 REQUIRED)
Expand Down Expand Up @@ -507,19 +498,18 @@ if(NOT PHASAR_IN_TREE)
NAMESPACE phasar::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
)
install(EXPORT ${PHASAR_DEPS_EXPORT_SET}
FILE ${PHASAR_DEPS_EXPORT_SET}.cmake
NAMESPACE phasar::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
)
else()
install(TARGETS phasar_interface
EXPORT LLVMExports
)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS phasar_interface)
endif()

# Install the header only json container ### TODO Fix this!
install(DIRECTORY external/json/single_include/
DESTINATION include
FILES_MATCHING PATTERN "*.hpp"
)

# Install Phasar utils helper scripts
install(DIRECTORY utils/
DESTINATION bin
Expand Down
7 changes: 3 additions & 4 deletions Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(PHASAR_LIBRARY_DIR "@PACKAGE_LIBRARY_INSTALL_DIR@")

include (CMakeFindDependencyMacro)
find_dependency(nlohmann_json)
find_dependency(nlohmann_json_schema_validator)

find_package(Boost 1.65.1 COMPONENTS graph REQUIRED)
find_package(LLVM 14 REQUIRED CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/PhasarDepsExports.cmake")
find_dependency(Boost 1.65.1 COMPONENTS graph REQUIRED)
find_dependency(LLVM 14 REQUIRED CONFIG)

set(PHASAR_USE_LLVM_FAT_LIB @USE_LLVM_FAT_LIB@)
set(PHASAR_BUILD_DYNLIB @PHASAR_BUILD_DYNLIB@)
Expand Down
50 changes: 50 additions & 0 deletions cmake/add_nlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

function(add_nlohmann_json)
set(JSON_BuildTests OFF)
set(JSON_Install OFF)

add_subdirectory(external/json)
set_property(TARGET nlohmann_json APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
)

install(TARGETS nlohmann_json
EXPORT ${PHASAR_DEPS_EXPORT_SET}
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
)
install(DIRECTORY external/json/include/
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include
)
endfunction()

function(add_json_schema_validator)
# We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here
# The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator
# is not installed, leading to linker error. But just including nlohmann_json is not sufficient, as
# in the installed state the nlohmann_json_schema_validator needs the nlohmann_json package which needs
# to be installed.
# The following workaround may collapse or become unnecessary once the issue is
# changed or fixed in nlohmann_json_schema_validator.
if (PHASAR_IN_TREE)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json_schema_validator)
endif()

set(JSON_VALIDATOR_INSTALL OFF)

add_subdirectory(external/json-schema-validator)
set_property(TARGET nlohmann_json_schema_validator APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
)

install(TARGETS nlohmann_json_schema_validator
EXPORT ${PHASAR_DEPS_EXPORT_SET}
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
)
install(FILES external/json-schema-validator/src/nlohmann/json-schema.hpp
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include/nlohmann
)
endfunction()

0 comments on commit fb19922

Please sign in to comment.