Hi,
I intend to use gcc-cross-compiler for my OS, but I don't know how to change default compiler (gcc) to i686-elf-gcc and default assembler to i686-elf-as in CMake (CMakeLists.txt)
How can I change default assembler and compiler in CMake?
Changing compiler and assembler in CMake
Re: Changing compiler and assembler in CMake
In general the proper way to do it is a toolchain file which sets the proper variables. additionally you COULD set the compiler and stuff via commandline, but this will likely fail as the crosscompiler is likely not able to compile cmake's test programs.
Re: Changing compiler and assembler in CMake
Writing make files is quite challenging, however working with CMake for OS development seems to be more tricky, isn't it? shall I use pure Make instead of CMake for developing my OS?
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Changing compiler and assembler in CMake
Personally I just use a standard makefile. No automake, no cmake. I've got a few scripts though to help me compile binaries using the correct compiler configuration and linkscripts - that way, I don't have to repeat a whole series of commands in each make target; I can just say "./scripts/compile.sh ..." and "./scripts/link.sh ..." wherever I need to compile or link something.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Changing compiler and assembler in CMake
I got CMake to cross compile my kernel, but it wasn't a pleasant experience and I would recommend staying away from CMake. In any case, here are the toolchain files I came up with:
i686-elf-gcc toolchain (toolchain-i686.cmake):
x86_64-elf-gcc toolchain (toolchain-x86_64.cmake):
You can then invoke cmake with something like this:
i686-elf-gcc toolchain (toolchain-i686.cmake):
Code: Select all
SET(CMAKE_SYSTEM_NAME Kiznix)
SET(CMAKE_SYSTEM_PROCESSOR x86)
SET(CMAKE_SYSTEM_VERSION 1)
INCLUDE(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(i686-elf-gcc GNU)
SET(CMAKE_C_SIZEOF_DATA_PTR 4)
SET(CMAKE_C_FLAGS "-O2 -g -ffreestanding -fbuiltin -Wall -Wextra -std=gnu99 -msse" CACHE STRING "" FORCE)
x86_64-elf-gcc toolchain (toolchain-x86_64.cmake):
Code: Select all
SET(CMAKE_SYSTEM_NAME Kiznix)
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
SET(CMAKE_SYSTEM_VERSION 1)
INCLUDE(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(x86_64-elf-gcc GNU)
SET(CMAKE_C_SIZEOF_DATA_PTR 8)
SET(CMAKE_C_FLAGS "-O2 -g -ffreestanding -fbuiltin -Wall -Wextra -std=gnu99 -mcmodel=kernel -mno-red-zone" CACHE STRING "" FORCE)
Code: Select all
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/toolchain-x86_64.cmake $(PROJECT_DIR)