[CMake] find_file - strange behavior when using Android toolchain

Stephan Menzel stephan.menzel at gmail.com
Wed Jul 31 02:20:51 EDT 2019


Hello all,

I'm trying to adapt my CMake based toolchain to Android and I'm noticing
very strange behavior that I'd like to ask about.
My toolchain is C++ based with some dependencies such as Boost, OpenSSL or
protobuf. So far it works on a variety of platforms such as Windows (MSVC),
several Linuxes, including Raspbian on ARM. So I considered myself well
prepared for Android, thinking it can't be that different. How wrong I
was... I'm cross compiling from a Linux system, which is able to build the
source in question just fine with clang and gcc. Most recent Android SDK
and bundled NDK.

As soon as I started building and finding my 3rd party dependencies I
noticed that many commands in my own scripts or others that try to find a
file (like a header) or a lib fail despite the file being there.
Like here in this case for example (randomly taken from the AWS SDK
installed CMake finders):

find_file(AWSSDK_CORE_HEADER_FILE Aws.h
            "${AWSSDK_ROOT_DIR}/${AWSSDK_INSTALL_INCLUDEDIR}/aws/core"

"${AWSSDK_DEFAULT_ROOT_DIR}/${AWSSDK_INSTALL_INCLUDEDIR}/aws/core"
            )

I have double checked many times that the file clearly is there in that
exact position correct casing and the process has full read permissions. I
can open it for reading and I can't see anything strange about it. Just
some header.  But AWSSDK_CORE_HEADER_FILE is NOTFOUND. The finders for
Boost and OpenSSL have the same problem whenever they use find_file or
similar and so have my own.

So far I have worked around the issue by hard setting the variables in
question before the script runs. In this case I would look at my
directories, set AWSSDK_CORE_HEADER_FILE to the file path and run it again.
Then the test will pass but that can't be it. Also, a huge library like the
AWS SDK has so many such commands and variables that I cannot possibly
override all of them.

Why does that command fail at all? I looked at the docs for find_file but I
cannot see any mention of cases where the file is not found because of some
toolchain or cross compile settings

I have tried with the CMake that comes bundled in the NDK as well, same
results. And again, it works fine on ARM in general when the ndk toolchain
is not involved. I can only assume something in
"ndk-bundle/build/cmake/android.toolchain.cmake" sets some global CMake
setting that disables find_file. But why would they do this? And why would
such a breaking setting even exist? None of that makes sense to me.

Anybody have some input please?

Cheers,
Stephan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190731/accf1309/attachment.html>


More information about the CMake mailing list