Skip to content

Commit 2938c39

Browse files
committed
apply changes that went missing
1 parent bafd2d6 commit 2938c39

8 files changed

Lines changed: 195 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ option(PHASAR_BUILD_IR "Build IR test code (default is OFF)" OFF)
5151

5252
option(PHASAR_BUILD_DOC "Build documentation" OFF)
5353

54+
option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)
55+
5456
option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)
5557

5658
option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON)
@@ -103,7 +105,6 @@ endif()
103105
# Boost
104106
find_package(Boost 1.65.1 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
105107
include_directories(${Boost_INCLUDE_DIRS})
106-
add_definitions(-DBOOST_LOG_DYN_LINK)
107108

108109
# JSON library
109110
option(JSON_BuildTests OFF)
@@ -233,6 +234,8 @@ if (PHASAR_BUILD_IR)
233234
add_subdirectory(test)
234235
endif()
235236

237+
set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Install dir of headers")
238+
236239
# Install targets of phasar-llvm, other executables, and libraries are to be
237240
# found in the individual subdirectories of tools/
238241

@@ -273,6 +276,33 @@ install(DIRECTORY config/
273276
WORLD_READ
274277
)
275278

279+
install(EXPORT phasarTargets
280+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
281+
NAMESPACE phasar::
282+
FILE phasarTargets.cmake
283+
)
284+
285+
include(CMakePackageConfigHelpers)
286+
configure_package_config_file(
287+
Config.cmake.in
288+
phasarConfig.cmake
289+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
290+
PATH_VARS INCLUDE_INSTALL_DIR
291+
)
292+
293+
write_basic_package_version_file(
294+
${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake
295+
VERSION 1.0.0
296+
COMPATIBILITY SameMajorVersion
297+
)
298+
299+
### Install Config and ConfigVersion files
300+
install(
301+
FILES "${CMAKE_CURRENT_BINARY_DIR}/phasarConfig.cmake"
302+
"${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake"
303+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
304+
)
305+
276306
# If the Phasar shared object libraries are not installed into a system folder
277307
# the so libs must be added manually to the linker search path and the linker
278308
# config must be updated as follows:

Config.cmake.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set(PHASAR_VERSION 1.0.0)
2+
3+
@PACKAGE_INIT@
4+
set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
5+
include( "${CMAKE_CURRENT_LIST_DIR}/phasarTargets.cmake" )
6+
7+
check_required_components(phasar)

cmake/phasar_macros.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ macro(add_phasar_library name)
161161
set(libkind)
162162
endif()
163163
add_library( ${name} ${libkind} ${srcs} )
164+
add_library( phasar::${name} ALIAS ${name} )
164165
if( LLVM_COMMON_DEPENDS )
165166
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
166167
endif( LLVM_COMMON_DEPENDS )
@@ -173,6 +174,11 @@ macro(add_phasar_library name)
173174
if(PHASAR_LINK_LIBS)
174175
foreach(lib ${PHASAR_LINK_LIBS})
175176
target_link_libraries(${name} LINK_PRIVATE ${lib})
177+
if(PHASAR_DEBUG_LIBDEPS)
178+
target_link_libraries(${name} LINK_PRIVATE ${lib})
179+
else()
180+
target_link_libraries(${name} LINK_PUBLIC ${lib})
181+
endif(PHASAR_DEBUG_LIBDEPS)
176182
endforeach(lib)
177183
endif(PHASAR_LINK_LIBS)
178184

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
3+
project(PhasarExttoolTest)
4+
5+
set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
6+
set(CMAKE_CXX_STANDARD 17)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
set(CMAKE_CXX_EXTENSIONS OFF)
9+
10+
11+
# Build a small test tool to show how phasar may be used
12+
add_executable(myphasartool
13+
myphasartool.cpp
14+
)
15+
16+
find_package(phasar)
17+
include_directories(${PHASAR_INCLUDE_DIR})
18+
link_directories(${PHASAR_LIBRARY_DIR})
19+
20+
target_link_libraries(myphasartool
21+
LINK_PUBLIC
22+
phasar::phasar_config
23+
phasar::phasar_controller
24+
phasar::phasar_db
25+
phasar::phasar_experimental
26+
phasar::phasar_clang
27+
phasar::phasar_controlflow
28+
phasar::phasar_ifdside
29+
phasar::phasar_mono
30+
phasar::phasar_passes
31+
phasar::phasar_pointer
32+
phasar::phasar_typehierarchy
33+
phasar::phasar_phasarllvm_utils
34+
# phasar::phasar_utils #already introduced through phasar_clang
35+
)
36+
37+
install(TARGETS myphasartool
38+
RUNTIME DESTINATION bin
39+
LIBRARY DESTINATION lib
40+
ARCHIVE DESTINATION lib
41+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a demo tool that uses PhASAR as a library. Currently this is only supported in the f-CMakePackage feature branch of PhASAR. The number of phasar libraries explicitly stated in CMakeLists.txt can be further reduced by stating the non-transitive dependencies of phasar libraries. This is pending work on the PhASAR side.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/******************************************************************************
2+
* Copyright (c) 2017 Philipp Schubert.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Philipp Schubert and others
8+
*****************************************************************************/
9+
10+
#include <iostream>
11+
#include <fstream>
12+
13+
#include <boost/filesystem/operations.hpp>
14+
15+
#include <phasar/DB/ProjectIRDB.h>
16+
#include <phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h>
17+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h>
18+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IFDSLinearConstantAnalysis.h>
19+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h>
20+
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IFDSSolver.h>
21+
#include <phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h>
22+
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
23+
#include <phasar/Utils/Logger.h>
24+
25+
namespace llvm {
26+
class Value;
27+
} // namespace llvm
28+
29+
using namespace psr;
30+
31+
int main(int argc, const char **argv) {
32+
initializeLogger(false);
33+
auto &lg = lg::get();
34+
if (argc < 2 || !boost::filesystem::exists(argv[1]) ||
35+
boost::filesystem::is_directory(argv[1])) {
36+
std::cerr << "myphasartool\n"
37+
"A small PhASAR-based example program\n\n"
38+
"Usage: myphasartool <LLVM IR file>\n";
39+
return 1;
40+
}
41+
initializeLogger(false);
42+
ProjectIRDB DB({argv[1]});
43+
if (auto F = DB.getFunctionDefinition("main")) {
44+
LLVMTypeHierarchy H(DB);
45+
// print type hierarchy
46+
H.print();
47+
LLVMPointsToInfo P(DB);
48+
// print points-to information
49+
P.print();
50+
LLVMBasedICFG I(DB, CallGraphAnalysisType::OTF, {"main"}, &H, &P);
51+
// print inter-procedural control-flow graph
52+
I.print();
53+
// IFDS template parametrization test
54+
std::cout << "Testing IFDS:\n";
55+
IFDSLinearConstantAnalysis L(&DB, &H, &I, &P, {"main"});
56+
IFDSSolver<IFDSLinearConstantAnalysis::n_t, IFDSLinearConstantAnalysis::d_t,
57+
IFDSLinearConstantAnalysis::f_t, IFDSLinearConstantAnalysis::t_t,
58+
IFDSLinearConstantAnalysis::v_t, IFDSLinearConstantAnalysis::i_t>
59+
S(L);
60+
S.solve();
61+
S.dumpResults();
62+
// IDE template parametrization test
63+
std::cout << "Testing IDE:\n";
64+
IDELinearConstantAnalysis M(&DB, &H, &I, &P, {"main"});
65+
IDESolver<IDELinearConstantAnalysis::n_t, IDELinearConstantAnalysis::d_t,
66+
IDELinearConstantAnalysis::f_t, IDELinearConstantAnalysis::t_t,
67+
IDELinearConstantAnalysis::v_t, IDELinearConstantAnalysis::l_t,
68+
IDELinearConstantAnalysis::i_t>
69+
T(M);
70+
T.solve();
71+
T.dumpResults();
72+
} else {
73+
std::cerr << "error: file does not contain a 'main' function!\n";
74+
}
75+
return 0;
76+
}

lib/PhasarClang/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ file(GLOB_RECURSE PHASARCLANG_SRC *.h *.cpp)
22

33
include_directories(${CLANG_INCLUDE_DIRS})
44

5+
set(PHASAR_LINK_LIBS
6+
phasar_utils
7+
)
8+
59
set(LLVM_LINK_COMPONENTS
610
Support
711
Core

lib/Utils/CMakeLists.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ set(LLVM_LINK_COMPONENTS
1616
BitWriter
1717
)
1818

19-
2019
if(BUILD_SHARED_LIBS)
2120
add_phasar_library(phasar_utils
2221
SHARED
@@ -29,11 +28,40 @@ else()
2928
)
3029
endif()
3130

31+
set(LLVM_LINK_COMPONENTS
32+
coverage
33+
coroutines
34+
libdriver
35+
lto
36+
support
37+
analysis
38+
bitwriter
39+
core
40+
ipo
41+
irreader
42+
instcombine
43+
instrumentation
44+
linker
45+
objcarcopts
46+
scalaropts
47+
transformutils
48+
codegen
49+
vectorize
50+
)
51+
52+
llvm_map_components_to_libnames(llvm_libs
53+
${LLVM_LINK_COMPONENTS}
54+
)
55+
56+
target_include_directories(phasar_utils PUBLIC ${LLVM_INCLUDE_DIRS})
57+
target_compile_definitions(phasar_utils PUBLIC -DBOOST_LOG_DYN_LINK)
58+
3259
find_package(Boost COMPONENTS log REQUIRED)
3360
target_link_libraries(phasar_utils
3461
LINK_PUBLIC
3562
${Boost_LIBRARIES}
3663
${CMAKE_DL_LIBS}
64+
${llvm_libs}
3765
)
3866

3967
set_target_properties(phasar_utils

0 commit comments

Comments
 (0)