【问题标题】:Change compiler called in makefile更改 makefile 中调用的编译器
【发布时间】:2015-02-14 18:41:49
【问题描述】:

我有一个当前使用cmake 编译源文件集合的make 文件,但我想更改它以使其使用intel 的c 编译器。我可以将所有的cmake 更改为icc 或者......这将如何完成?

以下是原样的 make 文件,它来自字节币的加密挖掘守护进程。

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

如果有帮助的话,我可以在正常构建后发布它在 /build 中创建的其他文件,但我想我必须执行的任何更改编译器的过程对于每个 MAKE 文件都是相同的。

否则,可以在这里找到其余的源文件:

https://github.com/amjuarez/bytecoin

我正在运行 Ubuntu 14.04。

提前致谢!

【问题讨论】:

    标签: c++ makefile cmake icc


    【解决方案1】:

    您在第一次调用 CMake 时使用带有 -DCMAKE_TOOLCHAIN_FILE=path/to/file 的 toolchain.txt 文件指定 CMake 的工具链设置,从而生成 makefile:

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

    应该有像

    这样的条目
    set(CMAKE_C_COMPILER /<your-toolchain-path>/gcc)
    set(CMAKE_CXX_COMPILER /<your-toolchain-path>/g++)
    

    在toolchain.txt.

    【讨论】:

    • 如何在现有的 make 文件中指定这些设置?我想我会将 toolchain.txt 文件放在与 makefile 相同的目录中,但我如何告诉 makefile 读取它(或者它会自动发生)?
    • @Eric 您在文件中指定-DCMAKE_TOOLCHAIN_FILE=path/to/file 选项,我将更新我的答案以使其更清晰。
    【解决方案2】:

    通常CXX=&lt;mycompiler&gt; cmake 应该做你想做的事。或者您可以修改项目的工具链文件,假设您要永久进行更改。

    这是我运行 cmake 以使用 clang 和 clang++ 构建 llvm/clang 的脚本:

    CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Release\ 
    -DLLVM_ENABLE_ASSERTIONS=1  -DLLVM_TARGETS_TO_BUILD=X86 ../llvm
    

    【讨论】:

    • 我可以在现有 make 文件的开头添加它吗? CXX=icc cmake?
    • 在bash或类似的地方,如果你输入name=x,那么环境变量name就会被设置。由于 cmake 使用环境变量来确定要使用的编译器,因此它应该只选择新的编译器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多