User Tools

Site Tools


cmake

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cmake [2012/11/05 14:45]
mikael.ohman
cmake [2017/01/25 17:34] (current)
smilauer
Line 1: Line 1:
 ====== CMake tutorial ====== ====== CMake tutorial ======
 +CMake is a cross-platform build system with many nice features.
 +It generates platform specific build files, such as Makefiles or Visual Studio project files during configuration.
  
 +It supports multiple targets, e.g. out-of-tree configurations and builds (simply configure from multiple build directories).
 ===== Developers ===== ===== Developers =====
 To add new files to be compiled, you will need to edit one of the following files To add new files to be compiled, you will need to edit one of the following files
Line 23: Line 26:
 ===== Linux ===== ===== Linux =====
 Install CMake from the package system of your choice. Install CMake from the package system of your choice.
-Create ​out-of-tree build directory ​+Create ​an out-of-tree build directory:
  
   mkdir -p ~/​build/​debug/​   mkdir -p ~/​build/​debug/​
Line 31: Line 34:
   ctest   ctest
  
-Instead of ''​cmake''​ can use ''​ccmake''​ which uses an ncurses interface, or ''​cmake-gui''​ for a GUI.+Instead of ''​cmake'' ​you can use ''​ccmake''​ which uses an ncurses interface, or ''​cmake-gui''​ for a GUI.
 Use the command ''​make help''​ for a list of all targets. Use the command ''​make help''​ for a list of all targets.
  
Line 43: Line 46:
   make   make
   ctest   ctest
-//**Note:** After initial configuration,​ you cannot change compiler. If you install a new version of GCC, you will need to remove the build directory and do the configuration again. //+//**Note:** After initial configuration,​ you cannot change compiler. If you install a new version of GCC, you will need to remove the build directory and do the configuration again. Just doing ''​make clean''​ isn't enough.// 
 + 
 +=== Tips: === 
 +* The build process usually hides the compiler command lines, to show them, use 
 + 
 +   $ make VERBOSE=1 
 ==== CTest ==== ==== CTest ====
 Some useful options for ctest include running the tests in parallel; Some useful options for ctest include running the tests in parallel;
Line 63: Line 72:
   cpack -G ZIP   cpack -G ZIP
   ...   ...
 +  ​
 +==== KDevelop ====
 +The KDevelop IDE has build in support for CMake projects (and GIT). It includes a graphical configuration of multiple targets. Simply choose to import a project, and select CMakeLists.txt from the source directory
 +You can then open the configuration from the menu and make your choices:
 +
 +{{:​kdevelop_cmake.png}}
 +
 +==== Python bindings ====
 +With CMake, it is also possible to create shared library loadable as Python module. You need CMake version at least 2.8.8 and two additional cmake parameters ( ''​-DUSE_SHARED_LIB=ON''​ and ''​-DUSE_PYTHON_BINDINGS=ON''​ ). After standard ''​make''​ procedure, ''​liboofem.so''​ file is created in ''​build''​ directory. From python it can be loaded and use like this:
 +  import sys
 +  sys.path.append("/​path/​to/​build/​directory"​) # path where liboofem.so was created
 +  import liboofem
 +  ​
 +  a = liboofem.FloatArray(2)
 +  a[1] = 15.0
 +  a[0] = 10.0
 +  print a[0], a[1]
 +
 +  ​
 ===== Windows (Visual Studio) ===== ===== Windows (Visual Studio) =====
   - Install CMake   - Install CMake
Line 69: Line 97:
   - Press generate to produce project files for VS.   - Press generate to produce project files for VS.
  
-//Note: The build types (debug, release) are handled internally by Visual Studio, so no configuration option for this is presented in CMake//+To run the test suite, open the solution explorer in VS and "​build"​ the ''​tests''​ or ''​benchmarks''​ targets to run through the test suite or benchmark suite respectively. 
 + 
 +//**Note:** The build types (debug, release) are handled internally by Visual Studio, so no configuration option for this is presented in CMake// 
 + 
 +//**Note:** PETSc isn't easily built on windows, so support for parallel builds is still lacking//
  
-To run the test suiteopen the solution explorer in VS and "build" ​the ''​test''​ target ​to run through ​the test suite.+===== Windows (MinGW) ===== 
 +  - Install CMake (tested with version 3.3.2) 
 +  - Install a new mingw-w64 (tested with version 5.2.0). It has support for 32-bit if necessary. MinGW-w64 version is selected from a [[http://​sourceforge.net/​projects/​mingw-w64/​|GUI installer]].  
 +  - Run $ mingw32-make.exe -v 
 +  - Run a batch e.g. C:\Program Files (x86)\mingw-w64\i686-5.2.0-posix-dwarf-rt_v4-rev1\mingw-w64.bat which opens a new terminal. In that terminalwe have already PATH to mingw32-make.exe. If the PATH is already set up, any terminal would work. 
 +  - Create directory, e.g. mkdir C:​\oofem\optimized ​and cd under optimized. 
 +  - Run cmake with flags, e.g. $ cmake.exe -G"MinGW Makefiles" ​-DCMAKE_BUILD_TYPE=RELEASE -DUSE_SHARED_LIB="​OFF"​ -DUSE_IML="​ON"​ -DUSE_DSS="​ON"​ .. 
 +  - Run mingw32-make.exe -j 3 to compile 
 +  - If you want smooth transfer of oofem.exe to another windows computer, you need to put all *.dll from C:\Program Files (x86)\mingw-w64\i686-5.2.0-posix-dwarf-rt_v4-rev1\mingw32\bin in the same directory as oofem.exe. 
 +  - Run $ctest for checking OOFEM tests
cmake.1352123106.txt.gz · Last modified: 2012/11/05 14:45 by mikael.ohman