How Do You Get The Full Set Of Compiler And Linker Flags Used By Ndk-build?
Solution 1:
Try examine
{SDK_PATH}/ndk-bundle/build/core/toolchains/arm-linux-androideabi-4.9/setup.mk
or different toolchain (that depends on what you'are building). There are flags needed for cross-compilation defined.
EDIT
I've done some digging.
If you edit a file:
{SDK_PATH}/ndk-bundle/build/core/definitions.mk
and find a line define ev-compile-cpp-source
. Or maybe better define ev-build-file
.
You can add there
$(info $_FLAGS is [${_FLAGS}])
before $$eval
.
Now if you build something, you'll see flags.
Solution 2:
For custom build systems you should use a standalone toolchain. That'll handle getting all the basic flags right for targeting Android. It won't handle any of the decisions best left to the build system though such as optimization level, debug flags, etc.
EDIT:
Unfortunately your current solution is as good as it can get for the time being. Eventually the toolchain configuration will be moved into JSON files in $NDK/meta
like a few (trivial) things already have so we can share that info between ndk-build and CMake, but that's not happening any time soon.
Solution 3:
Use cmake to drive configure, or to write out the values in whatever format you need.
For example, here's a CMakeLists.txt file that configures and compiles the expat project. It expects the source for expat to be on the system already. Probably most of what you want is in the standard_configure_env macro; it's the modified CFLAGS etc that you'll want.
cmake_minimum_required(VERSION 3.6)
project (expat)
macro(standard_configure_env output)
set(${output}
CC=${ANDROID_C_COMPILER}
CXX=${ANDROID_CXX_COMPILER}
CFLAGS=--target=${CMAKE_C_COMPILER_TARGET}\ --sysroot=${ANDROID_SYSROOT}\ \ --gcc-toolchain=${ANDROID_TOOLCHAIN_ROOT}\ ${ANDROID_COMPILER_FLAGS}
CXXFLAGS=${ANDROID_COMPILER_FLAGS_CXX}
AR=${ANDROID_AR}
RANLIB=${ANDROID_RANLIB}
LD=${CMAKE_LINKER}
LDFLAGS=${ANDROID_LINKER_FLAGS}
)
endmacro()
include(ProcessorCount)
ProcessorCount(nCpus)
set(expat_output_dir ${CMAKE_CURRENT_BINARY_DIR}/expat)
set(expat_build_dir ${expat_output_dir}/expat_bin)
set(expat_install_dir ${expat_output_dir}/install)
set(expat_src_dir /Users/james/yourpathgoeshere/cmake/expat/src/expat-2.1.0)
set(markers_dir ${expat_output_dir}/markers)
file(MAKE_DIRECTORY ${markers_dir})
set(expat_copied ${markers_dir}/copied)
set(expat_configured ${markers_dir}/configured)
set(expat_final_lib ${expat_install_dir}/lib/libexpat.a)
file(MAKE_DIRECTORY ${expat_install_dir}/include)
standard_configure_env(configure_env)
set(configure_host ${ANDROID_HEADER_TRIPLE})
# expat doesn't understand these Android architectures, so set them by hand to what expat can# useif(${configure_host} STREQUAL aarch64-linux-android)
set(configure_host arm-linux-android64v8a)
elseif(${configure_host} STREQUAL armv7-linux-androideabi)
set(configure_host arm-linux-androideabiv7a)
endif()
set(configure_args
--host=${configure_host}
--disable-shared
--prefix=${expat_output_dir}/install
--exec-prefix=${expat_output_dir}/install
)
add_custom_command(
OUTPUT ${expat_configured}
COMMAND ${configure_env} ./configure ${configure_args} && touch${expat_configured}
DEPENDS ${expat_copied}
WORKING_DIRECTORY ${expat_build_dir}
)
add_custom_command(
OUTPUT ${expat_copied}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${expat_src_dir}${expat_build_dir}
COMMAND touch${expat_copied}
)
add_custom_command(
OUTPUT ${expat_final_lib}
COMMAND make -j${nCpus} installlib && touch${expat_final_lib}
WORKING_DIRECTORY ${expat_build_dir}
DEPENDS ${expat_configured}
)
add_custom_target(expat_build DEPENDS ${expat_final_lib})
add_library(expat STATIC IMPORTED GLOBAL)
add_dependencies(expat expat_build)
set_target_properties(expat
PROPERTIES
LINKER_LANGUAGE CXX
IMPORTED_LOCATION ${expat_install_dir}/lib/libexpat.a
INTERFACE_INCLUDE_DIRECTORIES ${expat_install_dir}/include)
Thanks to @DanAlbert and @JakubPiskorz for pointing out that I really do want to get this from cmake.
Post a Comment for "How Do You Get The Full Set Of Compiler And Linker Flags Used By Ndk-build?"