(New page: {{Template:I18n/Language Navigation Bar|Development/Tutorials/CMake}} == 소개 == CMake는 스크립트 파일을 읽고, 그것이 실행되는 플랫폼의 native 빌드 시스템의 ...) |
|||
| Line 116: | Line 116: | ||
==== KDevelop 프로젝트 파일 ==== | ==== KDevelop 프로젝트 파일 ==== | ||
| − | If you prefer project files for KDevelop (which will basically be Makefiles accompanied by some extra files for KDevelop), run it like this: | + | 만약 (기본적으로 KDevelop를 위한 몇몇 파일에 의해 Makefile이 동반되는)KDevelop를 위한 프로젝트 파일을 좋아한다면, 이것과 같이 실행하라. |
| + | :''If you prefer project files for KDevelop (which will basically be Makefiles accompanied by some extra files for KDevelop), run it like this:'' | ||
<code> | <code> | ||
$ cmake ../kdelibs -GKDevelop3 | $ cmake ../kdelibs -GKDevelop3 | ||
</code> | </code> | ||
| − | Use 'cmake -h' to find out which generators CMake supports and the other options. | + | CMake가 지원하는 것과 다른 옵션을 찾기 위해 'cmake -h'를 사용하라. |
| + | :''Use 'cmake -h' to find out which generators CMake supports and the other options.'' | ||
==== CMake와 Qt4 ==== | ==== CMake와 Qt4 ==== | ||
| − | To locate Qt 4, CMake searches for qmake in your execute path. CMake does ''not'' use the QTDIR environment variable. So make sure that the first qmake found in the execution path is the one you like to use. | + | Qt 4에 위치한 곳을 찾아내기 위해, CMake는 당신의 실행 경로에서 qmake를 찾는다. CMake는 QTDIR 환경 변수를 사용하지 않는다. 그러므로, 실행 경로에서 찾은 처음 qmake가 사용하기 원하는 것인지 확인하라. |
| + | :''To locate Qt 4, CMake searches for qmake in your execute path. CMake does ''not'' use the QTDIR environment variable. So make sure that the first qmake found in the execution path is the one you like to use.'' | ||
==== 더 자세한 세부사항 ==== | ==== 더 자세한 세부사항 ==== | ||
| − | When CMake has finished, it will have created a file called "CMakeCache.txt". This file contains all the settings CMake has detected on your system. If you want to run CMake with another generator or you want CMake to detect everything again, delete this file. | + | CMake가 종료되었을 때, "CMakeCache.txt"라는 파일이 생성될 것이다. 이것은 당신의 시스템에서 CMake가 찾은 모든 설정을 포함한다. 만약 다른 생성 프로그램으로 CMake를 수행하기를 원하거나, CMake가 모든 것을 다시 찾기를 원한다면 이 파일을 지워라. |
| + | :''When CMake has finished, it will have created a file called "CMakeCache.txt". This file contains all the settings CMake has detected on your system. If you want to run CMake with another generator or you want CMake to detect everything again, delete this file.'' | ||
| − | If CMake didn't find something, but you know it is somewere on your box, you can tell CMake manually where to find it. CMake uses variables to store this information. These variables are cached in the already mentioned file CMakeCache.txt. You have three options to adjust these variables manually: | + | 만약 CMake가 무언가를 찾지 않았지만, 당신이 이것이 당신의 상자의 어딘가에 있다는 것을 안다면, 당신은 CMake에게 찾을 곳을 수동적으로 알려줄 수 있다. CMake는 이 정보를 저장하는 변수를 사용한다. 이 변수들은 이미 언급된 CMakeCache.txt 파일에 캐시된다. 이 변수들을 수동적으로 적용하기 위해 3가지 방법이 있다. |
| − | * tell CMake the correct value via the command line: cmake ../kdelibs -DNAME_OF_THE_VARIABLE=value | + | :''If CMake didn't find something, but you know it is somewere on your box, you can tell CMake manually where to find it. CMake uses variables to store this information. These variables are cached in the already mentioned file CMakeCache.txt. You have three options to adjust these variables manually:'' |
| + | |||
| + | * 커맨드 라인 하에서 올바른 값을 CMake에게 말하기 : cmake ../kdelibs -DNAME_OF_THE_VARIABLE=value | ||
| + | * CMake 변수를 정용하기 위해 GUI 기반의 커서를 제공하는 ccmake를 사용하기(실행: ccmake ../kdelibs) | ||
| + | * CMakeCache.txt를 직접 수정하기(추천하지 않는다.) | ||
| + | :''* tell CMake the correct value via the command line: cmake ../kdelibs -DNAME_OF_THE_VARIABLE=value | ||
* use ccmake, which provides a curses based GUI to adjust the CMake variables (run: ccmake ../kdelibs) | * use ccmake, which provides a curses based GUI to adjust the CMake variables (run: ccmake ../kdelibs) | ||
| − | * edit the file CMakeCache.txt directly (not recommended) | + | * edit the file CMakeCache.txt directly (not recommended)'' |
| − | You should run "ccmake ../kdelibs" at least once so that you get an impression which variables CMake uses. Press "T" to see also the "advanced" variables. So, if CMake didn't find something, start ccmake and adjust it manually. | + | 당신은 최소한 한번은 "ccmake ../kdelibs"를 실행해야 한다. 그래서 CMake가 사용하는 변수의 결과물을 얻는다. |
| + | "T"를 누르고 "advanced" 변수를 보기 위해 "T"를 눌러라. 그래서 CMake가 아무것도 찾지 않았다면, ccmake를 시작하고, 수동적으로 그것을 적용하라. | ||
| + | :''You should run "ccmake ../kdelibs" at least once so that you get an impression which variables CMake uses. Press "T" to see also the "advanced" variables. So, if CMake didn't find something, start ccmake and adjust it manually.'' | ||
==== 커맨드 라인 변수들 ==== | ==== 커맨드 라인 변수들 ==== | ||
| Line 245: | Line 256: | ||
* a file AdditionalInfo.txt will be created. There you will see all *.in and *.in.in files of your project. The stuff done in these files will have to be converted manually to cmake. | * a file AdditionalInfo.txt will be created. There you will see all *.in and *.in.in files of your project. The stuff done in these files will have to be converted manually to cmake. | ||
| − | == | + | == 자주묻는 질문들== |
| − | === | + | === CMake 문법과 들여쓰기에 대해 내가 좋아하는 에디터에 어떻게 설정할 수 있습니까? === |
| − | Read the CMake Wiki section [http://www.cmake.org/Wiki/CMake_Editors_Support CMake Editors Support]. It describes how to setup Emacs (XEmacs works too), VIM, Kate, KWrite, and KDevelop. | + | CMake 위키의 [http://www.cmake.org/Wiki/CMake_Editors_Support CMake 에디터 지원] 섹션을 읽어라. 이것은 Emacs(XEmacs도 동작한다.), VIM, Kate, KWrite, 그리고 KDevelop에서 어떻게 설정하는지에 대해 설명한다. |
| + | :''Read the CMake Wiki section [http://www.cmake.org/Wiki/CMake_Editors_Support CMake Editors Support]. It describes how to setup Emacs (XEmacs works too), VIM, Kate, KWrite, and KDevelop.'' | ||
| − | === | + | === 나는 빌드 중에 몇몇 파일들을 생성하는 것이 필요합니다. 어떻게 해야 합니까? === |
| − | Use ADD_CUSTOM_COMMAND(). It's explained here in the CMake wiki: [http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F How can I generate a source file during the build] | + | :ADD_CUSTOM_COMMAN()를 사용하라. 이것은 CMake 위키 안의[http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F 빌드하는 동안 어떻게 소스파일을 생성할 수 있는 방법] |
| + | 섹션에서 설명되어진다. | ||
| + | :''Use ADD_CUSTOM_COMMAND(). It's explained here in the CMake wiki: [http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F How can I generate a source file during the build]'' | ||
=== I need to build an executable which is used later on during the build to generate files. How do I do this ? === | === I need to build an executable which is used later on during the build to generate files. How do I do this ? === | ||
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
CMake는 스크립트 파일을 읽고, 그것이 실행되는 플랫폼의 native 빌드 시스템의 위해 input 파일들을 생성한다. 이것은 GNU Makefile, KDevelop 프로젝트파일, XCode 프로젝트 파일, 그리고 Visual Studio 프로젝트 파일을 생성할수 있다.
CMake는 자유 소프트웨어이고, BSD-style 라이센스 한에서 릴리즈된다. 이것은 Kitware Inc.에 의해 개발되었다.
아래의 링크들은 일반적으로 CMake에 대해 배울수 있는 몇몇 괜찮은 곳들이다.:
또한 CMake 메일링 리스트에 가입하는 것을 고려해보라.
CMake는 2006년 3월에 결정된 KDE 4 release의 공식적인 도구이다. 첫번째로 오래된 KDE 도구 automake와 unsermake와 비교하여 기술적인 장점때문이다.:
[1]에서 CMake의 마지막 버전을 검색한다.
다운로드 하여 압축을 풀고, 컴파일 한다.:
$ mkdir cmake-build
$ cd cmake-build
$ ../bootstrap
$ make
$ make install
기본적으로 이것은 CMake를 /user/local 안에 설치할 것이다. 그러므로 당신의 실행 경로 안에/user/local/bin을 가지고 있도록 해야한다. 만약 설치 prefix를 바꾸려면, (예를 들어 데비안에서는 /usr로), '--prefix=PATH' 옵션을 bootstrap 명령에 추가하라.
만약 현재 개발버전을 사용하기를 원한다면, here에 위치한 설명에 따르라.
[3]에서 CMake의 가장 마지막 안정 버전을 검색하라.
다운로드받아서 cmake 인스톨러를 설치하라.
기본적으로 이것은 C:\Program Files\CMake 2.4에 설치될 것이다. 그러므로 당신의 실행 경로에 <installpath>\bin를 추가시켜야 한다.
만약 현재 개발 버전을 사용하기를 원한다면, here의 설명에 따르라.
당신의 시스템을 위해 빌드 파일들을 생성하기 위해서는 CMake를 실행해야 한다. in-source(소스 안에서)와 out-of-source(소스 밖에서) 둘 다 CMake에 의해 지원된다. 그러나 현재 in-source(소스 안에서) 빌드는 KDE 구현에 의하여 막혀져 있다.
그러므로 ~/src/kdelibs/ 안에 kdelibs/를 가지고 있다고 한다면, 다음을 수행한다.
$ ls
kdelibs/
$ mkdir kdelibs-build
$ cd kdelibs-build
$ cmake ../kdelibs
이것은 kdelibs-build/ 안에 kdelibs의 빌드를 위해 Makefile을 생성할 것이다.
당신의 시스템을 위해 빌드 파일들을 생성하기 위해서는 CMake를 실행해야 한다. in-source(소스 안에서)와 out-of-source(소스 밖에서) 둘 다 CMake에 의해 지원된다. 그러나 현재 in-source(소스 안에서) 빌드는 KDE 구현에 의하여 막혀져 있다.
c:\daten\kde4 안에 kdelib\를 가지고 있다고 한다면, 다음을 수행한다.:
c:\daten\kde4> cd kdelibs\win
c:\daten\kde4> cmake
c:\daten\kde4> make
c:\daten\kde4> make install
c:\daten\kde4> cd ..
c:\daten\kde4> mkdir kdelibs-build
c:\daten\kde4> cd kdelibs-build
c:\daten\kde4\kdelibs-build> cmake ..\kdelibs
이것은 kdelibs-build/ 안에 kdelibs의 빌드를 위해 Makefile을 생성할 것이다. 윈도우에서 KDE 컴파일에 관한 정보를 얻고 싶다면, KDE on Windows를 참고하라.
만약 (기본적으로 KDevelop를 위한 몇몇 파일에 의해 Makefile이 동반되는)KDevelop를 위한 프로젝트 파일을 좋아한다면, 이것과 같이 실행하라.
$ cmake ../kdelibs -GKDevelop3
CMake가 지원하는 것과 다른 옵션을 찾기 위해 'cmake -h'를 사용하라.
Qt 4에 위치한 곳을 찾아내기 위해, CMake는 당신의 실행 경로에서 qmake를 찾는다. CMake는 QTDIR 환경 변수를 사용하지 않는다. 그러므로, 실행 경로에서 찾은 처음 qmake가 사용하기 원하는 것인지 확인하라.
CMake가 종료되었을 때, "CMakeCache.txt"라는 파일이 생성될 것이다. 이것은 당신의 시스템에서 CMake가 찾은 모든 설정을 포함한다. 만약 다른 생성 프로그램으로 CMake를 수행하기를 원하거나, CMake가 모든 것을 다시 찾기를 원한다면 이 파일을 지워라.
만약 CMake가 무언가를 찾지 않았지만, 당신이 이것이 당신의 상자의 어딘가에 있다는 것을 안다면, 당신은 CMake에게 찾을 곳을 수동적으로 알려줄 수 있다. CMake는 이 정보를 저장하는 변수를 사용한다. 이 변수들은 이미 언급된 CMakeCache.txt 파일에 캐시된다. 이 변수들을 수동적으로 적용하기 위해 3가지 방법이 있다.
당신은 최소한 한번은 "ccmake ../kdelibs"를 실행해야 한다. 그래서 CMake가 사용하는 변수의 결과물을 얻는다. "T"를 누르고 "advanced" 변수를 보기 위해 "T"를 눌러라. 그래서 CMake가 아무것도 찾지 않았다면, ccmake를 시작하고, 수동적으로 그것을 적용하라.
Some cmake command line variables you may want to set:
If you have headers and libraries installed in non-standard locations that cmake cannot find (e.g., fink on Mac OSX installs to /sw), then set the following as environment variables. Despite the similar naming convention, these will not work as arguments on the cmake command line:
For more information on variables, see this cmake.org wiki page
If cmake finishes with "Generating done" then there was no errors, but if it finishes with "Configuring done" then there was errors that you have to fix. Once cmake finishes successfully, run your buildtool (i.e. make, KDevelop, XCode or MSVC) and build and wait until it has finished. Then "make install".
If you got a failure that says something like
CMake Error: This project requires some variables to be set,
and cmake can not find them.
Please set the following variables:
X11_XTest_LIB (ADVANCED)
then you may have a missing library (or other dependency). To find
out which library, search in the cmake/modules directory for
the variable that cmake can't find. In the example above, it is
FIND_LIBRARY(X11_XTest_LIB Xtst ${X11_LIB_SEARCH_PATH})
So the missing library is Xtst. You then need to find it (perhaps installing a libXtst-devel library) and re-run cmake.
Here's the most simple CMakeLists.txt:
add_executable(hello main.cpp)
This will create an executable named "hello" (or "hello.exe" under Windows) from the source file main.cpp. You can mix C and C++ files as you want. You can have multiple executables and libraries in one CMakeLists.txt. The same source file can be used in multiple targets, it will be compiled for each target independently from the other targets. Probably the most important part of the cmake language are the variables:
SET( MY_SOURCES main.cpp widget.cpp)
MESSAGE(STATUS "my sources: ${MY_SOURCES}")
So, use the SET() command to set the value of a variable. If you list more than one string, the variable will be a list. A list is a list of strings separated by semicolons. If you set it to only one item, it will have just that value. To get the value of a variable, use ${VAR}.
You can iterate over a list using FOREACH():
FOREACH(next_ITEM ${MY_SOURCES})
MESSAGE(STATUS "next item: ${next_ITEM}")
ENDFOREACH(next_ITEM ${MY_SOURCES}) The commands in CMake are case-insensitive. Names of variables and names of parameter are case-sensitive.
You can also test for various things:
IF (UNIX)
MESSAGE(STATUS "This is UNIX (including OS X and CygWin)")
ENDIF (UNIX)
IF (MSVC)
SET(MY_SRCS ${MY_SRCS} winextra.cpp)
ENDIF (MSVC) In this second example you can see also how to append items to a list.
In the cmake Wiki there is also a tutorial on using cmake to build KDE 4 software. It is recommended reading.
Here's a basic CMakeList file that builds a small KDE 4 project:
PROJECT(kde4project)
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} )
SET(KDE4ProjectSources kde4mainapp.cpp someclass.cpp someotherclass.cpp)
KDE4_ADD_EXECUTABLE(kde4project ${KDE4ProjectSources} )
TARGET_LINK_LIBRARIES(kde4project ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} )
Variables, macros and other useful information specific to KDE can be found at the Development/KDE and CMake Together page.
CMake can be extended using cmake scripts. CMake comes with a number of scripts; under UNIX they are by default installed to /usr/local/share/CMake/Modules/. The KDE libraries install also a set of cmake modules into share/apps/cmake/modules/. The files located there will be preferred over the ones in the system global cmake module path. For detecting software packages there are FindFOO.cmake files, see here for more information. You can also write macros in CMake. They are powerful enough to do most things you will need to build software, but they are not intended to be used as a general purpose programming language.
In kdesdk/cmake/ you can find a script am2cmake . This is a ruby script, so you need to have ruby installed. Run am2cmake in the toplevel directory of your sources:
$ cd src/mykooltool/
$ am2cmake --kde4
Don't forget the switch "--kde4", otherwise it won't generate files suitable for KDE 4 software. The converted files 'may' work as they are, but complicated projects will require some additional editing.
You may have to:
CMake 위키의 CMake 에디터 지원 섹션을 읽어라. 이것은 Emacs(XEmacs도 동작한다.), VIM, Kate, KWrite, 그리고 KDevelop에서 어떻게 설정하는지에 대해 설명한다.
섹션에서 설명되어진다.
Let's say the executable is called genembed. Then use KDE4_ADD_EXECUTABLE(foo RUN_UNINSTALLED ${fooSources})to create the executable. The RUN_UNINSTALLED option is important, because the executable has to run from the build dir and has to link to the libraries in the builddir. To achieve this, the executable is compiled with RPATH set accordingly and a wrapper shell script, named just like the executable but with the suffix ".sh" is created. This shell scripts sets up LD_LIBRARY_PATH and the calls the actual executable.
Use this wrapper shell script in the ADD_CUSTOM_COMMAND() as described above.
You can find out the name and exact location by querying the property WRAPPER_SCRIPT. Here's a full example taken from kdelibs/kstyles/keramik/ :
KDE4_ADD_EXECUTABLE(genembed RUN_UNINSTALLED ${genembed_SRCS})
GET_TARGET_PROPERTY(GENEMBED_EXECUTABLE genembed WRAPPER_SCRIPT)
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/keramikrc.h
COMMAND ${GENEMBED_EXECUTABLE} --file ${CMAKE_CURRENT_BINARY_DIR}/keramikPics.txt > \
${CMAKE_CURRENT_BINARY_DIR}/pixmaps.keramik
DEPENDS genembed ${keramikPics}
)
As you can see genembed is also listed as a dependency, this means cmake knows that it has to build the executable genembed before executing this rule.
No. $KDEDIR is deprecated in KDE 4.
A: If you have an old Qt4 version in your qt/lib directory you must delete the old (4.0.1) files.
Pass the VERBOSE variable to make, i.e.
% make VERBOSE=1
or
% VERBOSE=1 make
For more details see the CMake wiki: Is there an option to produce more 'verbose' compiling?
Simply remove the build directory, or just the contents of the build directory.