Project

General

Profile

{{title}}

Useful links

Source Structure

CMakeTutorial
   |-- app
   |   |-- CMakeLists.txt
   |   |-- main.cxx
   |-- math
   |   |-- advanced
   |   |   |-- AdvancedFunctions.cxx
   |   |   |-- AdvancedFunctions.h
   |   |-- simple
   |   |   |-- SimpleFunctions.cxx
   |   |   |-- SimpleFunctions.h
   |   |-- CMakeLists.txt
   |   |-- MathExports.h
   |-- CMakeLists.txt
   |-- TutorialConfig.h.in

The code is based on the code of this first tutorial, focusing on the use of cmake under Visual Studio.
Some additions/modifications have been made on the CMakeLists.txt and app.cxx files to test also some additional
cmake features described by this second tutorial, describing the basic use of cmake irrespective of the development platform.

It has been tested on both Windows (with Visual Studio) and on Linux (with Eclipse) summarized below.

Test on Windows

Download the tutorial code

[tmp]$ git clone gitolite@ciws.iasfbo.inaf.it:CIWS/Sandbox/PUB/CMakeTutorial.git
Cloning into 'CMakeTutorial'...
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 31 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (31/31), 6.06 KiB | 0 bytes/s, done.
Resolving deltas: 100% (9/9), done.
[tmp]$

Import the code into Visual Studio

Create the Build dir at the same directory level of CMakeTutorial directory, and run cmake to create a build for Visual Studio, i.e.:

With Windows Explorer browse the CMakeTutorial_Build directory and double-click on Tutorial.sln to open the project with Visual Studio.

Build and Run test

right mouse button on ALL_BUILD->Build
right mouse button on INSTALL->Build
right mouse button on RUN_TESTS->Build

1>  Test project C:/Users/massimo/local/CMakeTutorial_Build
1>      Start 1: AppTest1
1>  1/3 Test #1: AppTest1 .........................   Passed    1.96 sec
1>      Start 2: AppTest2
1>  2/3 Test #2: AppTest2 .........................   Passed    0.05 sec
1>      Start 3: AppTest3
1>  3/3 Test #3: AppTest3 .........................   Passed    0.04 sec
1>  
1>  100% tests passed, 0 tests failed out of 3
1>  
1>  Total Test time (real) =   2.07 sec
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

To run test under Debug:

  • right mouse button on the project "app"->Properties->Configuration properties->Debugging and set:
  • Command: ./bin/app.exe
  • Command Arguments: 100
  • Environment: C:/Users/massimo/local/CMakeTutorial_Build/math/Debug (location of math.dll)
  • select the project "app"
  • Ctrl-F5

Test on Linux

Download the tutorial code

[tmp]$ git clone gitbox:CIWS/Sandbox/PUB/CMakeTutorial.git
Cloning into 'CMakeTutorial'...
remote: Counting objects: 31, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 31 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (31/31), 6.06 KiB | 0 bytes/s, done.
Resolving deltas: 100% (9/9), done.
[tmp]$

Import the code into Eclipse

Create the Build dir at the same directory level of CMakeTutorial directory, and run cmake to create a build for Eclipse.

[tmp]$ mkdir CMakeTutorial_Build
[tmp]$ cd CMakeTutorial_Build/
[CMakeTutorial_Build]$ cmake -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/local/bin ../CMakeTutorial
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Could not determine Eclipse version, assuming at least 3.6 (Helios). Adjust CMAKE_ECLIPSE_VERSION if this is wrong.
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
cxx Flags: 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/trifoglio/tmp/CMakeTutorial_Build
[CMakeTutorial_Build]$ 

* Run Eclipse 
> * Import->"Existing Projects into Workspace" and select /home/trifoglio/tmp/CMakeTutorial_Build directory.

Build and Test under Eclipse

  • right mouse button on "Project-Debug@CMakeTutorial_Build"->Build

To Debug:

  • Run->Debug Configuration->Main->Project->Tutorial-Debug@CMakeTutorial_Build
  • Run->Debug Configuration->Main->C/C++ Application-> app/app
  • Run->Debug Configuration->Arguments-> 100
  • right mouse button on "Project-Debug@CMakeTutorial_Build" ->Debug As -> Local C/C++ Application

To Run a single test:

  • Run->Run Configuration->Main->Project->Tutorial-Debug@CMakeTutorial_Build
  • Run->Run Configuration->Main->C/C++ Application-> app/app
  • Run->Run Configuration->Arguments-> 100
  • right mouse button on "Project-Debug@CMakeTutorial_Build" ->Run As -> Local C/C++ Application

In both cases, on the Console, it generates the output:

The sum of 100 and 100 is 200

Build and Test from the shell

Redefine LD_LIBRARY_PATH

[CMakeTutorial_Build]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/trifoglio/local/CMakeTutorial_Build/bin/

Use make:

[CMakeTutorial_Build]$ make clean
[CMakeTutorial_Build]$ make
[ 33%] Building CXX object math/CMakeFiles/math.dir/simple/SimpleFunctions.cxx.o
[ 66%] Building CXX object math/CMakeFiles/math.dir/advanced/AdvancedFunctions.cxx.o
Linking CXX shared library libmath.so
[ 66%] Built target math
[100%] Building CXX object app/CMakeFiles/app.dir/main.cxx.o
Linking CXX executable app
[100%] Built target app
[CMakeTutorial_Build]$ make install
[ 66%] Built target math
[100%] Built target app
Install the project...
-- Install configuration: "Debug" 
-- Installing: /home/trifoglio/local/CMakeTutorial_Build/bin/app
-- Removed runtime path from "/home/trifoglio/local/CMakeTutorial_Build/bin/app" 
-- Installing: /home/trifoglio/local/CMakeTutorial_Build/bin/libmath.so
[CMakeTutorial_Build]$ make test
Running tests...
Test project /home/trifoglio/local/CMakeTutorial_Build
    Start 1: AppTest1
1/3 Test #1: AppTest1 .........................   Passed    0.00 sec
    Start 2: AppTest2
2/3 Test #2: AppTest2 .........................   Passed    0.00 sec
    Start 3: AppTest3
3/3 Test #3: AppTest3 .........................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 3

Total Test time (real) =   0.01 sec
[CMakeTutorial_Build]$