首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从CMake中删除所有默认编译器选项

如何从CMake中删除所有默认编译器选项
EN

Stack Overflow用户
提问于 2022-10-17 13:44:00
回答 1查看 57关注 0票数 0

我正在尝试使用一个非常不寻常的编译器(CC65)来使用CMake,以便在我的项目中使用CLion。

我已经让CMake调用了正确的编译器,但是CMake仍然添加了我不需要的各种GNU编译器选项:

代码语言:javascript
复制
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END

如何摆脱所有的默认选项,以便我可以从头开始,逐步建立正确的选项?

更新1:

使用的工具链文件不是由我开发的,而是简单的:

cmake/blob/master/toolchain/cc65-toolchain.cmake

更新2:

我不会亲自打电话给CMake文件。我只努力使用JetBrains CLion。如果不是CLion的话,我只会使用GNU。

因为我自己不把CMake称为命令行选项,所以我使用set()函数。

代码语言:javascript
复制
set (CMAKE_TOOLCHAIN_FILE "${PROJECT_SOURCE_DIR}/Library/CMake/Atari/cc65-toolchain.cmake")

全部产出如下:

代码语言:javascript
复制
/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-debug-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -g -D DEBUG --asm-define DEBUG -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END
    
    

[Previous CMake output restored: 17.10.22, 17:40]

完整的CMakeLists.txt在这里:

https://sourceforge.net/p/tutorial-6502/code/ci/feature/compiler/~/tree/CMakeLists.txt

更新3:

为了确保我检查了是否可以调整CLion生成的命令。我是成功的,输出略有不同,但净结果保持不变:

代码语言:javascript
复制
/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/opt/local/bin/gmake -DCMAKE_C_COMPILER=/opt/local/bin/cc65 --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G "CodeBlocks - Unix Makefiles" -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - failed
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cc65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release-c65

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cc65 -xc -t atari -fpch-preprocess -v -dD -E
    cc65: Unknown option: -xc -t atari -fpch-preprocess -v -dD -E -D___CIDR_DEFINITIONS_END

更新4:

切换到CLion的默认工具链配置,以查看这两个工具链之间是否存在冲突。但这会导致所有选项都被传递为“DOS样式”,而不是“/”,而不是“-”。

代码语言:javascript
复制
/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/Applications/Developer/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/ninja/mac/ninja --toolchain Library/CMake/Atari/cc65-toolchain.cmake -G Ninja -S /Users/Shared/Work/Projects/6502Tutorial -B /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release
>>cc65-toolchain.cmake
>>cc65-toolchain.cmake
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/ca65
-- Detecting C compiler ABI info
>>cc65-toolchain.cmake
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/local/bin/cl65 - skipped
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/ca65
> CMAKE_C_COMPILER:    /opt/local/bin/cl65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/cmake-build-release

Cannot get compiler information:
    Compiler exited with error code 1: /opt/local/bin/cl65 @/private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/response-file5391882336445539336 /private/var/folders/yv/kps0l5k55db3bmvbp4mbcdpw0000gn/T/compiler-file6838441381382142237 | @response-file5391882336445539336=/TC -t atari /Be /Bd /EP
    cl65: Don't know what to do with '/TC -t atari /Be /Bd /EP'
EN

回答 1

Stack Overflow用户

发布于 2022-10-19 06:14:49

CMake论坛的一些帮助下,(剩下的)问题已经被定位为(很可能)在CLion中。现在在使用终端时创建生成文件:

代码语言:javascript
复制
>cmake --toolchain Library/cc65-toolchain.cmake -S . -B cmake-build-release 
-- The ASM compiler identification is cc65
-- Found assembler: /opt/local/bin/cl65
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /opt/local/bin/cl65
-- Check for working C compiler: /opt/local/bin/cl65 - works
-- Warning: Did not find file Compiler/cc65-ASM
> CMAKE_ASM_COMPILER:  /opt/local/bin/cl65
> CMAKE_C_COMPILER:    /opt/local/bin/cl65
> CMAKE_AR:            /opt/local/bin/ar65
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Shared/Work/Projects/6502Tutorial/Atari/cmake-build-release

当然,我曾经尝试从终端上打电话给CMake,在它没有工作的时候也是如此。

我的猜测是,有多个问题,其中一些是我修复的,现在剩下的所有问题都是关于CLion的。因此,原来的问题已得到答复:

CMake默认选项可以通过使用适当的工具链文件.删除。

感谢所有帮助解决这个棘手问题的人。我会打开一个在JetBrains论坛上的后续文章

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74098302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档