blob: dcf805a78ebfa72040ad8b6308428d64e0de6b00 [file] [log] [blame]
Hao Chen1c8ea5b2023-10-20 23:03:45 +00001function(add_aidl_library NAME LANG SOURCES AIDLFLAGS)
2 if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
3 cmake_policy(SET CMP0116 NEW)
4 endif()
5
6 set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/.intermediates/${NAME}-source")
7 set(GEN_SOURCES)
8 foreach(SOURCE ${SOURCES})
9 get_filename_component(SOURCE_WE ${SOURCE} NAME_WE)
10 get_filename_component(SOURCE_ABSOLUTE ${SOURCE} ABSOLUTE)
11 get_filename_component(SOURCE_DIR ${SOURCE_ABSOLUTE} DIRECTORY)
12 set(GEN_SOURCE "${GEN_DIR}/${SOURCE_WE}.cpp")
13 set(DEPFILE_ARG)
14 if (NOT ${CMAKE_GENERATOR} MATCHES "Unix Makefiles")
15 set(DEPFILE_ARG DEPFILE "${GEN_SOURCE}.d")
16 endif()
17 add_custom_command(
18 OUTPUT "${GEN_SOURCE}"
19 MAIN_DEPENDENCY "${SOURCE_ABSOLUTE}"
20 ${DEPFILE_ARG}
21 COMMAND "${AIDL_BIN}"
22 ARGS
23 --lang=${LANG}
24 --include="${SOURCE_DIR}"
25 --dep="${GEN_SOURCE}.d"
26 --out="${GEN_DIR}"
27 --header_out="${GEN_DIR}/include"
28 --ninja
29 --structured
30 --min_sdk_version=current
31 ${AIDLFLAGS}
32 "${SOURCE_ABSOLUTE}"
33 )
34 list(APPEND GEN_SOURCES "${GEN_SOURCE}")
35 endforeach()
36
37 add_library(${NAME} ${GEN_SOURCES})
38
39 target_include_directories(${NAME}
40 PUBLIC
41 "${GEN_DIR}/include"
42 "${ANDROID_BUILD_TOP}/frameworks/native/libs/binder/ndk/include_${LANG}"
43 )
44 target_link_libraries(${NAME}
45 libbinder_sdk
46 )
47endfunction()