
main.c#include <stdio.h>
int main(void)
{
printf("Hello, World!\n");
return 0;
}
CMakeLists.txt에 기술한다.
cmake_minimum_requiredcmake_minimum_required(VERSION 3.22)
cmake_minimum_required()$ cmake --version
cmake version 3.22.1
project()프로젝트의 이름을 설정합니다.
project(<PROJECT-NAME> [<language-name>...])
project(<PROJECT-NAME> [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]] [DESCRIPTION <project-description-string>] [HOMEPAGE_URL <url-string>] [LANGUAGES <language-name>...])
project(CProject VERSION 1.0.0)
proejct(CProject VERSION 1.0.0 LANGUAGES C CXX)
C++은 CXX로 해야함C++로 하면 CXX_COMPILER가 아닌 C++_COMPILER라고 없는 것 찾음
지정된 소스 파일을 사용하여 프로젝트에 실행 파일을 추가합니다.
add_executable(<name> <options>... <sources>...) :target: normal Add an executable target called ``<name>`` to be built from the source files listed in the command invocation. The options are: ``WIN32`` Set the :prop_tgt:`WIN32_EXECUTABLE` target property automatically. See documentation of that target property for details. ``MACOSX_BUNDLE`` Set the :prop_tgt:`MACOSX_BUNDLE` target property automatically. See documentation of that target property for details. ``EXCLUDE_FROM_ALL`` Set the :prop_tgt:`EXCLUDE_FROM_ALL` target property automatically. See documentation of that target property for details.
add_executable(<name> IMPORTED [GLOBAL]) :target: IMPORTED Add an :ref:`IMPORTED executable target <Imported Targets>` to reference an executable file located outside the project. The target name may be referenced like any target built within the project, except that by default it is visible only in the directory in which it is created, and below. The options are: ``GLOBAL`` Make the target name globally visible.
add_executable(<name> ALIAS <target>) :target: ALIAS Creates an :ref:`Alias Target <Alias Targets>`, such that ``<name>`` can be used to refer to ``<target>`` in subsequent commands. The ``<name>`` does not appear in the generated buildsystem as a make target. The ``<target>`` may not be an ``ALIAS``.
add_executable(main main.cc)
cmake_minimum_required(VERSION 3.22)
project(CProject VERSION 1.0.0 LANGUAGES C C++)
add_executable(main 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

--build <위치>: <위치>에 대해 빌드 수행make 명령 쓰거나, $ cmake --build . 로 빌드 수행$ cmake --build .


--build <위치> --target <target>: <target> 수행make clean을 수행하고 싶다면?--target clean$ cmake --build . --target clean
$ cmake . : updateCMake project를 파싱한적 있다면, 아래의 명령으로 업데이트 가능하다.build $ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/markyang/test-c/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.
cd build
cmake -S .. -B . -G "Unix Makefiles" # option 1
cmake .. -G "Unix Makefiles" # option 2
cd build
cmake -S .. -B . -G "Visual Studio 16 2019" # option 1
cmake .. -G "Visual Studio 16 2019" # option 2
cd build
cmake -S .. -B . -G "Ninja" # option 1
cmake .. -G "Ninja" # option 2
