Boost.Test and CMake


 
Thread Tools Search this Thread
Top Forums Programming Boost.Test and CMake
# 1  
Old 06-07-2012
Boost.Test and CMake

Hi,
I just started using CMake and the Boost Libraries. In this progress I encountered some problems.
One of these problems is combining Boost unit tests with cmake. I don't know how to set the whole project up. I tried to set up a simple test project. This contains a main.cpp a comp.cpp and the comp.h
The main.cpp isn't doing anything at the moment. Comp contains a class:
Code:
class Comp
{
int add(int a, int b);
int sub(int a, int b);
}

Well the content of the cpp should be obvious I hope.
Additional I wrote the runner.cpp:
Code:
#define BOOST_TEST_MODULE "C++ Unit Tests for Calculator"
#include <boost/test/unit_test.hpp>
#include "Comp_Test.h"

and the Comp_Test.h:
Code:
#include <boost/test/unit_test.hpp>
#include"inc/Comp.h"
BOOST_AUTO_TEST_SUITE(adder_test_suite);
BOOST_AUTO_TEST_CASE(add_test_case)
{
        Adder adder;
        BOOST_REQUIRE_EQUAL(adder.add(10,5),15);
}
BOOST_AUTO_TEST_SUITE_END();

The folder structure is as followed:
main
|prog
| |inc
| | |Comp.h
| |main.cpp
| |Comp.cpp
| |CMakelists.txt[1]
|test
| |inc
| | |Comp_Test.h
| |runner.cpp
| |CMakelists.txt[2]

CMakelists.txt[1] should set up the makefile for the project itself and has following content:
Code:
cmake_minimum_required(VERSION 2.6)
project(comp)

ENABLE_TESTING()

include_directories(inc)

add_executable(prog
        main.cpp
        Comp.cpp
)
ADD_TEST(test1 TEST_BINARY_DIRECTORY comp_test)

and the second CMakelists.txt contains:
Code:
cmake_minimum_required(VERSION 2.6)
project(Test)
find_package(Boost REQUIRED unit_test_framework)

include_directories(inc)

include_directories(../prog)

include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})

add_executable(test
        runner.cpp)

target_link_libraries(
        test
        ${Boost_LIBRARIES}
)

So far am I. I think this contains some errors.
Some questions I couldn't answer myself:
1. Is it even possible to separate this in 2 projects like I tried?
2. If I don't separate it what happens to the testcode when I don't want to test? I hope it will only be executed if I execute "make test".

Well, sorry for the long code I hope somebody can help me. Thank you in advance for everybody who has taken the effort to read till the end. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem to download cmake extra modules v 1.7

Hello. I am currently trying to compile kde-baseapps. I issue this command: which returns So I need this ECM stuff. I found this: extra-cmake-modules.git - Extra modules and scripts for CMake.. When I click in the corresponding link in the column, I receive this: This also happens... (2 Replies)
Discussion started by: colt
2 Replies

2. Programming

Boost library path for cmake & make

I was compiling a downloaded open source pkg. Following the install instruction, I did $ mkdir build; cd build; cmake ../; make but got error message:make: *** No rule to make target 'usr/lib64/lib64/libboost_graph-mt.so.5'. needed by ../bin.gam-create. stop make: *** Error 2 make: *** Error... (1 Reply)
Discussion started by: yifangt
1 Replies

3. Programming

cmake and boost library installation problem

hi all, I am new to linux and C++ programming so I'm posting in hope of some help. I am trying to install a C++ library using boost and cmake but I keep gettin this error in the terminal: CMake Error at /usr/share/cmake/Modules/FindBoost.cmake:1199 (message): Unable to find the... (9 Replies)
Discussion started by: peter_071
9 Replies

4. Solaris

cmake installation problem

hi guys.. i installed cmake in solaris 5.10..... x86 i checked pkginfo | grep -i cmake ... it installed but when excuted cmake it showing following error in output bash-3.00# cmake ld.so.1: cmake: fatal: liblzma.so.5: open failed: No such file or directory help me anyone before... (3 Replies)
Discussion started by: coolboys
3 Replies

5. Solaris

boost thread not accessible to boost::move error

Hi All I am working unders Sun Solaris and I am not "/opt/boost/boost/thread/detail/thread.hpp", line 344: Error: boost::thread::thread(boost::thread&) is not accessible from boost::move(boost::detail::thread_move_t<boost::thread>). Do you know if there are other solutions other than... (2 Replies)
Discussion started by: manustone
2 Replies

6. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

7. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies
Login or Register to Ask a Question