From fb19922ea5734efc63aad11a673708bc0cfda09c Mon Sep 17 00:00:00 2001 From: Fabian Schiebel Date: Mon, 4 Mar 2024 19:30:12 +0100 Subject: [PATCH] Do not install phasar's dependencies to the global namespace anymore --- CMakeLists.txt | 50 ++++++++++++++--------------------- Config.cmake.in | 7 +++-- cmake/add_nlohmann_json.cmake | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 34 deletions(-) create mode 100644 cmake/add_nlohmann_json.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ddf030ca..98d53d667 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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 @@ -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) @@ -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) @@ -507,6 +498,11 @@ 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 @@ -514,12 +510,6 @@ else() 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 diff --git a/Config.cmake.in b/Config.cmake.in index 305cf04e2..f160d869b 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -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@) diff --git a/cmake/add_nlohmann_json.cmake b/cmake/add_nlohmann_json.cmake new file mode 100644 index 000000000..4ee85bb6b --- /dev/null +++ b/cmake/add_nlohmann_json.cmake @@ -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(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(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()