Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Android Targets #1410

Closed
leleliu008 opened this issue Jan 29, 2022 · 12 comments
Closed

Support Android Targets #1410

leleliu008 opened this issue Jan 29, 2022 · 12 comments
Assignees
Labels
Component - Build CMake, Autotools Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Type - Improvement Improvements that don't add a new feature or functionality

Comments

@leleliu008
Copy link

https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.13/hdf5-1.13.0/src/hdf5-1.13.0.tar.bz2

cmake \
        -DHDF5_BUILD_DOC=OFF \
        -DBUILD_SHARED_LIBS=ON \
        -DBUILD_STATIC_LIBS=ON \
        -DBUILD_STATIC_EXECS=ON \
        -DTEST_LFS_WORKS_RUN=ON
        -S . \
        -B build.d

27

It seems that this project do not support cross-compiling. how can I skip these build time checks? Thanks.

@byrnHDF
Copy link
Contributor

byrnHDF commented Jan 31, 2022

You can pre-populate the file needed - you need to do a search. However we do have CMake support in the src/CMakeLists.txt file for using the file. About line 1028 HDF5_USE_PREGEN variable.

@byrnHDF byrnHDF self-assigned this Feb 4, 2022
@jebos
Copy link

jebos commented Sep 28, 2022

@byrnHDF can you point to a documentation on how to
I'm trying to just compile the current develop branch of hdf5 for a current android on windows using the latest NDK ect.

I'm a bit lost in regards of
a) where to get the values for this file (how to generate)
and
b) how the file needs to look like (are there examples?)

Can you give me a hint into the correct direction. Thanks.

@byrnHDF
Copy link
Contributor

byrnHDF commented Sep 28, 2022

Some references first:
CMake toolchains: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
aarch64 on Ubuntu: https://discourse.cmake.org/t/cross-compile-for-aarch64-on-ubuntu/2161/10
Using clang(includes an addendum for gcc) on windows to arm: https://stackoverflow.com/questions/54539682/how-to-set-up-cmake-to-cross-compile-with-clang-for-arm-embedded-on-windows?rq=1
CMake NDK: https://developer.android.com/ndk/guides/cmake

A note found during search: make sure you set the CMAKE_FIND_ROOT_PATH variable to a path where you have an exact copy of the root filesystem you have on your target device (with libraries and binaries pre-compiled for the target processor).

@byrnHDF
Copy link
Contributor

byrnHDF commented Sep 28, 2022

Initial release_docs file: INSTALL_cross_compile.txt
`
// HDF5 Build and Install Instructions for Cross Compiling

Cross-compiling has several consequences for CMake:
CMake cannot automatically detect the target platform.
CMake cannot find libraries and headers in the default system directories.
Executables built during cross compiling cannot be executed.

Cross-compiling support means that CMake separates information about the
build platform and target platform and gives the user mechanisms to solve
cross-compiling issues without additional requirements such as running
virtual machines, etc.

CMake uses a toolchain of utilities to compile, link libraries and create
archives, and other tasks to drive the build. The toolchain utilities
available are determined by the languages enabled.

CMake stores info about the current toolchain in the following variables:
CMAKE_C_COMPILER,
CMAKE_CXX_COMPILER.
They contain paths to the C and C++ compilers respectively. This is usually
enough on desktop platforms. In the case of the embedded systems, also a
custom linker and assembler setting is needed. In more complex projects
you may need to additionally specify binaries to other parts of the toolchain
(size, ranlib, objcopy…). All these tools should be set in the corresponding
variables:
CMAKE_AR,
CMAKE_ASM_COMPILER,
CMAKE_LINKER,
CMAKE_OBJCOPY,
CMAKE_RANLIB

As for the host and target operating systems, CMake stores their names in the
following variables:
CMAKE_HOST_SYSTEM_NAME
– name of the platform, on which CMake is running (host platform).
On major operating systems this is set to the Linux, Windows or
Darwin (MacOS) value.
CMAKE_SYSTEM_NAME
– name of the platform, for which we are building (target platform).
By default, this value is the same as CMAKE_HOST_SYSTEM_NAME, which
means that we are building for the local platform (no cross-compilation).

Put the toolchain variables into a separate file (e.g. <toolchain_name>.cmake)
and set CMAKE_TOOLCHAIN_FILE variable to the path of that file.
If cmake is invoked with the command line parameter:
--toolchain path/to/file
or
-DCMAKE_TOOLCHAIN_FILE=path/to/file
the file will be loaded early to set values for the compilers. The
CMAKE_CROSSCOMPILING variable is set to true when CMake is cross-compiling.

Structure of the toolchain file

In fact, the toolchain file doesn’t have any structure. You can put anything you
want there. But the best practice is to define at least these settings:
path to the toolchain binaries (C compiler, C++ compiler, linker, etc.)
name of the target platform (and optionally target processor architecture)
required compilation and linking flags on that particular platform
toolchain sysroot settings

References:
https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html
https://gitlab.com/embeddedlinux/libs/platform
`

@byrnHDF
Copy link
Contributor

byrnHDF commented Sep 28, 2022

The one file that needs to be pre-generated is the H5Tinit.c file. The variables indicated in the error log (see above) are the variables that need to match the target system.

The HDF5 CMake variables;
HDF5_USE_PREGEN: set this to true
HDF5_USE_PREGEN_DIR: set this path to the preset H5Tinit.c file

@byrnHDF
Copy link
Contributor

byrnHDF commented Sep 28, 2022

There may be more HDF5 files that will need adjustments for different platforms, but H5Tinit.c is the key file. The next possible issue might be the H5pubconf.h file that is generated - if that happens we can adjust the PREGEN code blocks to account for it.

@cbldlpl
Copy link

cbldlpl commented Nov 17, 2022

The one file that needs to be pre-generated is the H5Tinit.c file. The variables indicated in the error log (see above) are the variables that need to match the target system.

The HDF5 CMake variables; HDF5_USE_PREGEN: set this to true HDF5_USE_PREGEN_DIR: set this path to the preset H5Tinit.c file

I also encountered this problem, how to get the value of the variable matching the target system?

@derobins derobins added Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Component - Build CMake, Autotools Type - Improvement Improvements that don't add a new feature or functionality labels May 4, 2023
@derobins
Copy link
Member

Can this issue be closed?

  • The long double checks are gone
  • AC_RUN_IFELSE in the Autotools has defaults for everything that is left (just szip encoding and checking pthread_attr_setscope)
  • H5detect is gone
  • H5make_libsettings is gone

Cross compiling should basically just work now

@leleliu008
Copy link
Author

@derobins Thanks for your effort. I tried the master branch HEAD and it was successfully built, so this can be closed now.

@byrnHDF byrnHDF closed this as completed Jun 13, 2023
@leleliu008
Copy link
Author

The cross compiling is broken again:

CMake Error: try_run() invoked in cross-compiling mode, please set the following cache variables appropriately:
   H5_LDOUBLE_TO_LONG_SPECIAL_RUN (advanced)
   H5_LDOUBLE_TO_LONG_SPECIAL_RUN__TRYRUN_OUTPUT (advanced)
For details see /github/home/.ndk-pkg/run/524/hdf5/src/_/TryRunResults.cmake
CMake Error: try_run() invoked in cross-compiling mode, please set the following cache variables appropriately:
   H5_LONG_TO_LDOUBLE_SPECIAL_RUN (advanced)
   H5_LONG_TO_LDOUBLE_SPECIAL_RUN__TRYRUN_OUTPUT (advanced)
For details see /github/home/.ndk-pkg/run/524/hdf5/src/_/TryRunResults.cmake
CMake Error: try_run() invoked in cross-compiling mode, please set the following cache variables appropriately:
   H5_LDOUBLE_TO_LLONG_ACCURATE_RUN (advanced)
   H5_LDOUBLE_TO_LLONG_ACCURATE_RUN__TRYRUN_OUTPUT (advanced)
For details see /github/home/.ndk-pkg/run/524/hdf5/src/_/TryRunResults.cmake
CMake Error: try_run() invoked in cross-compiling mode, please set the following cache variables appropriately:
   H5_LLONG_TO_LDOUBLE_CORRECT_RUN (advanced)
   H5_LLONG_TO_LDOUBLE_CORRECT_RUN__TRYRUN_OUTPUT (advanced)
For details see /github/home/.ndk-pkg/run/524/hdf5/src/_/TryRunResults.cmake
CMake Error: try_run() invoked in cross-compiling mode, please set the following cache variables appropriately:
   H5_DISABLE_SOME_LDOUBLE_CONV_RUN (advanced)
   H5_DISABLE_SOME_LDOUBLE_CONV_RUN__TRYRUN_OUTPUT (advanced)
For details see /github/home/.ndk-pkg/run/524/hdf5/src/_/TryRunResults.cmake

@byrnHDF
Copy link
Contributor

byrnHDF commented Jul 23, 2023

Was this the develop branch? Looks like the checks were reverted about 5 weeks ago.

@leleliu008
Copy link
Author

Yes, I use the default breach: develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Build CMake, Autotools Priority - 3. Low 🔽 Code cleanup, small feature change requests, etc. Type - Improvement Improvements that don't add a new feature or functionality
Projects
None yet
Development

No branches or pull requests

5 participants