Skip to content

feat/conan2 #744

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

Merged
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ Dockerfile @janniclas
/include/phasar/Utils/OnTheFlyAnalysisPrinter.h @sritejakv
/include/phasar/PhasarLLVM/Utils/SourceMgrPrinter.h @sritejakv
/lib/PhasarLLVM/Utils/SourceMgrPrinter.cpp @sritejakv

/conanfile.py @jusito
/utils/conan/ @jusito
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
bin/*

# build directories for cmake
build/
build_*/
build-*/
build*/
cmake-build*/
cmake-install*/
CMakeUserPresets.json
venv/

# LLVM project
llvm-project/*
Expand All @@ -26,6 +28,7 @@ doc/*

# log/ directory
log/*
**/*/logs/

# CMake build dir
build/*
Expand All @@ -49,6 +52,9 @@ build/*

# ignore all auto-generated LLVM IR code
*.ll
!utils/conan/llvm-core/all/test_package/test_function.ll
!test_package/example.ll
!test_package_cmake/example.ll

# auto generated test files
*.test
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ repos:
rev: v4.3.0
hooks:
- id: trailing-whitespace
exclude: "^.*\\.patch$"
- id: end-of-file-fixer
exclude: "^.*\\.patch$"
- id: check-yaml
- id: check-added-large-files
- id: requirements-txt-fixer
Expand Down
29 changes: 16 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ option(PHASAR_BUILD_DOC "Build documentation" OFF)
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)

option(PHASAR_BUILD_TOOLS "Build PhASAR-based tools (default is ON)" ${PHASAR_BUILD_OPTIONAL_TARGETS_DEFAULT})
option(PHASAR_USE_CONAN "Using Conan for dependencies instead of submodules." OFF)

#option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
option(PHASAR_BUILD_DYNLIB "Build one fat shared library. Requires BUILD_SHARED_LIBS to be turned OFF (default is OFF)" OFF)
Expand Down Expand Up @@ -216,7 +217,8 @@ else()
message(STATUS "Dynamic log disabled")
endif()

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

Expand Down Expand Up @@ -430,18 +432,19 @@ if(NOT PHASAR_IN_TREE)
install(TARGETS phasar_interface
EXPORT PhasarExports
)

# Install the export-set containing all the phasar targets
install(EXPORT PhasarExports
FILE PhasarExports.cmake
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"
)
if (NOT PHASAR_USE_CONAN)
# Install the export-set containing all the phasar targets
install(EXPORT PhasarExports
FILE PhasarExports.cmake
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"
)
endif()
else()
install(TARGETS phasar_interface
EXPORT LLVMExports
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sudo ninja install

## How to use PhASAR?

We recomment using phasar as a library with `cmake`.
We recomment using phasar as a library with `cmake` or `conan`.

If you already have installed phasar, [Use-PhASAR-as-a-library](https://github.com/secure-software-engineering/phasar/wiki/Using-Phasar-as-a-Library) may be a good start.

Expand All @@ -200,6 +200,19 @@ Depending on your use of PhASAR you also may need to add LLVM to your build.

For more information please consult our [PhASAR wiki pages](https://github.com/secure-software-engineering/phasar/wiki).

## How to use with Conan v2 ?

To export the recipe and dependencies execute from repo root:
- `conan export utils/conan/llvm-core/ --version 14.0.6 --user secure-software-engineering`
- `conan export utils/conan/clang/ --version 14.0.6 --user secure-software-engineering`
- `conan export .`
- View exported `conan list "phasar/*"`
- [Consume the package](https://docs.conan.io/2/tutorial/consuming_packages.html)

If you just want to use phasar-cli:
- `conan install --tool-requires phasar/... --build=missing -of .`
- `source conanbuild.sh`
- `phasar-cli --help`

## Please help us to improve PhASAR

Expand Down
17 changes: 13 additions & 4 deletions cmake/add_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ macro(add_llvm)
set(USE_LLVM_FAT_LIB ON)
endif()

if (NOT USE_LLVM_FAT_LIB)
if (PHASAR_USE_CONAN)
set(LLVM_ENABLE_RTTI ON)
elseif (NOT USE_LLVM_FAT_LIB)
message(STATUS "Link against individual LLVM modules")
set(LLVM_REQUIRED_LIBRARIES
Core
Expand Down Expand Up @@ -42,7 +44,7 @@ macro(add_llvm)
message(WARNING "Did not find the LLVM modules ${LLVM_SMALL_LIB_NOTFOUND_PRETTY}. Fallback to link against ${LLVM_LIBRARY}. To silence this warning, set -DUSE_LLVM_FAT_LIB=ON in the cmake invocation.")
endif()
endif(DEFINED LLVM_SMALL_LIB_NOTFOUND)
endif(NOT USE_LLVM_FAT_LIB)
endif()
endif(NOT PHASAR_IN_TREE)

if(NOT LLVM_ENABLE_RTTI AND NOT PHASAR_IN_TREE)
Expand All @@ -53,8 +55,15 @@ endmacro()

macro(add_clang)
# The clang-cpp shared library is now the preferred way to link dynamically against libclang if we build out of tree.
if(NOT PHASAR_IN_TREE)
find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp HINTS ${LLVM_LIBRARY_DIRS})
if (PHASAR_USE_CONAN)
find_package(Clang REQUIRED)
set(CLANG_LIBRARY clangCodeGen clangTooling)
elseif(NOT PHASAR_IN_TREE)
if (USE_LLVM_FAT_LIB)
find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp HINTS ${LLVM_LIBRARY_DIRS})
else()
find_library(CLANG_LIBRARY NAMES clangCodeGen clangTooling HINTS ${LLVM_LIBRARY_DIRS})
endif()
if(${CLANG_LIBRARY} STREQUAL "CLANG_LIBRARY-NOTFOUND")
set(NEED_LIBCLANG_COMPONENT_LIBS ON)
endif()
Expand Down
100 changes: 54 additions & 46 deletions cmake/add_nlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -1,60 +1,68 @@

function(add_nlohmann_json)
set(JSON_BuildTests OFF)
set(JSON_Install OFF)
if (PHASAR_USE_CONAN)
find_package(nlohmann_json REQUIRED)
else()
set(JSON_BuildTests OFF)
set(JSON_Install OFF)

if (PHASAR_IN_TREE)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json)
endif()
if (PHASAR_IN_TREE)
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json)
endif()

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

add_subdirectory(external/json EXCLUDE_FROM_ALL)
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
)
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
)
endif()
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()
if (PHASAR_USE_CONAN)
find_package(nlohmann_json_schema_validator REQUIRED)
else()
# 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)
set(JSON_VALIDATOR_INSTALL OFF)

set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)

add_subdirectory(external/json-schema-validator EXCLUDE_FROM_ALL)
add_subdirectory(external/json-schema-validator EXCLUDE_FROM_ALL)

set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})

set_property(TARGET nlohmann_json_schema_validator APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
)
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
)
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
)
endif()
endfunction()
Loading