2
votes

Am using a Customized Android Compiler. That compiles cpp code and generates the .so file. From Command Prompt it is working fine but when I try to Build using Cmake then Cmake always picks wither Clang or GNU Compiler for Android compilation even after setting the compiler name in toolchain file.

My Analysis and Findings are as below.

I am working towards creating a toolchain file for an ANDROID compiler

I understand that the flow in CMAKE, when CMAKE_SYSTEM_NAME is specified in Android is different when compared to specifying CMAKE_SYSTEM_NAME as IOS or LINUX

Please validate my current understanding when a toolchain file or command-line option sets CMAKE_SYSTEM_NAME to "Android"

CMakeDetermineSystem.cmake loads this file: Android-Determine.cmake Next is the platform-specific initialization step: CMakeSystemSpecificInitialize.cmake which loads Android-Initialize.cmake to select the sysroot. A "determine" step also runs for each language when it is first enabled in a new build tree:

Android-Determine-C.cmake
Android-Determine-CXX.cmake

The language files go here:

Determine-Compiler.cmake
Determine-Compiler-NDK.cmake

The latter file is where we parse a bunch of information from the NDK. The results persist in CMakeFiles/$v/CMake${lang}Compiler.cmake for future runs.

Next is the language-specific initialization step. For Example – in case {lang} is C : CMakeCInformation.cmake

That loads one of these:

Android-GNU-C.cmake
Android-Clang-C.cmake

which loads one of these:

Android-GNU.cmake
Android-Clang.cmake

Determine-Compiler-NDK.cmake is where cmake looks for versions of clang or gcc or llvm toolchains and sets the appropriate compiler.

Our Requirement and Problem statement When I tried manually setting a c and cxx compiler from a toolchain file, cmake would not allow me to point to my custom compilers. Ideally, I would want my toolchain file to tell cmake the libraries to include/link and the compilers to use. But once System has been determined as android, cmake goes through the above sequence of events and expects toolchains to be specified for either clang, gcc or llvm compilers.

I believe I would probably need to make changes in the following files to accommodate cmake to use custom compilers. Determine-Compiler-NDK.cmake - We would need to add support for an "NewCompiler Toolchain" which would contain android libraries and compilers.

New Android-{NewCompiler}-C.cmake, Android-{ NewCompiler }-CXX.cmake, Android-{ NewCompiler }.cmake and another appropriate toolchain file to set target architecture and compiler flags.

Any comments on the process or how to go about this would be appreciated.

1

1 Answers

1
votes

Toolchain files can set the path to compilers on the host, but target-platform-wide information like the set of libraries and include directories to use typically belongs in platform information modules (e.g. Platform/Android-... and the like).

Since your compiler doesn't come with the NDK, perhaps you could look at using the standalone toolchain mode.