首先。如果您正在編寫一個C程序,請將您的文件命名爲.c - 而不是.cpp,以確保CMake將它們標識爲C代碼。這就是您默認看到-std=c++11
的原因。
然後,您可以使用SET(CMAKE_C_FLAGS ...)添加編譯器標誌,即使這不是推薦的方法。你永遠不會認爲GCC會被調用。
正如@zaufi所說。您可以使用:
set_property(TARGET Thesis PROPERTY C_STANDARD 99)
https://cmake.org/cmake/help/v3.1/prop_tgt/C_STANDARD.html#prop_tgt:C_STANDARD
的-std標誌是確定哪些語言功能GCC應使GCC編譯器標誌。在這裏閱讀更多: http://linux.die.net/man/1/gcc
-std=
Determine the language standard.
This option is currently only supported when compiling C or C++ .
The compiler can accept several base standards, such as c89 or c++98,
and GNU dialects of those standards, such as gnu89 or gnu++98. By
specifying a base standard, the compiler will accept all programs
following that standard and those using GNU extensions that do not
contradict it. For example, -std=c89 turns off certain features of
GCC that are incompatible with ISO C90, such as the "asm" and
"typeof" keywords, but not other GNU extensions that do not have a
meaning in ISO C90, such as omitting the middle term of a "?:"
expression. On the other hand, by specifying a GNU dialect of a
standard, all features the compiler support are enabled, even when
those features change the meaning of the base standard and some
strict-conforming programs may be rejected.
'-std'是** **編譯標誌,而不是一個一個的CMake。 '-std = c99'表示要求編譯器使用[C99標準](https://en.wikipedia.org/wiki/C99)。 – Tsyvarev
,如果你打算要求CMake 3.3最小化,最好使用['CMAKE_C_STANDARD'](https://cmake.org/cmake/help/v3.3/variable/CMAKE_C_STANDARD.html),也許[ CMAKE_C_STANDARD_REQUIRED'](https://cmake.org/cmake/help/v3.3/variable/CMAKE_C_STANDARD_REQUIRED.html)...或設置相應的目標屬性。 – zaufi