Difference between revisions of "CMake"

From GnuCash
Jump to: navigation, search
(FAQ: link to mailing list reasons)
(Update most CMake links)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
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.
 
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
+
* [{{URL:cmake-wiki|FAQ}} FAQ]
* http://www.cmake.org/HTML/Download.html - Download
+
* [{{URL:cmake}}download/ Download CMake]
* http://www.cmake.org/HTML/Documentation.html - The same page which you also get by "man cmake"
+
* [{{URL:cmake}}documentation/ Documentation] - The same page which you also get by "man cmake".
* http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/ - Potentially helpful additional macros
+
* <s>http://websvn.kde.org/trunk/KDE/kdelibs/cmake/modules/</s> [Moved, probably related: {{URL:cmake}}cmake/help/latest/module/FindKDE4.html] - Potentially helpful additional macros
 +
* [https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/ A blog post] about handling dependencies and targets for custom build commands.
 +
* [{{URL:llvm}}docs/CMakePrimer.html LLVM's CMake Primer], a more programmer-oriented tutorial than the one in the CMake documentation.
 +
*[https://crascit.com/professional-cmake/ Professional CMake: A Practical Guide], ~ US $30
  
 
== Building ==
 
== 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.
+
Please see [[Building On Linux#Build using CMake and Ninja]].
  
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:
+
== GnuCash Documentation Configuration Variables ==
 +
They are in [[Initializing_Documentation_Build_Environment#CMake]].
  
  mkdir build-cmake
+
== GnuCash Program Configuration Variables ==
cd build-cmake
+
GnuCash's CMakeLists.txt defines the following configuration options and defaults:
cmake ../src
+
{|border=1
 +
!width="128" | Option
 +
!width="256" | Description
 +
!width="64" | Default
 +
|-
 +
| WITH_SQL || Build this project with SQL (libdbi) support || ON
 +
|-
 +
| WITH_AQBANKING || Build this project with aqbanking (online banking) support || ON
 +
|-
 +
| WITH_GNUCASH || Build all of GnuCash, not just the library || ON
 +
|-
 +
| WITH_CUTECASH || Also build cutecash || Removed in 3.x
 +
|-
 +
| WITH_OFX || Compile with ofx support (needs LibOFX)|| ON
 +
|-
 +
| WITH_PYTHON || Enable python plugin and bindings || OFF
 +
|-
 +
| ENABLE_BINRELOC || Compile with binary relocation support || ON
 +
|-
 +
| ENABLE_REGISTER2 || Compile with register2 enabled || OFF
 +
|-
 +
| DISABLE_NLS || Do not use Native Language Support || OFF
 +
|-
 +
| DISABLE_DEPRECATED_GLIB || Don't use deprecated glib functions || OFF
 +
|-
 +
| DISABLE_DEPRECATED_GTK || Don't use deprecated gtk, gdk or gdk-pixbuf functions || OFF
 +
|-
 +
| DISABLE_DEPRECATED_GNOME || Don't use deprecated gnome functions || OFF
 +
|-
 +
| ALLOW_OLD_GETTEXT || allow to configure build with a gettext version older than 0.19.6. Some files will not be translated! || OFF
 +
|-
 +
|}
  
The general syntax here is "cmake <path to source>". Once the build directory is set up (which you can identify by the file CMakeCache.txt), you can re-run cmake by typing "cmake <path to build directory>", e.g. "cmake .".
+
To change from a default define the option on the cmake command line, e.g. <tt>-DWITH_PYTHON=ON</tt>.
 +
Other CMake variables you may need to define:
 +
:;CMAKE_BUILD_TYPE: <tt>Debug</tt>, <tt>Release</tt>, or … [https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html CMake Manual]
 +
:;CMAKE_INSTALL_PREFIX: The target installation directory, defaults to <tt>/usr/local</tt>.
 +
:;CMAKE_PREFIX_PATH: A ';' separated list of paths where dependencies are installed. No default.
 +
:;GNC_DBD_DIR: The location of the dbi-driver libraries, required for the SQL backends.
  
To run the build, as usual type
+
;See also: [[Dependency Graphs]]
make
 
  
 
== FAQ ==
 
== FAQ ==
 
===How can you change between a Debug and Release build===
 
===How can you change between a Debug and Release build===
 
:Use the options <tt>-DCMAKE_BUILD_TYPE=Debug</tt> or <tt>-DCMAKE_BUILD_TYPE=Release</tt> when calling CMake, or change the Variable CMAKE_BUILD_TYPE directly in the CMakeCache.txt file.
 
:Use the options <tt>-DCMAKE_BUILD_TYPE=Debug</tt> or <tt>-DCMAKE_BUILD_TYPE=Release</tt> when calling CMake, or change the Variable CMAKE_BUILD_TYPE directly in the CMakeCache.txt file.
 +
 +
===How can I see the actual compiler commands: Verbose mode?===
 +
By default, cmake builds the makefiles with verbose mode disabled. You can enable this verbose mode when calling make by the argument VERBOSE=1, like so:
 +
make VERBOSE=1
 +
Alternatively, you can switch on the verbose mode for the cmake configuration by setting the variable CMAKE_VERBOSE_MAKEFILE=on, like so:
 +
cmake -DCMAKE_VERBOSE_MAKEFILE=on .
  
 
===Which variables are set in CMake when running CMakeLists.txt?===
 
===Which variables are set in CMake when running CMakeLists.txt?===
:That's a long list. See http://www.cmake.org/Wiki/CMake_Useful_Variables
+
:That's a long list. See [{{URL:cmake-wiki}}Useful-Variables CMake Wiki: CMake_Useful_Variables]
  
 
===Which C preprocessor macros tell me whether I'm on Windows or Linux?===
 
===Which C preprocessor macros tell me whether I'm on Windows or Linux?===
:See http://www.cmake.org/Wiki/CMake_Platform_Dependent_Issues#The_Platforms_.2F_Compilers_Table:
+
:See [{{URL:cmake-wiki}}Platform-Dependent-Issues#the-platforms--compilers-table CMake Wiki: Platform-Dependent-Issues#the-platforms--compilers-table]:
 
  #ifdef __linux // For linux-only code
 
  #ifdef __linux // For linux-only code
 
  // ...
 
  // ...
Line 40: Line 85:
  
 
===How can I check in the CMakeLists.txt code whether I'm on Windows or Linux?===
 
===How can I check in the CMakeLists.txt code whether I'm on Windows or Linux?===
:Se http://www.cmake.org/Wiki/CMake_Useful_Variables#System_.26_Compiler_Information
+
:See [{{URL:cmake-wiki}}Useful-Variables#system--compiler-information CMake Wiki: System & Compiler Information]
 
  IF (UNIX)  # All unix-like OS's, including Apple OS X (and Cygwin)
 
  IF (UNIX)  # All unix-like OS's, including Apple OS X (and Cygwin)
 
  # ...
 
  # ...
Line 53: Line 98:
 
:* For Windows issues which concern either Mingw or MSVC, you would use <tt>IF (MINGW)</tt> or <tt>IF (MSVC)</tt>, respectively.
 
:* For Windows issues which concern either Mingw or MSVC, you would use <tt>IF (MINGW)</tt> or <tt>IF (MSVC)</tt>, respectively.
 
:* 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 additionally? ===
 
See http://lists.gnucash.org/pipermail/gnucash-devel/2010-February/027582.html
 

Latest revision as of 23:20, 5 October 2024

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.

Building

Please see Building On Linux#Build using CMake and Ninja.

GnuCash Documentation Configuration Variables

They are in Initializing_Documentation_Build_Environment#CMake.

GnuCash Program Configuration Variables

GnuCash's CMakeLists.txt defines the following configuration options and defaults:

Option Description Default
WITH_SQL Build this project with SQL (libdbi) support ON
WITH_AQBANKING Build this project with aqbanking (online banking) support ON
WITH_GNUCASH Build all of GnuCash, not just the library ON
WITH_CUTECASH Also build cutecash Removed in 3.x
WITH_OFX Compile with ofx support (needs LibOFX) ON
WITH_PYTHON Enable python plugin and bindings OFF
ENABLE_BINRELOC Compile with binary relocation support ON
ENABLE_REGISTER2 Compile with register2 enabled OFF
DISABLE_NLS Do not use Native Language Support OFF
DISABLE_DEPRECATED_GLIB Don't use deprecated glib functions OFF
DISABLE_DEPRECATED_GTK Don't use deprecated gtk, gdk or gdk-pixbuf functions OFF
DISABLE_DEPRECATED_GNOME Don't use deprecated gnome functions OFF
ALLOW_OLD_GETTEXT allow to configure build with a gettext version older than 0.19.6. Some files will not be translated! OFF

To change from a default define the option on the cmake command line, e.g. -DWITH_PYTHON=ON. Other CMake variables you may need to define:

CMAKE_BUILD_TYPE
Debug, Release, or … CMake Manual
CMAKE_INSTALL_PREFIX
The target installation directory, defaults to /usr/local.
CMAKE_PREFIX_PATH
A ';' separated list of paths where dependencies are installed. No default.
GNC_DBD_DIR
The location of the dbi-driver libraries, required for the SQL backends.
See also
Dependency Graphs

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.

How can I see the actual compiler commands: Verbose mode?

By default, cmake builds the makefiles with verbose mode disabled. You can enable this verbose mode when calling make by the argument VERBOSE=1, like so:

make VERBOSE=1

Alternatively, you can switch on the verbose mode for the cmake configuration by setting the variable CMAKE_VERBOSE_MAKEFILE=on, like so:

cmake -DCMAKE_VERBOSE_MAKEFILE=on .

Which variables are set in CMake when running CMakeLists.txt?

That's a long list. See CMake Wiki: CMake_Useful_Variables

Which C preprocessor macros tell me whether I'm on Windows or Linux?

See CMake Wiki: Platform-Dependent-Issues#the-platforms--compilers-table:
#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?

See CMake Wiki: System & Compiler Information
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).