Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

CMake cross-compiling: C flags from toolchain file ignored

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")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...