forked from haolongzhangm/dmabuffer_alloc_trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
47 lines (41 loc) · 2.21 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
cmake_minimum_required(VERSION 3.23)
set(VERSION_SCRIPT ${CMAKE_SOURCE_DIR}/version_script.ld)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -fPIC")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(ANDROID OR OHOS)
# now old ANDROID have libc++_shared.so, new ANDROID have libc++.so so we use
# libc++_static by default, by set ANDROID_STL=c++_static only take effect on old NDK,
# so we force config by use xxx_LINKER_FLAGS
message(STATUS "config static-libstdc++ for ANDROID or OHOS")
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
endif()
# Check if using Clang
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${VERSION_SCRIPT}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
add_subdirectory(aosp_file)
if (ANDROID_ABI MATCHES "arm64-v8a")
set(VNDK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aosp_file/com.android.vndk.v30/lib64")
set(APEX_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aosp_file/com.android.runtime/lib64")
else ()
set(VNDK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aosp_file/com.android.vndk.v30/lib")
set(APEX_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/aosp_file/com.android.runtime/lib")
endif ()
add_library(dma_alloc_hook SHARED ${CMAKE_SOURCE_DIR}/src/dma_alloc_hook.cpp)
target_link_libraries(dma_alloc_hook PRIVATE backtrace_header)
install(TARGETS dma_alloc_hook DESTINATION ${CMAKE_INSTALL_PREFIX}/out/lib)
add_library(checkleak SHARED ${CMAKE_SOURCE_DIR}/src/checkleak.cpp)
target_link_directories(checkleak PRIVATE ${VNDK_LIB_PATH} ${APEX_LIB_PATH})
target_link_libraries(checkleak PRIVATE log backtrace backtrace_header c_malloc_debug)
install(TARGETS checkleak DESTINATION ${CMAKE_INSTALL_PREFIX}/out/lib)
# copy database compile_commands.json to PROJECT_SOURCE_DIR
add_custom_target(
copy_database_compile_commands_mem_trace ALL
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${PROJECT_BINARY_DIR}/compile_commands.json
${PROJECT_SOURCE_DIR}/compile_commands.json)