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

Please dont hard code compiler paths #978

Closed
Rippanda12 opened this issue Jul 15, 2024 · 9 comments · Fixed by #981
Closed

Please dont hard code compiler paths #978

Rippanda12 opened this issue Jul 15, 2024 · 9 comments · Fixed by #981

Comments

@Rippanda12
Copy link
Contributor

Rippanda12 commented Jul 15, 2024

box86/CMakeLists.txt

Lines 87 to 89 in 21e9a43

set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
#set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as) #will use gcc in fact
set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf)

Please leave that unset so that it wont break if they are cross compiling/building :)
Currently you are breaking builds on systems that dont use the triple arm-linux-gnueabihf-gcc arch arm is one of them

@Rippanda12
Copy link
Contributor Author

cmake tells users how to set the compiler if it doesnt find it

CMake Error at CMakeLists.txt:92 (project):
  The CMAKE_C_COMPILER:

    arm-linux-gnueabihf-gcc

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:92 (project):
  No CMAKE_ASM_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

THis bit is crucial for arm64 build, for it to be plug'n play.

@Rippanda12
Copy link
Contributor Author

Same here but I can't compile without patching your thing

@Rippanda12
Copy link
Contributor Author

Rippanda12 commented Jul 16, 2024

Not every GCC compiler has the same triple name.
The one I'm compiling uses armv7h-linux-gnueabihf, now I have to patch so that I can build.
Is it too much to ask from people to adhere to standards instead of hardcoding stuff in?
This is the same with what I experienced with X11 libs, most of them have hard coded paths (look here https://github.com/BredOS/multilib-pkgbuilds, under patches/).

This is how cross compilation should be done
https://github.com/BredOS/multilib-pkgbuilds/blob/main/patches%2Flib32-llvm.patch#L32

Atleast do checks first. Cmake supports those.
User defined Cc CXX should be respected at all costs.

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

but those patch are Arch OS specific. The point is to have box86 buildable everywhere. Currently, most machine still use debian based OS (Debian, Ubuntu, Armbian), and this works perfectly, without the need to use a shell script. Note that this is not really cross-compiling, it' build on the devices directly.

If you find a solution to make this parametrable without breaking debian compatibility, I'm all hears.

Last time I tried, cmake was not not happy and needed the settings of the C compiler very early in the CMake Script, but maybe there is a simpler way?

@Rippanda12
Copy link
Contributor Author

Rippanda12 commented Jul 16, 2024

set(COMPILER_TRIPLE arm-linux-gnueabihf-gcc)
find_program(COMPILER_FOUND ${COMPILER_TRIPLE})

if(COMPILER_FOUND)
    set(CMAKE_C_COMPILER ${COMPILER_FOUND})
else()
    message(STATUS "Cross compiler ${COMPILER_TRIPLE} not found, using CC or -DCMAKE_C_COMPILER")
endif()

Edit: this is the actual fix

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

Ok, looks good to me.

Out of curiosity, is set(COMPILER_TRIPLE arm-linux-gnueabihf-gcc) overloadable? Or does cmake has some specific test that allows it to goes from "arm-linux-gnueabihf-gcc" the actual armhf triplet actually setup in the system?

@Rippanda12
Copy link
Contributor Author

its still hard coded in a way, checks for that toolchain, if it exists sets it and uses it else uses either /usr/bin/gcc OR in the case of most crosscompilations, CC var or if user specified -DCMAKE_C_COMPILER

@ptitSeb
Copy link
Owner

ptitSeb commented Jul 16, 2024

Ah ok, this allows to use fallback instead of just failing. Nice.

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 a pull request may close this issue.

2 participants