diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2016-07-12 17:26:55 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-13 16:47:43 (GMT) |
commit | 42ce9f1e7178b3535726c0c885cc7c9f760cc8b6 (patch) | |
tree | 6ebd228d18eb0b08ff2d950900574dd29caad95d /Tests/RunCMake/AndroidMK | |
parent | d5257063b04a95aca3d144f860698a3c7181e554 (diff) | |
download | CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.zip CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.tar.gz CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.tar.bz2 |
Add support for creating prebuilt Android.mk files
Add options to the `install()` and `export()` commands to export the
targets we build into Android.mk files that reference them as prebuilt
libraries with associated usage requirements (compile definitions,
include directories, link libraries). This will allow CMake-built
projects to be imported into projects using the Android NDK build
system.
Closes: #15562
Diffstat (limited to 'Tests/RunCMake/AndroidMK')
-rw-r--r-- | Tests/RunCMake/AndroidMK/AndroidMK-check.cmake | 30 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/AndroidMK.cmake | 11 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/RunCMakeTest.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt | 23 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt | 25 | ||||
-rw-r--r-- | Tests/RunCMake/AndroidMK/foo.cxx | 3 |
7 files changed, 97 insertions, 0 deletions
diff --git a/Tests/RunCMake/AndroidMK/AndroidMK-check.cmake b/Tests/RunCMake/AndroidMK/AndroidMK-check.cmake new file mode 100644 index 0000000..691e326 --- /dev/null +++ b/Tests/RunCMake/AndroidMK/AndroidMK-check.cmake @@ -0,0 +1,30 @@ +# This file does a regex file compare on the generated +# Android.mk files from the AndroidMK test + +macro(compare_file_to_expected file expected_file) + file(READ "${file}" ANDROID_MK) + # clean up new lines + string(REGEX REPLACE "\r\n" "\n" ANDROID_MK "${ANDROID_MK}") + string(REGEX REPLACE "\n+$" "" ANDROID_MK "${ANDROID_MK}") + # read in the expected regex file + file(READ "${expected_file}" expected) + # clean up new lines + string(REGEX REPLACE "\r\n" "\n" expected "${expected}") + string(REGEX REPLACE "\n+$" "" expected "${expected}") + # compare the file to the expected regex and if there is not a match + # put an error message in RunCMake_TEST_FAILED + if(NOT "${ANDROID_MK}" MATCHES "${expected}") + set(RunCMake_TEST_FAILED + "${file} does not match ${expected_file}: + +Android.mk contents = [\n${ANDROID_MK}\n] +Expected = [\n${expected}\n]") + endif() +endmacro() + +compare_file_to_expected( +"${RunCMake_BINARY_DIR}/AndroidMK-build/Android.mk" +"${RunCMake_TEST_SOURCE_DIR}/expectedBuildAndroidMK.txt") +compare_file_to_expected( +"${RunCMake_BINARY_DIR}/AndroidMK-build/CMakeFiles/Export/share/ndk-modules/Android.mk" +"${RunCMake_TEST_SOURCE_DIR}/expectedInstallAndroidMK.txt") diff --git a/Tests/RunCMake/AndroidMK/AndroidMK.cmake b/Tests/RunCMake/AndroidMK/AndroidMK.cmake new file mode 100644 index 0000000..ed21e58 --- /dev/null +++ b/Tests/RunCMake/AndroidMK/AndroidMK.cmake @@ -0,0 +1,11 @@ +project(build) +set(CMAKE_BUILD_TYPE Debug) +add_library(foo foo.cxx) +add_library(car foo.cxx) +add_library(bar foo.cxx) +add_library(dog foo.cxx) +target_link_libraries(foo car bar dog debug -lm) +export(TARGETS bar dog car foo ANDROID_MK + ${build_BINARY_DIR}/Android.mk) +install(TARGETS bar dog car foo DESTINATION lib EXPORT myexp) +install(EXPORT_ANDROID_MK myexp DESTINATION share/ndk-modules) diff --git a/Tests/RunCMake/AndroidMK/CMakeLists.txt b/Tests/RunCMake/AndroidMK/CMakeLists.txt new file mode 100644 index 0000000..576787a --- /dev/null +++ b/Tests/RunCMake/AndroidMK/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.5) +project(${RunCMake_TEST} NONE) # or languages needed +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/AndroidMK/RunCMakeTest.cmake b/Tests/RunCMake/AndroidMK/RunCMakeTest.cmake new file mode 100644 index 0000000..786d45b --- /dev/null +++ b/Tests/RunCMake/AndroidMK/RunCMakeTest.cmake @@ -0,0 +1,2 @@ +include(RunCMake) +run_cmake(AndroidMK) diff --git a/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt b/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt new file mode 100644 index 0000000..def8fcb --- /dev/null +++ b/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt @@ -0,0 +1,23 @@ +LOCAL_PATH.*call my-dir.* +include.*CLEAR_VARS.* +LOCAL_MODULE.*bar +LOCAL_SRC_FILES.*bar.* +include.*PREBUILT_STATIC_LIBRARY.* +.* +include.*CLEAR_VARS.* +LOCAL_MODULE.*dog +LOCAL_SRC_FILES.*.*dog.* +include.*PREBUILT_STATIC_LIBRARY.* +.* +include.*CLEAR_VARS.* +LOCAL_MODULE.*car +LOCAL_SRC_FILES.*.*car.* +include.*PREBUILT_STATIC_LIBRARY.* +.* +include.*CLEAR_VARS.* +LOCAL_MODULE.*foo +LOCAL_SRC_FILES.*.*foo.* +LOCAL_CPP_FEATURES.*rtti exceptions +LOCAL_STATIC_LIBRARIES.*car bar dog +LOCAL_EXPORT_LDLIBS := -lm +include.*PREBUILT_STATIC_LIBRARY.* diff --git a/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt b/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt new file mode 100644 index 0000000..1bdb308 --- /dev/null +++ b/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt @@ -0,0 +1,25 @@ +LOCAL_PATH.*call my-dir.* +_IMPORT_PREFIX.*LOCAL_PATH./../.. + +include.*CLEAR_VARS.* +LOCAL_MODULE.*bar +LOCAL_SRC_FILES.*_IMPORT_PREFIX./lib.*bar.* +include.*PREBUILT_STATIC_LIBRARY.* + +include.*CLEAR_VARS. +LOCAL_MODULE.*dog +LOCAL_SRC_FILES.*_IMPORT_PREFIX./lib.*dog.* +include.*PREBUILT_STATIC_LIBRARY.* + +include.*CLEAR_VARS.* +LOCAL_MODULE.*car +LOCAL_SRC_FILES.*_IMPORT_PREFIX./lib.*car.* +include.*PREBUILT_STATIC_LIBRARY.* + +include.*CLEAR_VARS.* +LOCAL_MODULE.*foo +LOCAL_SRC_FILES.*_IMPORT_PREFIX\)/lib.*foo.* +LOCAL_CPP_FEATURES.*rtti exceptions +LOCAL_STATIC_LIBRARIES.*car bar dog +LOCAL_EXPORT_LDLIBS := -lm +include.*PREBUILT_STATIC_LIBRARY.* diff --git a/Tests/RunCMake/AndroidMK/foo.cxx b/Tests/RunCMake/AndroidMK/foo.cxx new file mode 100644 index 0000000..3695dc9 --- /dev/null +++ b/Tests/RunCMake/AndroidMK/foo.cxx @@ -0,0 +1,3 @@ +void foo() +{ +} |