mirror of
https://github.com/android/ndk-samples
synced 2025-11-05 23:20:53 +08:00
Factor out common library flags to a function.
I assume I'll want to make more "global" changes at some point, so rather than copying the same add_compile_options into every project, create add_app_library() as a wrapper around add_library() which handles the common stuff.
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(echo LANGUAGES C CXX)
|
project(echo LANGUAGES C CXX)
|
||||||
|
|
||||||
add_compile_options(-Wall -Wextra -Werror)
|
include(AppLibrary)
|
||||||
|
|
||||||
add_library(echo
|
add_app_library(echo
|
||||||
SHARED
|
SHARED
|
||||||
audio_main.cpp
|
audio_main.cpp
|
||||||
audio_player.cpp
|
audio_player.cpp
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(Base LANGUAGES CXX)
|
project(Base LANGUAGES CXX)
|
||||||
|
|
||||||
add_compile_options(-Wall -Werror -Wextra)
|
include(AppLibrary)
|
||||||
|
|
||||||
add_library(base
|
add_app_library(base
|
||||||
STATIC
|
STATIC
|
||||||
logging.cpp
|
logging.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(BitmapPlasma LANGUAGES CXX)
|
project(BitmapPlasma LANGUAGES CXX)
|
||||||
|
|
||||||
add_compile_options(-Wall -Wextra -Werror)
|
include(AppLibrary)
|
||||||
|
|
||||||
add_library(plasma SHARED plasma.cpp)
|
add_app_library(plasma SHARED plasma.cpp)
|
||||||
|
|
||||||
# Include libraries needed for plasma lib
|
# Include libraries needed for plasma lib
|
||||||
target_link_libraries(plasma
|
target_link_libraries(plasma
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
|
|||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
|
arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
|
||||||
|
arguments.add("-DCMAKE_MODULE_PATH=${rootDir.resolve("cmake")}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
|
|||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
|
arguments.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
|
||||||
|
arguments.add("-DCMAKE_MODULE_PATH=${rootDir.resolve("cmake")}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
15
cmake/AppLibrary.cmake
Normal file
15
cmake/AppLibrary.cmake
Normal file
@@ -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()
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.22.1)
|
cmake_minimum_required(VERSION 3.22.1)
|
||||||
project(Vectorization LANGUAGES CXX)
|
project(Vectorization LANGUAGES CXX)
|
||||||
|
|
||||||
add_compile_options(-Wall -Wextra -Werror)
|
include(AppLibrary)
|
||||||
|
|
||||||
find_package(base REQUIRED CONFIG)
|
find_package(base REQUIRED CONFIG)
|
||||||
|
|
||||||
add_library(app
|
add_app_library(app
|
||||||
SHARED
|
SHARED
|
||||||
benchmark.cpp
|
benchmark.cpp
|
||||||
jni.cpp
|
jni.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user