CMake 交叉编译:忽略工具链文件中的 C 标志 [英] CMake cross-compiling: C flags from toolchain file ignored

查看:21
本文介绍了CMake 交叉编译:忽略工具链文件中的 C 标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 cmake 进行交叉编译.在我的工具链文件中有一行

I use cmake for cross compiling. In my toolchain file there is a line

SET(CMAKE_C_FLAGS "-std=gnu99")

CMakeLists.txt 中不再设置此变量.

This variable is not set in CMakeLists.txt again.

当我运行 cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake .. 这个标志被忽略.

When I run cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake .. this flag is ignored.

更详细:flags.cmake 行显示了一个空的 C_FLAGS = 行.但是在 CMakeOutput.log 中,我可以找到一行 Build flags: -std=gnu99.

To be more detailed: The line of flags.cmake shows an empty C_FLAGS = line. But in CMakeOutput.log I can find a line Build flags: -std=gnu99.

我发现第二次运行 cmake ..(无论是否指定工具链文件都一样)修复了这个问题.

I found out that a second run of cmake .. (same with or without toolchain file specified) fixes this problem.

但是为什么我第一次运行 cmake 时没有设置??

But why is it not set the first time i run cmake ??

添加了 MNWE

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(myproject)

SET(files src/main.c)

add_executable(myexec ${files})

avr.cmake:

SET(CMAKE_SYSTEM_NAME Generic)

SET(CMAKE_C_COMPILER avr-gcc)

SET(CMAKE_C_FLAGS "-std=gnu99")

推荐答案

我找到了一个临时解决方案,通过替换该行

I've found a temporary solution by replacing the line

SET(CMAKE_C_FLAGS "-std=gnu99")

SET(CMAKE_C_FLAGS "-std=gnu99" CACHE STRING "" FORCE)

这篇关于CMake 交叉编译:忽略工具链文件中的 C 标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆