Skip to content

Commit 2c111b5

Browse files
jusitofabianbs96
andauthored
feat/conan2 (#744)
* deploy(conan): +Conan v2 recipe * deploy(conan): fix nlohmann dep * deploy(conan): fix clang should be linked static * deploy(conan): recipe requires v2 * deploy(conan): fix deps recipes * deploy(conan): recipes should use proper user * deploy(conan): fix dyn user / version * deploy(conan): default category for unknown components / linker flags * deploy(conan): add fPIC * deploy(conan): rm legacy package option * deploy(conan): build tools * doc(conan): update readme * clean(conan): minor review * clean(conan): use link instead of copy * clean(conan): fix pre-commit * deploy(conan): fix ci? libclang-cpp.so forced linking to libLLVM.so * Use PHASAR_LLVM_VERSION to refer to the llvm version in the cmake configuration * deploy(conan): fix review --------- Co-authored-by: Fabian Schiebel <[email protected]>
1 parent 590f19f commit 2c111b5

34 files changed

+2036
-90
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ Dockerfile @janniclas
3232
/include/phasar/Utils/OnTheFlyAnalysisPrinter.h @sritejakv
3333
/include/phasar/PhasarLLVM/Utils/SourceMgrPrinter.h @sritejakv
3434
/lib/PhasarLLVM/Utils/SourceMgrPrinter.cpp @sritejakv
35+
36+
/conanfile.py @jusito
37+
/utils/conan/ @jusito

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
bin/*
55

66
# build directories for cmake
7-
build/
8-
build_*/
9-
build-*/
7+
build*/
8+
cmake-build*/
9+
cmake-install*/
10+
CMakeUserPresets.json
11+
venv/
1012

1113
# LLVM project
1214
llvm-project/*
@@ -26,6 +28,7 @@ doc/*
2628

2729
# log/ directory
2830
log/*
31+
**/*/logs/
2932

3033
# CMake build dir
3134
build/*
@@ -49,6 +52,9 @@ build/*
4952

5053
# ignore all auto-generated LLVM IR code
5154
*.ll
55+
!utils/conan/llvm-core/all/test_package/test_function.ll
56+
!test_package/example.ll
57+
!test_package_cmake/example.ll
5258

5359
# auto generated test files
5460
*.test

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ repos:
55
rev: v4.3.0
66
hooks:
77
- id: trailing-whitespace
8+
exclude: "^.*\\.patch$"
89
- id: end-of-file-fixer
10+
exclude: "^.*\\.patch$"
911
- id: check-yaml
1012
- id: check-added-large-files
1113
- id: requirements-txt-fixer

CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ option(PHASAR_BUILD_DOC "Build documentation" OFF)
166166
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
167167

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

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

219-
if (NOT PHASAR_IN_TREE)
220+
if (PHASAR_USE_CONAN)
221+
elseif (NOT PHASAR_IN_TREE)
220222
# RPATH
221223
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
222224

@@ -430,18 +432,19 @@ if(NOT PHASAR_IN_TREE)
430432
install(TARGETS phasar_interface
431433
EXPORT PhasarExports
432434
)
433-
434-
# Install the export-set containing all the phasar targets
435-
install(EXPORT PhasarExports
436-
FILE PhasarExports.cmake
437-
NAMESPACE phasar::
438-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
439-
)
440-
install(EXPORT ${PHASAR_DEPS_EXPORT_SET}
441-
FILE ${PHASAR_DEPS_EXPORT_SET}.cmake
442-
NAMESPACE phasar::
443-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
444-
)
435+
if (NOT PHASAR_USE_CONAN)
436+
# Install the export-set containing all the phasar targets
437+
install(EXPORT PhasarExports
438+
FILE PhasarExports.cmake
439+
NAMESPACE phasar::
440+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
441+
)
442+
install(EXPORT ${PHASAR_DEPS_EXPORT_SET}
443+
FILE ${PHASAR_DEPS_EXPORT_SET}.cmake
444+
NAMESPACE phasar::
445+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
446+
)
447+
endif()
445448
else()
446449
install(TARGETS phasar_interface
447450
EXPORT LLVMExports

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ sudo ninja install
176176

177177
## How to use PhASAR?
178178

179-
We recomment using phasar as a library with `cmake`.
179+
We recomment using phasar as a library with `cmake` or `conan`.
180180

181181
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.
182182

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

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

203+
## How to use with Conan v2 ?
204+
205+
To export the recipe and dependencies execute from repo root:
206+
- `conan export utils/conan/llvm-core/ --version 14.0.6 --user secure-software-engineering`
207+
- `conan export utils/conan/clang/ --version 14.0.6 --user secure-software-engineering`
208+
- `conan export .`
209+
- View exported `conan list "phasar/*"`
210+
- [Consume the package](https://docs.conan.io/2/tutorial/consuming_packages.html)
211+
212+
If you just want to use phasar-cli:
213+
- `conan install --tool-requires phasar/... --build=missing -of .`
214+
- `source conanbuild.sh`
215+
- `phasar-cli --help`
203216

204217
## Please help us to improve PhASAR
205218

cmake/add_llvm.cmake

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ macro(add_llvm)
1313
set(USE_LLVM_FAT_LIB ON)
1414
endif()
1515

16-
if (NOT USE_LLVM_FAT_LIB)
16+
if (PHASAR_USE_CONAN)
17+
set(LLVM_ENABLE_RTTI ON)
18+
elseif (NOT USE_LLVM_FAT_LIB)
1719
message(STATUS "Link against individual LLVM modules")
1820
set(LLVM_REQUIRED_LIBRARIES
1921
Core
@@ -42,7 +44,7 @@ macro(add_llvm)
4244
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.")
4345
endif()
4446
endif(DEFINED LLVM_SMALL_LIB_NOTFOUND)
45-
endif(NOT USE_LLVM_FAT_LIB)
47+
endif()
4648
endif(NOT PHASAR_IN_TREE)
4749

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

5456
macro(add_clang)
5557
# The clang-cpp shared library is now the preferred way to link dynamically against libclang if we build out of tree.
56-
if(NOT PHASAR_IN_TREE)
57-
find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp HINTS ${LLVM_LIBRARY_DIRS})
58+
if (PHASAR_USE_CONAN)
59+
find_package(Clang REQUIRED)
60+
set(CLANG_LIBRARY clangCodeGen clangTooling)
61+
elseif(NOT PHASAR_IN_TREE)
62+
if (USE_LLVM_FAT_LIB)
63+
find_library(CLANG_LIBRARY NAMES clang-cpp libclang-cpp HINTS ${LLVM_LIBRARY_DIRS})
64+
else()
65+
find_library(CLANG_LIBRARY NAMES clangCodeGen clangTooling HINTS ${LLVM_LIBRARY_DIRS})
66+
endif()
5867
if(${CLANG_LIBRARY} STREQUAL "CLANG_LIBRARY-NOTFOUND")
5968
set(NEED_LIBCLANG_COMPONENT_LIBS ON)
6069
endif()

cmake/add_nlohmann_json.cmake

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,68 @@
11

22
function(add_nlohmann_json)
3-
set(JSON_BuildTests OFF)
4-
set(JSON_Install OFF)
3+
if (PHASAR_USE_CONAN)
4+
find_package(nlohmann_json REQUIRED)
5+
else()
6+
set(JSON_BuildTests OFF)
7+
set(JSON_Install OFF)
58

6-
if (PHASAR_IN_TREE)
7-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json)
8-
endif()
9+
if (PHASAR_IN_TREE)
10+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json)
11+
endif()
12+
13+
add_subdirectory(external/json EXCLUDE_FROM_ALL)
14+
set_property(TARGET nlohmann_json APPEND PROPERTY
15+
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
16+
)
917

10-
add_subdirectory(external/json EXCLUDE_FROM_ALL)
11-
set_property(TARGET nlohmann_json APPEND PROPERTY
12-
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
13-
)
14-
15-
install(TARGETS nlohmann_json
16-
EXPORT ${PHASAR_DEPS_EXPORT_SET}
17-
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
18-
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
19-
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
20-
)
21-
install(DIRECTORY external/json/include/
22-
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include
23-
)
18+
install(TARGETS nlohmann_json
19+
EXPORT ${PHASAR_DEPS_EXPORT_SET}
20+
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
21+
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
22+
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
23+
)
24+
install(DIRECTORY external/json/include/
25+
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include
26+
)
27+
endif()
2428
endfunction()
2529

2630
function(add_json_schema_validator)
27-
# We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here
28-
# The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator
29-
# is not installed, leading to linker error. But just including nlohmann_json is not sufficient, as
30-
# in the installed state the nlohmann_json_schema_validator needs the nlohmann_json package which needs
31-
# to be installed.
32-
# The following workaround may collapse or become unnecessary once the issue is
33-
# changed or fixed in nlohmann_json_schema_validator.
34-
if (PHASAR_IN_TREE)
35-
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json_schema_validator)
36-
endif()
31+
if (PHASAR_USE_CONAN)
32+
find_package(nlohmann_json_schema_validator REQUIRED)
33+
else()
34+
# We need to work around the behavior of nlohmann_json_schema_validator and nlohmann_json here
35+
# The validator needs the json part, but if you include it, the library of nlohmann_json_schema_validator
36+
# is not installed, leading to linker error. But just including nlohmann_json is not sufficient, as
37+
# in the installed state the nlohmann_json_schema_validator needs the nlohmann_json package which needs
38+
# to be installed.
39+
# The following workaround may collapse or become unnecessary once the issue is
40+
# changed or fixed in nlohmann_json_schema_validator.
41+
if (PHASAR_IN_TREE)
42+
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS nlohmann_json_schema_validator)
43+
endif()
3744

38-
set(JSON_VALIDATOR_INSTALL OFF)
45+
set(JSON_VALIDATOR_INSTALL OFF)
3946

40-
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
41-
set(BUILD_SHARED_LIBS OFF)
47+
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
48+
set(BUILD_SHARED_LIBS OFF)
4249

43-
add_subdirectory(external/json-schema-validator EXCLUDE_FROM_ALL)
50+
add_subdirectory(external/json-schema-validator EXCLUDE_FROM_ALL)
4451

45-
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})
52+
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})
4653

47-
set_property(TARGET nlohmann_json_schema_validator APPEND PROPERTY
48-
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
49-
)
54+
set_property(TARGET nlohmann_json_schema_validator APPEND PROPERTY
55+
INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:${PHASAR_DEPS_INSTALL_DESTINATION}/include>
56+
)
5057

51-
install(TARGETS nlohmann_json_schema_validator
52-
EXPORT ${PHASAR_DEPS_EXPORT_SET}
53-
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
54-
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
55-
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
56-
)
57-
install(FILES external/json-schema-validator/src/nlohmann/json-schema.hpp
58-
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include/nlohmann
59-
)
58+
install(TARGETS nlohmann_json_schema_validator
59+
EXPORT ${PHASAR_DEPS_EXPORT_SET}
60+
LIBRARY DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
61+
ARCHIVE DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/lib
62+
RUNTIME DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/bin
63+
)
64+
install(FILES external/json-schema-validator/src/nlohmann/json-schema.hpp
65+
DESTINATION ${PHASAR_DEPS_INSTALL_DESTINATION}/include/nlohmann
66+
)
67+
endif()
6068
endfunction()

0 commit comments

Comments
 (0)