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

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

问题描述

我使用的CMake进行交叉编译。在我的工具链文件中有一条线

  SET(CMAKE_C_FLAGS-std = gnu99)

此变量没有设置的CMakeLists.txt一次。

当我运行 cmake的-DCMAKE_TOOLCHAIN​​_FILE = toolchain.cmake .. 此标志将被忽略。

要更加细化: flags.cmake 的行显示一个空的 C_FLAGS = 行。
但在 CMakeOutput.log 我能找到一个行构建标志:-std = gnu99

我发现 cmake的.. 的第二次运行(与相同或不指定工具链文件)修复了这个问题。

但它为什么不设置我第一次运行cmake ??

编辑:添加MNWE

的CMakeLists.txt:

  cmake_minimum_required(版本2.6)
项目(MyProject的)SET(文件的src / main.c中)add_executable(myexec $ {}文件)

avr.cmake:

  SET(CMAKE_SYSTEM_NAME通用)SET(CMAKE_C_COMPILER AVR-GCC)SET(CMAKE_C_FLAGS-std = gnu99)


解决方案

我发现通过更换就行了临时的解决方案

  SET(CMAKE_C_FLAGS-std = gnu99)

  SET(CMAKE_C_FLAGS-std = gnu99CACHE字符串FORCE)

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

SET(CMAKE_C_FLAGS "-std=gnu99")

This variable is not set in CMakeLists.txt again.

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

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.

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

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

EDIT: Added 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")

by

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

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

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