PySide CMake Primer: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Rename category "LanguageBindings::PySide" -> "PySide")
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=PySide CMake Primer=
 
 
[[Category:PySide]]
 
 


This page is a basic introduction to CMake, the build system used by PySide and the bindings generator.
This page is a basic introduction to CMake, the build system used by PySide and the bindings generator.
Line 5: Line 9:
These practical steps will focus on how to use CMake on a Linux (or similar) environment but should apply with minor modifications to other supported platforms as well.
These practical steps will focus on how to use CMake on a Linux (or similar) environment but should apply with minor modifications to other supported platforms as well.


==Configuring==
== Configuring ==


===Project file CMakeLists.txt===
=== Project file - CMakeLists.txt ===


CMake parses the file CMakeLists.txt for information about the project, like project name, dependencies, what should be compiled, what should be shipped, and so on.
CMake parses the file CMakeLists.txt for information about the project, like project name, dependencies, what should be compiled, what should be shipped, and so on.


===CMake variables===
=== CMake variables ===


CMake can have its default behavior modified by providing some options in the command line:
CMake can have its default behavior modified by providing some options in the command line:


* <span class="caps">CMAKE</span>_INSTALL_PREFIX=&lt;some path here&gt; sets the install prefix to the specified path.
* CMAKE_INSTALL_PREFIX=<some path here> sets the install prefix to the specified path.
* <span class="caps">CMAKE</span>_MODULE_PATH=&lt;some path here&gt; sets the extra directories where CMake will try to find its modules. (Note that if there are cmake configuration files in the default module path, /usr/lib/, that cmake will use these first.)
* CMAKE_MODULE_PATH=<some path here> sets the extra directories where CMake will try to find its modules. (Note that if there are cmake configuration files in the default module path, /usr/lib/, that cmake will use these first.)
* <span class="caps">CMAKE</span>_TOOLCHAIN_FILE=&lt;file path&gt; sets the path to the file that describes the toolchain used to compile this project. It is very useful when using CMake with Icecream to speed up compilation.
* CMAKE_TOOLCHAIN_FILE=<file path> sets the path to the file that describes the toolchain used to compile this project. It is very useful when using CMake with Icecream to speed up compilation.
* <span class="caps">SITE</span>_PACKAGE=&lt;some path here&gt; sets the Python site-packages directory
* SITE_PACKAGE=<some path here> sets the Python site-packages directory


You can define a variable using the -D&lt;<span class="caps">VARIABLE</span>&gt; switch like the example below.
You can define a variable using the -D<VARIABLE> switch like the example below.


* -<span class="caps">DCMAKE</span>_BUILD_TYPE=Release|Debug sets the building behavior. Default value is Release.
* -DCMAKE_BUILD_TYPE=Release|Debug sets the building behavior. Default value is Release.


===Invoking CMake===
=== Invoking CMake ===


After writing the CMakeLists.txt and deciding which flags will be used, you can invoke CMake using:
After writing the CMakeLists.txt and deciding which flags will be used, you can invoke CMake using:
<code>
cmake <CMake flags> <path to toplevel CMakeLists.txt file>
</code>


For example, if you use the build/ folder to build the project and want it to be installed into /opt/sandbox/, use the following lines:
For example, if you use the build/ folder to build the project and want it to be installed into /opt/sandbox/, use the following lines:
<code>
cd build/
cmake -DCMAKE_INSTALL_PREFIX=/opt/sandbox ..
</code>


CMake will process the project file and write the output files in the current directory.
CMake will process the project file and write the output files in the current directory.


==Building==
== Building ==


After the configuration process, the Makefiles are written and you can build the project by issue the command <code>make</code>.
After the configuration process, the Makefiles are written and you can build the project by issue the command <code>make</code>.


==Installing==
== Installing ==
 
As in the building process, <code>make install</code> will install the files into the target directory.
 
===Categories:===
 
* [[:Category:LanguageBindings|LanguageBindings]]
** [[:Category:LanguageBindings::PySide|PySide]]

Latest revision as of 03:30, 5 June 2016



This page is a basic introduction to CMake, the build system used by PySide and the bindings generator.

These practical steps will focus on how to use CMake on a Linux (or similar) environment but should apply with minor modifications to other supported platforms as well.

Configuring

Project file - CMakeLists.txt

CMake parses the file CMakeLists.txt for information about the project, like project name, dependencies, what should be compiled, what should be shipped, and so on.

CMake variables

CMake can have its default behavior modified by providing some options in the command line:

  • CMAKE_INSTALL_PREFIX=<some path here> sets the install prefix to the specified path.
  • CMAKE_MODULE_PATH=<some path here> sets the extra directories where CMake will try to find its modules. (Note that if there are cmake configuration files in the default module path, /usr/lib/, that cmake will use these first.)
  • CMAKE_TOOLCHAIN_FILE=<file path> sets the path to the file that describes the toolchain used to compile this project. It is very useful when using CMake with Icecream to speed up compilation.
  • SITE_PACKAGE=<some path here> sets the Python site-packages directory

You can define a variable using the -D<VARIABLE> switch like the example below.

  • -DCMAKE_BUILD_TYPE=Release|Debug sets the building behavior. Default value is Release.

Invoking CMake

After writing the CMakeLists.txt and deciding which flags will be used, you can invoke CMake using:

cmake <CMake flags> <path to toplevel CMakeLists.txt file>

For example, if you use the build/ folder to build the project and want it to be installed into /opt/sandbox/, use the following lines:

cd build/
cmake -DCMAKE_INSTALL_PREFIX=/opt/sandbox ..

CMake will process the project file and write the output files in the current directory.

Building

After the configuration process, the Makefiles are written and you can build the project by issue the command

make

.

Installing