CMake: CMakeLists for C11

cmake_minimum_required(VERSION 3.6)
project(Example)

set(CMAKE_C_STANDARD 11)
set(CMAKE_COMPILER_IS_GNUCC TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

set(SOURCE_FILES main.c)
add_executable(Example ${SOURCE_FILES})

I am learning C11 and I am using the CLion IDE. In this IDE, the only possible option is to use CMake for projects, and I read several CMake manuals (in stack overflows too), and I did not find a ready-made solution for writing the correct CMakeLists for C11 projects.

set(CMAKE_C_STANDARD 11)

This line sets the standard to C11.

set(CMAKE_COMPILER_IS_GNUCC TRUE)

This line sets gcc as a compiler.

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

This line sets the default compilation flags for the IDE.

Is my CMakeLists.txt correct?

+4
source share
1 answer
set(CMAKE_COMPILER_IS_GNUCC TRUE)

CMAKE_COMPILER_IS_GNUCC should only be read to see which compiler matches your current generator, for example:

if(CMAKE_COMPILER_IS_GNUCC)
    # do something special for GNU C compiler
endif()

. this, ( ).

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")

: CMAKE_C_FLAGS . .

CMakeLists.txt?

, CLion, ?

+3

Source: https://habr.com/ru/post/1657281/


All Articles