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

feat: make enable_cross_compiler more open-closed #196

Merged

Conversation

abeimler
Copy link
Contributor

Another remaining issue for Cross-compiling is that its options are using global CMake options instead of the function arguments. We should be using function arguments

#180 (comment)

# my custom arm settings
  enable_cross_compiler(
    CC "arm-none-eabi-gcc"
    CXX "arm-none-eabi-g++"
    TARGET_ARCHITECTURE "arm"
    CROSS_ROOT "/usr/arm-none-eabi-gcc"
    CROSS_TRIPLET "arm-none-eabi-gcc"
  )  
# opt-in cross-compiling
if(ENABLE_AARCH64_CROSS_COMPILING)
  # my custom aarch64 settings
  enable_cross_compiler(
    DEFAULT_TRIPLET "arm64-linux"
    CC "aarch64-linux-gnu-gcc"
    CXX "aarch64-linux-gnu-g++"
    TARGET_ARCHITECTURE "arm64-linux"
    CROSS_ROOT "/usr/gcc-aarch64-linux-gnu"
    CROSS_TRIPLET "aarch64-linux-gnu"
    #TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/my-toolchain.cmake"
  )
else()
  option(ENABLE_CROSS_COMPILING "Detect cross compiler and setup toolchain" OFF)
  if(ENABLE_CROSS_COMPILING)
    enable_cross_compiler()
  endif()
endif()

@abeimler
Copy link
Contributor Author

abeimler commented Jan 25, 2023

fatal error: stdio.h: No such file or directory

idk why the CI failed last time Q-Q ... it worked in docker and in the last CI-PR-Check (maybe some caching problem...)

Anyway, I rewrite the example(s) and make it more "bare metal".

@abeimler
Copy link
Contributor Author

abeimler commented Jan 25, 2023

#180 (comment)

I try to auto-detect the following cross-compilers, when setting DEFAULT_TRIPLET:

Example:

  • -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic
  • -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=wasm32-emscripten

For arm-linux or arm64-linux, you must set the compiler:

Example:

  • -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER=gcc-aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=gcc-aarch64-linux-gnu-g++ -DDEFAULT_TRIPLET=arm64-linux
  • -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DDEFAULT_TRIPLET=arm-linux -DCROSS_ROOT=/usr/gcc-arm-linux-gnueabihf

For (bare-metal) you don't need/can't(?) set arm-linux/arm64-linux (for vcpkg):

Example:

  • -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=arm-none-eabi-g++
  • -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER=arm-none-eabi-gcc -DCMAKE_CXX_COMPILER=arm-none-eabi-g++ -DTARGET_ARCHITECTURE:STRING=arm -DCROSS_ROOT:STRING="/usr/arm-none-eabi-gcc" -DCROSS_TRIPLET:STRING=arm-none-eabi-gcc

The option for DEFAULT_TRIPLET are the simlary to vcpkg triplets

  • x64-mingw-dynamic
  • x64-mingw-static
  • x86-mingw-dynamic
  • x86-mingw-static
  • wasm32-emscripten
  • arm-linux
  • arm64-linux

@abeimler abeimler marked this pull request as draft January 25, 2023 12:36
@abeimler abeimler force-pushed the feature/open-closed-enable-cross-compiler branch from 3b55faa to 9ea1237 Compare January 26, 2023 13:06
@abeimler abeimler force-pushed the feature/open-closed-enable-cross-compiler branch from 9ea1237 to 1c5d9a5 Compare January 26, 2023 13:21
@abeimler abeimler marked this pull request as ready for review January 26, 2023 13:38
Copy link
Owner

@aminya aminya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

@aminya aminya merged commit 6846f39 into aminya:main Jan 29, 2023
@aminya aminya linked an issue Aug 22, 2023 that may be closed by this pull request
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-compiling
2 participants