diff --git a/audio-echo/app/src/main/cpp/CMakeLists.txt b/audio-echo/app/src/main/cpp/CMakeLists.txt index 23a06ce08..deffbc97b 100644 --- a/audio-echo/app/src/main/cpp/CMakeLists.txt +++ b/audio-echo/app/src/main/cpp/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.22.1) project(echo LANGUAGES C CXX) -add_compile_options(-Wall -Wextra -Werror) +include(AppLibrary) -add_library(echo +add_app_library(echo SHARED audio_main.cpp audio_player.cpp diff --git a/base/src/main/cpp/CMakeLists.txt b/base/src/main/cpp/CMakeLists.txt index c70b4410d..9e4fb549f 100644 --- a/base/src/main/cpp/CMakeLists.txt +++ b/base/src/main/cpp/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.22.1) project(Base LANGUAGES CXX) -add_compile_options(-Wall -Werror -Wextra) +include(AppLibrary) -add_library(base +add_app_library(base STATIC logging.cpp ) diff --git a/bitmap-plasma/app/src/main/cpp/CMakeLists.txt b/bitmap-plasma/app/src/main/cpp/CMakeLists.txt index f068dc03a..37eef2aba 100644 --- a/bitmap-plasma/app/src/main/cpp/CMakeLists.txt +++ b/bitmap-plasma/app/src/main/cpp/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.22.1) -project(BitmapPlasma LANGUAGES C) +project(BitmapPlasma LANGUAGES CXX) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-unused-function") +include(AppLibrary) -add_library(plasma SHARED plasma.c) +add_app_library(plasma SHARED plasma.cpp) # Include libraries needed for plasma lib target_link_libraries(plasma diff --git a/bitmap-plasma/app/src/main/cpp/plasma.c b/bitmap-plasma/app/src/main/cpp/plasma.cpp similarity index 97% rename from bitmap-plasma/app/src/main/cpp/plasma.c rename to bitmap-plasma/app/src/main/cpp/plasma.cpp index b9e03efee..cb9e3f1eb 100644 --- a/bitmap-plasma/app/src/main/cpp/plasma.c +++ b/bitmap-plasma/app/src/main/cpp/plasma.cpp @@ -108,16 +108,10 @@ static __inline__ Fixed angle_sin(Angle a) { return angle_sin_tab[(uint32_t)a & (ANGLE_2PI - 1)]; } -static __inline__ Fixed angle_cos(Angle a) { return angle_sin(a + ANGLE_PI2); } - static __inline__ Fixed fixed_sin(Fixed f) { return angle_sin(ANGLE_FROM_FIXED(f)); } -static __inline__ Fixed fixed_cos(Fixed f) { - return angle_cos(ANGLE_FROM_FIXED(f)); -} - /* Color palette used for rendering the plasma */ #define PALETTE_BITS 8 #define PALETTE_SIZE (1 << PALETTE_BITS) @@ -180,8 +174,7 @@ static void fill_plasma(AndroidBitmapInfo* info, void* pixels, double t) { #define YT1_INCR FIXED_FROM_FLOAT(1 / 100.) #define YT2_INCR FIXED_FROM_FLOAT(1 / 163.) - int yy; - for (yy = 0; yy < info->height; yy++) { + for (uint32_t yy = 0; yy < info->height; yy++) { uint16_t* line = (uint16_t*)pixels; Fixed base = fixed_sin(yt1) + fixed_sin(yt2); Fixed xt1 = xt10; @@ -335,7 +328,7 @@ static void stats_endFrame(Stats* s) { } JNIEXPORT void JNICALL Java_com_example_plasma_PlasmaView_renderPlasma( - JNIEnv* env, jobject obj, jobject bitmap, jlong time_ms) { + JNIEnv* env, jclass, jobject bitmap, jlong time_ms) { AndroidBitmapInfo info; void* pixels; int ret; diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt index 6bd96f0c4..80085c899 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidApplicationConventionPlugin.kt @@ -30,6 +30,7 @@ class AndroidApplicationConventionPlugin : Plugin { externalNativeBuild { cmake { arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON") + arguments.add("-DCMAKE_MODULE_PATH=${rootDir.resolve("cmake")}") } } diff --git a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt index 1ac2746d4..c697c99e6 100644 --- a/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt +++ b/build-logic/src/main/java/com/android/ndk/samples/buildlogic/AndroidLibraryConventionPlugin.kt @@ -33,6 +33,7 @@ class AndroidLibraryConventionPlugin : Plugin { externalNativeBuild { cmake { arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON") + arguments.add("-DCMAKE_MODULE_PATH=${rootDir.resolve("cmake")}") } } ndk { diff --git a/cmake/AppLibrary.cmake b/cmake/AppLibrary.cmake new file mode 100644 index 000000000..e44102fe4 --- /dev/null +++ b/cmake/AppLibrary.cmake @@ -0,0 +1,15 @@ +include_guard() + +# Wrapper for add_library which enables common options we want for all +# libraries. +function(add_app_library name) + cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "") + add_library(${name} ${arg_UNPARSED_ARGUMENTS}) + + target_compile_options(${name} + PRIVATE + -Wall + -Wextra + -Werror + ) +endfunction() diff --git a/vectorization/src/main/cpp/CMakeLists.txt b/vectorization/src/main/cpp/CMakeLists.txt index a51799c64..a26b18370 100644 --- a/vectorization/src/main/cpp/CMakeLists.txt +++ b/vectorization/src/main/cpp/CMakeLists.txt @@ -1,11 +1,10 @@ cmake_minimum_required(VERSION 3.22.1) project(Vectorization LANGUAGES CXX) -add_compile_options(-Wall -Wextra -Werror) - +include(AppLibrary) find_package(base REQUIRED CONFIG) -add_library(app +add_app_library(app SHARED benchmark.cpp jni.cpp