1e831bfa87
- link correct libbinder for AIDL modules - fix building AIDL interfaces with non-empty AidlRoot - don't silently drop non-existent dependencies Bug: 302718225 Test: aosp/3081709 atest binder_sdk_docker_test_clang Change-Id: I181ef5a994f728f8af19134a6697b065a9aee261
68 lines
2.1 KiB
Text
68 lines
2.1 KiB
Text
function(add_aidl_library NAME LANG AIDLROOT SOURCES AIDLFLAGS)
|
|
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20")
|
|
cmake_policy(SET CMP0116 NEW)
|
|
endif()
|
|
|
|
# Strip trailing slash
|
|
get_filename_component(AIDLROOT_TRAILING "${AIDLROOT}" NAME)
|
|
if ("${AIDLROOT_TRAILING}" STREQUAL "")
|
|
get_filename_component(AIDLROOT "${AIDLROOT}foo" DIRECTORY)
|
|
endif()
|
|
|
|
set(GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/.intermediates/${NAME}-source")
|
|
set(GEN_SOURCES)
|
|
foreach (SOURCE ${SOURCES})
|
|
set(SOURCE_FULL ${AIDLROOT}/${SOURCE})
|
|
get_filename_component(SOURCE_WLE ${SOURCE} NAME_WLE)
|
|
get_filename_component(SOURCE_SUBDIR ${SOURCE} DIRECTORY)
|
|
set(GEN_SOURCE "${GEN_DIR}/${SOURCE_SUBDIR}/${SOURCE_WLE}.cpp")
|
|
|
|
file(READ "${SOURCE}" SOURCE_CONTENTS)
|
|
string(FIND "${SOURCE_CONTENTS}" "@VintfStability" VINTF_MATCH)
|
|
set(STABILITY_FLAG)
|
|
if (${VINTF_MATCH} GREATER_EQUAL 0)
|
|
set(STABILITY_FLAG --stability vintf)
|
|
endif()
|
|
|
|
set(DEPFILE_ARG)
|
|
if (NOT ${CMAKE_GENERATOR} MATCHES "Unix Makefiles")
|
|
set(DEPFILE_ARG DEPFILE "${GEN_SOURCE}.d")
|
|
endif()
|
|
|
|
add_custom_command(
|
|
OUTPUT "${GEN_SOURCE}"
|
|
MAIN_DEPENDENCY "${SOURCE_FULL}"
|
|
${DEPFILE_ARG}
|
|
COMMAND "${AIDL_BIN}"
|
|
ARGS
|
|
--lang=${LANG}
|
|
--include="${AIDLROOT}"
|
|
--dep="${GEN_SOURCE}.d"
|
|
--out="${GEN_DIR}"
|
|
--header_out="${GEN_DIR}/include"
|
|
--ninja
|
|
--structured
|
|
--min_sdk_version=current
|
|
${STABILITY_FLAG}
|
|
${AIDLFLAGS}
|
|
"${SOURCE_FULL}"
|
|
)
|
|
list(APPEND GEN_SOURCES "${GEN_SOURCE}")
|
|
endforeach()
|
|
|
|
add_library(${NAME} ${GEN_SOURCES})
|
|
|
|
target_include_directories(${NAME}
|
|
PUBLIC
|
|
"${GEN_DIR}/include"
|
|
)
|
|
|
|
if (${LANG} MATCHES "ndk")
|
|
set(BINDER_LIB_NAME "libbinder_ndk_sdk")
|
|
else()
|
|
set(BINDER_LIB_NAME "libbinder_sdk")
|
|
endif()
|
|
target_link_libraries(${NAME}
|
|
${BINDER_LIB_NAME}
|
|
)
|
|
endfunction()
|