Skip to content

Commit 121d8f5

Browse files
committed
This makes PhASAR a package that can be used via find_package() in an out-of-tree tool. Dependent libraries, include dirs and definitions are propagated to the out-of-tree tool. See https://github.com/MMory/OOTPhasarToolDemo for an example.
1 parent 02e5465 commit 121d8f5

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ endif()
101101
# Boost
102102
find_package(Boost 1.65.1 COMPONENTS filesystem graph system program_options log ${BOOST_THREAD} REQUIRED)
103103
include_directories(${Boost_INCLUDE_DIRS})
104-
add_definitions(-DBOOST_LOG_DYN_LINK)
105104

106105
# JSON library
107106
option(JSON_BuildTests OFF)
@@ -231,6 +230,8 @@ if (PHASAR_BUILD_IR)
231230
add_subdirectory(test)
232231
endif()
233232

233+
set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Install dir of headers")
234+
234235
# Install targets of phasar-llvm, other executables, and libraries are to be
235236
# found in the individual subdirectories of tools/
236237

@@ -271,6 +272,33 @@ install(DIRECTORY config/
271272
WORLD_READ
272273
)
273274

275+
install(EXPORT phasarTargets
276+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
277+
NAMESPACE phasar::
278+
FILE phasarTargets.cmake
279+
)
280+
281+
include(CMakePackageConfigHelpers)
282+
configure_package_config_file(
283+
Config.cmake.in
284+
phasarConfig.cmake
285+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phasar
286+
PATH_VARS INCLUDE_INSTALL_DIR
287+
)
288+
289+
write_basic_package_version_file(
290+
${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake
291+
VERSION 1.0.0
292+
COMPATIBILITY SameMajorVersion
293+
)
294+
295+
### Install Config and ConfigVersion files
296+
install(
297+
FILES "${CMAKE_CURRENT_BINARY_DIR}/phasarConfig.cmake"
298+
"${CMAKE_CURRENT_BINARY_DIR}/phasarConfigVersion.cmake"
299+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/phasar"
300+
)
301+
274302
# If the Phasar shared object libraries are not installed into a system folder
275303
# the so libs must be added manually to the linker search path and the linker
276304
# 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ macro(add_phasar_library name)
160160
set(libkind)
161161
endif()
162162
add_library( ${name} ${libkind} ${srcs} )
163+
add_library( phasar::${name} ALIAS ${name} )
163164
if( LLVM_COMMON_DEPENDS )
164165
add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
165166
endif( LLVM_COMMON_DEPENDS )
@@ -188,6 +189,7 @@ macro(add_phasar_library name)
188189
endif(MSVC)
189190
install(TARGETS ${name}
190191
EXPORT LLVMExports
192+
EXPORT phasarTargets
191193
LIBRARY DESTINATION lib
192194
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
193195
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})

lib/PhasarClang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ endif()
2222
find_package(Boost COMPONENTS log REQUIRED)
2323
target_link_libraries(phasar_clang
2424
LINK_PUBLIC
25+
phasar_utils
2526
clangTooling
2627
clangFrontendTool
2728
clangFrontend

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)