Search code examples
c++makefilecmakeicc

Change compiler called in makefile


I have a make file that currently uses cmake to compile a collection of source files, but I would like to change it so it uses intel's c compiler. Can I just change all the cmake to icc or...how would this be done?

Below is the make file as-is, it's from a crypto-mining daemon for bytecoin.

all: all-release

cmake-debug:
    mkdir -p build/debug
    cd build/debug && cmake -D CMAKE_BUILD_TYPE=Debug ../..

build-debug: cmake-debug
    cd build/debug && $(MAKE)

test-debug: build-debug
    cd build/debug && $(MAKE) test

all-debug: build-debug

cmake-release:
    mkdir -p build/release
    cd build/release && cmake -D CMAKE_BUILD_TYPE=Release ../..

build-release: cmake-release
    cd build/release && $(MAKE)

test-release: build-release
    cd build/release && $(MAKE) test

all-release: build-release

clean:
    rm -rf build

tags:
    ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest

.PHONY: all cmake-debug build-debug test-debug all-debug cmake-release build-release test-release all-release clean tags

I can post the other files it creates in /build after a normal build, if that would help, but I imagine whatever process I have to do to change the compiler would be the same for each MAKE file.

Otherwise, the rest of the source files can be found here:

https://github.com/amjuarez/bytecoin

I am running Ubuntu 14.04.

Thanks in advance!


Solution

  • You specify your toolchain settings for CMake using a toolchain.txt file with the -DCMAKE_TOOLCHAIN_FILE=path/to/file on the first call of CMake, that generates the makefiles:

    cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=<path_to>/toolchain.txt
    

    There should be entries like

    set(CMAKE_C_COMPILER /<your-toolchain-path>/gcc)
    set(CMAKE_CXX_COMPILER /<your-toolchain-path>/g++)
    

    in toolchain.txt.