본문 바로가기
리눅스

cmake 기본 활용

by slowcloud_ 2026. 3. 6.

https://cmake.org/cmake/help/latest/guide/tutorial/index.html

 

CMake Tutorial — CMake 4.3.0-rc2 Documentation

Introduction The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address. Seeing how various topics all work together in an example project can be very helpful.

cmake.org

 

cmake는 메타 빌드 작성 도구이다. cmake를 통해 빌드시스템을 구성할 수 있다. 일반적으로는 make를 사용할 수 있는 Makefile을 생성하나, ninja, visual studio, 서브라임텍스트 등 타 도구의 빌드시스템도 구성할 수 있다.

 

본 문서에는 cmake를 사용하기 위한 최소 요구사항을 작성한다.

 

CMakeLists.txt 파일이 존재해야 하며, 다음 내용이 필요하다:

cmake_minimum_required(VERSION 3.23) # 가능한 cmake 최소 요구 버전
project(playground) # 프로젝트 이름. playground를 빼고 원하는대로 적으면 된다

 

이후 빌드할 타겟을 작성한다.

add_executable(target) # 컴파일 결과.
target_sources(target PRIVATE target.c) # 컴파일 결과를 만들기 위해 필요한 의존 소스코드 정보

# add_executable(target target.c) # 또는 이렇게 하나로 작성해도 된다.

 

add_executable, target_sources에 대한 더 자세한 정보는 아래에서 확인할 수 있다.

https://cmake.org/cmake/help/latest/command/add_executable.html#command:add_executable

 

add_executable — CMake 4.3.0-rc2 Documentation

Contents Add an executable to the project using the specified source files. add_executable( ... ...) Add an executable target called to be built from the source files listed in the command invocation. The options are: WIN32Set the WIN32_EXECUTABLE target p

cmake.org

https://cmake.org/cmake/help/latest/command/target_sources.html#command:target_sources

 

target_sources — CMake 4.3.0-rc2 Documentation

target_sources Add sources to a target. target_sources( {INTERFACE|PUBLIC|PRIVATE} ... [{INTERFACE|PUBLIC|PRIVATE} ...]...) Specifies sources to use when building a target and/or its dependents. The named must have been created by a command such as add_exe

cmake.org

 

cmake로 Makefile 생성
생성된 Makefile로 target.c를 빌드하고 실행한 모습

 

'리눅스' 카테고리의 다른 글

커널스페이스와 유저스페이스  (0) 2026.03.26
grep  (0) 2025.08.24
fzf 소개 및 간략한 사용법  (1) 2025.07.17