Status | |
---|---|
Travis | |
AppVeyor | |
Coverage |
C++ CMake based project template
An example project which can be used as starting point for C++ projects using cmake. It includes:
- A Dummy [google test] (http://code.google.com/p/googletest/) unit test
- A Dummy BDD Style (Gherkin) feature test using Cucumber and [Cucumber-cpp] (https://github.com/cucumber/cucumber-cpp)
- A Dummy BDD Style (Context/Specification) component test using [CppSpec] (https://github.com/tpuronen/cppspec)
- A Dummy BDD Style test using [Igloo] (http://igloo-testing.org/) testing framework
- A Dummy BDD Style test using [Catch] (https://github.com/philsquared/Catch) testing framework
- SonarQube project file
- CMake targets to build, run tests and measure metrics.
Building the Project requires
- a recent Version of CMake (3.2.x). See CMake documentation for more information about building using CMake.
- a recent C++ compiler supporting C++11 (tested on gcc 4.8, 4.9, clang 3.5, 3.6, Visual Studio 2013 & 2015 and MinGW 4.9)
The external dependencies can be downloaded and built by building the external_dependencies target.
Linux You can use cmake to configure and build. Just make sure to build the external dependencies first. E.g.
- mkdir build && (cd build && cmake ..)
- cmake --build build --target external_dependencies --config Debug
- cmake --build build --target all --config Debug
Windows You can use cmake to configure and build, you can also run the build.bat script to build the project and run the tests or run create_windows_installer.bat to create the installer exe.
Usage:
- build.bat [VS2013|VS2015] [--cmake_path <path_to_cmake>] [--config [Debug|Release]]
- create_windows_installer.bat [VS2013|VS2015] [--cmake_path <path_to_cmake>] [--config [Debug|Release]]
CMake with MinGW With CMake version 3.2 you get the following error when running for MinGW
CMake Error at ... (target_compile_features):
target_compile_features no known features for CXX compiler
Updating CMake to version 3.3 will fix this error.
Boost and MinGW
There is bug in boost and building with MinGW will fail first. In order to build boost with MinGW a script executed when building boost modifies the generated project-config.jam (in the boost build folder) by replacing all occurrence of mingw with gcc, i.e. the script replaces
if ! mingw in [ feature.values <toolset> ]
{
using mingw ;
}
project : default-build <toolset>mingw ;
with
if ! gcc in [ feature.values <toolset> ]
{
using gcc ;
}
project : default-build <toolset>gcc ;
Compile Error duplicate section When you build with MinGW you may have compile errors similar to the following:
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt11logic_errorEEEE]' has different size
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt11logic_errorEE]' has different size
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
C:/Work/Cpp_project_template/externals/lib/libboost_regex-mt-d.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
I don't know a solution to this problem, it seems to be a compiler bug see stackoverflow thread
A cmake targets exists for each test framework to run the tests. And additionally the CTest target contains all tests from all unittests frameworks included.
A cmake target exists to run the feature tests (run_feature_test). For more details on how to run cucumber feature tests see the Cucumber-cpp documentation.
In order to generate the code metrics and use sonar for publishing the metrics, sonar-runner, [cppcheck] (http://cppcheck.sourceforge.net/), [valgrind] (http://valgrind.org/) and [Rough Auditing Tool for Security (RATS)] (http://code.google.com/p/rough-auditing-tool-for-security/) are needed. On the sonar server the C++ Community Plugin should be installed.