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'm learning C11 and I'm using CLion IDE. In this IDE only possible option is use of CMake for projects, and I read a few manuals of CMake (in stack overflow, too), and I don't find ready solution to write correct CMakeLists for C11 projects.
set(CMAKE_C_STANDARD 11) This line set C11 standard.
set(CMAKE_COMPILER_IS_GNUCC TRUE) This line set gcc as compiler.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") This line set compilation flags to default of IDE.
Is my CMakeLists.txt correct?
1 Answer
set(CMAKE_COMPILER_IS_GNUCC TRUE) CMAKE_COMPILER_IS_GNUCC should only be read to test what compiler correspond to your current generator, something like:
if(CMAKE_COMPILER_IS_GNUCC) # do something special for GNU C compiler endif() Just remove it. You may want to read this, if you need to specify your compiler (but you should not need to).
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") This line does absolutely nothing: you set CMAKE_C_FLAGS with its own content. Just remove it.
Is my CMakeLists.txt correct?
When building, does CLion tell you it isn't?
1