Skip to content
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
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ option(PHASAR_BUILD_IR "Build IR test code (default is OFF)" OFF)

option(PHASAR_BUILD_DOC "Build documentation" OFF)

option(PHASAR_DEBUG_LIBDEPS "Debug internal library dependencies (private linkage)" OFF)

option(BUILD_SHARED_LIBS "Build shared libraries (default is ON)" ON)

option(PHASAR_ENABLE_WARNINGS "Enable warnings" ON)
Expand Down Expand Up @@ -101,7 +103,6 @@ endif()
# Boost
find_package(Boost 1.65.1 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_definitions(-DBOOST_LOG_DYN_LINK)

# JSON library
option(JSON_BuildTests OFF)
Expand Down Expand Up @@ -231,6 +232,8 @@ if (PHASAR_BUILD_IR)
add_subdirectory(test)
endif()

set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Install dir of headers")

# Install targets of phasar-llvm, other executables, and libraries are to be
# found in the individual subdirectories of tools/

Expand Down Expand Up @@ -271,6 +274,33 @@ install(DIRECTORY config/
WORLD_READ
)

install(EXPORT phasarTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
NAMESPACE phasar::
FILE phasarTargets.cmake
)

include(CMakePackageConfigHelpers)
configure_package_config_file(
Config.cmake.in
phasarConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
PATH_VARS INCLUDE_INSTALL_DIR
)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake
VERSION 1.0.0
COMPATIBILITY SameMajorVersion
)

### Install Config and ConfigVersion files
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/phasarConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
)

# If the Phasar shared object libraries are not installed into a system folder
# the so libs must be added manually to the linker search path and the linker
# config must be updated as follows:
Expand Down
7 changes: 7 additions & 0 deletions Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(PHASAR_VERSION 1.0.0)

@PACKAGE_INIT@
set_and_check(PHASAR_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
include( "${CMAKE_CURRENT_LIST_DIR}/phasarTargets.cmake" )

check_required_components(phasar)
8 changes: 7 additions & 1 deletion cmake/phasar_macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ macro(add_phasar_library name)
set(libkind)
endif()
add_library( ${name} ${libkind} ${srcs} )
add_library( phasar::${name} ALIAS ${name} )
if( LLVM_COMMON_DEPENDS )
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
endif( LLVM_COMMON_DEPENDS )
Expand All @@ -171,7 +172,11 @@ macro(add_phasar_library name)

if(PHASAR_LINK_LIBS)
foreach(lib ${PHASAR_LINK_LIBS})
target_link_libraries(${name} LINK_PRIVATE ${lib})
if(PHASAR_DEBUG_LIBDEPS)
target_link_libraries(${name} LINK_PRIVATE ${lib})
else()
target_link_libraries(${name} LINK_PUBLIC ${lib})
endif(PHASAR_DEBUG_LIBDEPS)
endforeach(lib)
endif(PHASAR_LINK_LIBS)

Expand All @@ -188,6 +193,7 @@ macro(add_phasar_library name)
endif(MSVC)
install(TARGETS ${name}
EXPORT LLVMExports
EXPORT phasarTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
Expand Down
41 changes: 41 additions & 0 deletions examples/use-phasar-as-library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.12)

project(PhasarExttoolTest)

set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


# Build a small test tool to show how phasar may be used
add_executable(myphasartool
myphasartool.cpp
)

find_package(phasar)
include_directories(${PHASAR_INCLUDE_DIR})
link_directories(${PHASAR_LIBRARY_DIR})

target_link_libraries(myphasartool
LINK_PUBLIC
phasar::phasar_config
phasar::phasar_controller
phasar::phasar_db
phasar::phasar_experimental
phasar::phasar_clang
phasar::phasar_controlflow
phasar::phasar_ifdside
phasar::phasar_mono
phasar::phasar_passes
phasar::phasar_pointer
phasar::phasar_typehierarchy
phasar::phasar_phasarllvm_utils
# phasar::phasar_utils #already introduced through phasar_clang
)

install(TARGETS myphasartool
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
1 change: 1 addition & 0 deletions examples/use-phasar-as-library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +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.
76 changes: 76 additions & 0 deletions examples/use-phasar-as-library/myphasartool.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/******************************************************************************
* Copyright (c) 2017 Philipp Schubert.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Philipp Schubert and others
*****************************************************************************/

#include <iostream>
#include <fstream>

#include <boost/filesystem/operations.hpp>

#include <phasar/DB/ProjectIRDB.h>
#include <phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h>
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h>
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IFDSLinearConstantAnalysis.h>
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IDESolver.h>
#include <phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Solver/IFDSSolver.h>
#include <phasar/PhasarLLVM/Pointer/LLVMPointsToInfo.h>
#include <phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h>
#include <phasar/Utils/Logger.h>

namespace llvm {
class Value;
} // namespace llvm

using namespace psr;

int main(int argc, const char **argv) {
initializeLogger(false);
auto &lg = lg::get();
if (argc < 2 || !boost::filesystem::exists(argv[1]) ||
boost::filesystem::is_directory(argv[1])) {
std::cerr << "myphasartool\n"
"A small PhASAR-based example program\n\n"
"Usage: myphasartool <LLVM IR file>\n";
return 1;
}
initializeLogger(false);
ProjectIRDB DB({argv[1]});
if (auto F = DB.getFunctionDefinition("main")) {
LLVMTypeHierarchy H(DB);
// print type hierarchy
H.print();
LLVMPointsToInfo P(DB);
// print points-to information
P.print();
LLVMBasedICFG I(DB, CallGraphAnalysisType::OTF, {"main"}, &H, &P);
// print inter-procedural control-flow graph
I.print();
// IFDS template parametrization test
std::cout << "Testing IFDS:\n";
IFDSLinearConstantAnalysis L(&DB, &H, &I, &P, {"main"});
IFDSSolver<IFDSLinearConstantAnalysis::n_t, IFDSLinearConstantAnalysis::d_t,
IFDSLinearConstantAnalysis::m_t, IFDSLinearConstantAnalysis::t_t,
IFDSLinearConstantAnalysis::v_t, IFDSLinearConstantAnalysis::i_t>
S(L);
S.solve();
S.dumpResults();
// IDE template parametrization test
std::cout << "Testing IDE:\n";
IDELinearConstantAnalysis M(&DB, &H, &I, &P, {"main"});
IDESolver<IDELinearConstantAnalysis::n_t, IDELinearConstantAnalysis::d_t,
IDELinearConstantAnalysis::m_t, IDELinearConstantAnalysis::t_t,
IDELinearConstantAnalysis::v_t, IDELinearConstantAnalysis::l_t,
IDELinearConstantAnalysis::i_t>
T(M);
T.solve();
T.dumpResults();
} else {
std::cerr << "error: file does not contain a 'main' function!\n";
}
return 0;
}
4 changes: 4 additions & 0 deletions lib/PhasarClang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ file(GLOB_RECURSE PHASARCLANG_SRC *.h *.cpp)

include_directories(${CLANG_INCLUDE_DIRS})

set(PHASAR_LINK_LIBS
phasar_utils
)

set(LLVM_LINK_COMPONENTS
Support
Core
Expand Down
30 changes: 29 additions & 1 deletion lib/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set(LLVM_LINK_COMPONENTS
BitWriter
)


if(BUILD_SHARED_LIBS)
add_phasar_library(phasar_utils
SHARED
Expand All @@ -29,11 +28,40 @@ else()
)
endif()

set(LLVM_LINK_COMPONENTS
coverage
coroutines
libdriver
lto
support
analysis
bitwriter
core
ipo
irreader
instcombine
instrumentation
linker
objcarcopts
scalaropts
transformutils
codegen
vectorize
)

llvm_map_components_to_libnames(llvm_libs
${LLVM_LINK_COMPONENTS}
)

target_include_directories(phasar_utils PUBLIC ${LLVM_INCLUDE_DIRS})
target_compile_definitions(phasar_utils PUBLIC -DBOOST_LOG_DYN_LINK)

find_package(Boost COMPONENTS log REQUIRED)
target_link_libraries(phasar_utils
LINK_PUBLIC
${Boost_LIBRARIES}
${CMAKE_DL_LIBS}
${llvm_libs}
)

set_target_properties(phasar_utils
Expand Down