CMake - 기초

markyang92·2024년 9월 3일
0

cmake

목록 보기
1/2
post-thumbnail

hello world

CMakeLists.txt main.cc

CMakeLists.txt

cmake_minimum_required(VERSION 3.22)

project(
	CppProject
    VERSION 1.0.0
    LANGUAGES C CXX
)

add_executable(Executable main.cc)

빌드 수행

  • build 디렉토리 생성 후
$ cd build
$ cmake ..
# 상위 디렉토리에 있는 CMakeLists.txt 수행

  • 정확하게는 아래 처럼 할 수 있음
$ cmake -S <path-to-source> -B <path-to-build>
$ cmake -S .. -B . # option 1
$ cmake .. # option 2

  • Makefile 생성 확인

--build <위치>: <위치>에 대해 빌드 수행

  • make 명령 쓰거나, $ cmake --build . 로 빌드 수행
$ cmake --build .

$ cmake . : update

  • CMake project를 파싱한적 있다면, 아래의 명령으로 업데이트 가능하다.
build $ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dhyang/cpp/build

-G: Generator 설정

* Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Ninja Multi-Config           = Generates build-<Config>.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.
  • Unix Makefiles
cd build
cmake -S .. -B . -G "Unix Makefiles" # option 1
cmake .. -G "Unix Makefiles" # option 2

  • MSVC
cd build
cmake -S .. -B . -G "Visual Studio 16 2019" # option 1
cmake .. -G "Visual Studio 16 2019" # option 2

  • Ninja
cd build
cmake -S .. -B . -G "Ninja" # option 1
cmake .. -G "Ninja" # option 2

profile
pllpokko@alumni.kaist.ac.kr

0개의 댓글