Difference between revisions of "CMake"
m (→Building) |
m (→Why do you use CMake additionally?) |
||
Line 54: | Line 54: | ||
:* For Windows issues which hold for both compilers, you would use<tt>IF (WIN32)</tt>. | :* For Windows issues which hold for both compilers, you would use<tt>IF (WIN32)</tt>. | ||
− | === Why do you use CMake | + | === Why do you use CMake at all? === |
See http://lists.gnucash.org/pipermail/gnucash-devel/2010-February/027582.html | See http://lists.gnucash.org/pipermail/gnucash-devel/2010-February/027582.html |
Revision as of 10:30, 1 March 2010
CMake is a build system which replaces automake/autoconf (the "autotools") and the shell scripts which were produced by the autotools. Similar to the autotools, the actual build on Linux is done through Makefiles. CMake supports Linux, Windows/mingw, Windows/MSVC and other platforms.
- http://www.cmake.org/Wiki/CMake_FAQ FAQ
- http://www.cmake.org/HTML/Download.html - Download
- http://www.cmake.org/HTML/Documentation.html - The same page which you also get by "man cmake"
- http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/ - Potentially helpful additional macros
Contents
- 1 Building
- 2 FAQ
- 2.1 How can you change between a Debug and Release build
- 2.2 Which variables are set in CMake when running CMakeLists.txt?
- 2.3 Which C preprocessor macros tell me whether I'm on Windows or Linux?
- 2.4 How can I check in the CMakeLists.txt code whether I'm on Windows or Linux?
- 2.5 Why do you use CMake at all?
Building
CMake actively encourages the user to build the project in a "separate build directory". That is, if the source is located in $HOME/gnucash, you should create a new directory for where the build is located - e.g. $HOME/gnucash/build, or also $HOME/gnucash-builds/my-build.
Currently in gnucash, only the sub-directory "src/" contains an experimental cmake build system. Hence, to build this experiment yourself, run the following commands from the top-level gnucash directory:
mkdir build-cmake cd build-cmake cmake ../src
The general syntax here is "cmake <path to source>". Once the build directory is set up (which is the case if the build directory contains a file named CMakeCache.txt), you can re-run cmake by typing "cmake <path to build directory>", e.g. "cmake .".
To run the build, as usual type
make
FAQ
How can you change between a Debug and Release build
- Use the options -DCMAKE_BUILD_TYPE=Debug or -DCMAKE_BUILD_TYPE=Release when calling CMake, or change the Variable CMAKE_BUILD_TYPE directly in the CMakeCache.txt file.
Which variables are set in CMake when running CMakeLists.txt?
- That's a long list. See http://www.cmake.org/Wiki/CMake_Useful_Variables
Which C preprocessor macros tell me whether I'm on Windows or Linux?
#ifdef __linux // For linux-only code // ... #ifdef _WIN32 // For Windows-MSVC and Windows-Cygwin, but *not* Windows-mingw // ... #ifdef __MINGW32__ // For Windows-mingw // ... #ifdef _MSC_VER // For only Windows-MSVC // ...
- Note: These macros do not result from CMake; instead, they exist in the respective build system already. Hence, those macros can be used regardless whether cmake is used or not.
How can I check in the CMakeLists.txt code whether I'm on Windows or Linux?
IF (UNIX) # All unix-like OS's, including Apple OS X (and Cygwin) # ... IF (WIN32) # All windows versions (including Cygwin) # ... IF (MINGW) # Mingw compiler on windows # ... IF (MSVC) # Microsoft compiler on windows # ...
- In other words:
- For Unix-only stuff you would write IF (UNIX)
- For Windows issues which concern either Mingw or MSVC, you would use IF (MINGW) or IF (MSVC), respectively.
- For Windows issues which hold for both compilers, you would useIF (WIN32).
Why do you use CMake at all?
See http://lists.gnucash.org/pipermail/gnucash-devel/2010-February/027582.html