Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
godlygeek committed Sep 24, 2024
1 parent 8724c58 commit 4dd729a
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(memray)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Find Python
find_package(Python COMPONENTS Interpreter Development.Module Development.SABIModule REQUIRED)
Expand All @@ -15,16 +16,28 @@ endif()

# Find required packages
find_package(PkgConfig REQUIRED)
pkg_check_modules(LZ4 REQUIRED liblz4)
pkg_check_modules(LZ4 liblz4)
if(NOT LZ4_FOUND)
message(FATAL_ERROR "LZ4 library not found. Please install liblz4-dev or equivalent.")
message(FATAL_ERROR "liblz4 not found. Please install liblz4-dev or equivalent.")
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
pkg_check_modules(UNWIND REQUIRED libunwind)
pkg_check_modules(UNWIND libunwind)
if(NOT UNWIND_FOUND)
message(FATAL_ERROR "libunwind not found. Please install libunwind-dev or equivalent.")
endif()

pkg_check_modules(DEBUGINFOD libdebuginfod)
if(NOT DEBUGINFOD_LIBRARIES)
set(DEBUGINFOD_LIBRARIES "debuginfod")
if(NOT DEBUGINFOD_FOUND)
# Some systems don't have a libdebuginfod.pc file.
# See if there's a libdebuginfod.so wherever liblz4 or libunwind are.
include(CheckLibraryExists)
check_library_exists("libdebuginfod.so" "debuginfod_find_debuginfo" "${LZ4_LIBRARY_DIRS};${UNWIND_LIBRARY_DIRS}" DEBUGINFOD)
if(DEBUGINFOD)
set(DEBUGINFOD_LIBRARIES "debuginfod")
else()
message(FATAL_ERROR "libdebuginfod not found. Please install libdebuginfod-dev or equivalent.")
endif()
endif()
endif()

Expand Down Expand Up @@ -122,11 +135,21 @@ target_link_libraries(_memray PRIVATE
${DEBUGINFOD_LIBRARIES}
dl
)
set_target_properties(_memray PROPERTIES INSTALL_RPATH "${DEBUGINFOD_LIBRARY_DIRS}")

set(CMAKE_BUILD_RPATH "${LZ4_LIBRARY_DIRS}:")
target_link_options(_memray PRIVATE ${LZ4_LDFLAGS} ${UNWIND_LDFLAGS} ${DEBUGINFOD_LDFLAGS})
target_compile_options(_memray PRIVATE ${LZ4_CFLAGS} ${UNWIND_CFLAGS} ${DEBUGINFOD_CFLAGS})
target_link_directories(_memray PRIVATE
${LZ4_LIBRARY_DIRS}
${UNWIND_LIBRARY_DIRS}
${DEBUGINFOD_LIBRARY_DIRS}
)
target_link_options(_memray PRIVATE
${LZ4_LDFLAGS}
${UNWIND_LDFLAGS}
${DEBUGINFOD_LDFLAGS}
)
target_compile_options(_memray PRIVATE
${LZ4_CFLAGS}
${UNWIND_CFLAGS}
${DEBUGINFOD_CFLAGS}
)
add_dependencies(_memray libbacktrace)

# _test_utils extension
Expand Down Expand Up @@ -164,11 +187,6 @@ python_add_library(_inject MODULE WITH_SOABI USE_SABI 3.7
target_include_directories(_inject PRIVATE
${CMAKE_SOURCE_DIR}/src/memray
)
target_compile_options(_test_utils PRIVATE ${COMPILER_FLAGS})
target_link_options(_test_utils PRIVATE ${LINKER_FLAGS})
target_compile_options(_inject PRIVATE ${COMPILER_FLAGS})
target_link_options(_inject PRIVATE ${LINKER_FLAGS})


# Install targets
install(TARGETS _memray _test_utils _inject LIBRARY DESTINATION memray)

0 comments on commit 4dd729a

Please sign in to comment.