A template for modern C++ projects using CMake, Clang-Format, CI, unit testing and more, with support for downstream inclusion.

Overview

Actions Status Actions Status Actions Status codecov GitHub release (latest by date)

Modern C++ Template

A quick C++ template for modern CMake projects, aimed to be an easy to use starting point.

This is my personal take on such a type of template, thus I might not use the best practices or you might disagree with how I do things. Any and all feedback is greatly appreciated!

Features

  • Modern CMake configuration and project, which, to the best of my knowledge, uses the best practices,

  • An example of a Clang-Format config, inspired from the base Google model, with minor tweaks. This is aimed only as a starting point, as coding style is a subjective matter, everyone is free to either delete it (for the LLVM default) or supply their own alternative,

  • Static analyzers integration, with Clang-Tidy and Cppcheck, the former being the default option,

  • Doxygen support, through the ENABLE_DOXYGEN option, which you can enable if you wish to use it,

  • Unit testing support, through GoogleTest (with an option to enable GoogleMock) or Catch2,

  • Code coverage, enabled by using the ENABLE_CODE_COVERAGE option, through Codecov CI integration,

  • Package manager support, with Conan and Vcpkg, through their respective options

  • CI workflows for Windows, Linux and MacOS using GitHub Actions, making use of the caching features, to ensure minimum run time,

  • .md templates for: README, Contributing Guideliness, Issues and Pull Requests,

  • Permissive license to allow you to integrate it as easily as possible. The template is licensed under the Unlicense,

  • Options to build as a header-only library or executable, not just a static or shared library.

  • Ccache integration, for speeding up rebuild times

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

This project is meant to be only a template, thus versions of the software used can be change to better suit the needs of the developer(s). If you wish to use the template as-is, meaning using the versions recommended here, then you will need:

  • CMake v3.15+ - found at https://cmake.org/

  • C++ Compiler - needs to support at least the C++17 standard, i.e. MSVC, GCC, Clang

Note: You also need to be able to provide CMake a supported generator.

Installing

It is fairly easy to install the project, all you need to do is clone if from GitHub or generate a new repository from it (also on GitHub).

If you wish to clone the repository, rather than generate from it, you simply need to run:

git clone https://github.com/filipdutescu/modern-cpp-template/

After finishing getting a copy of the project, with any of the methods above, create a new folder in the include/ folder, with the name of your project. Edit cmake/SourcesAndHeaders.cmake to add your files.

You will also need to rename the cmake/ProjectConfig.cmake.in file to start with the exact name of your project. Such as cmake/MyNewProjectConfig.cmake.in. You should also make the same changes in the GitHub workflows provided, notably .github/workflows/ubuntu.yml, in which you should replace the CMake option -DProject_ENABLE_CODE_COVERAGE=1 to -DMyNewProject_ENABLE_CODE_COVERAGE=1.

Finally, change "Project" from CMakeLists.txt, from

project(
  "Project"
  VERSION 0.1.0
  LANGUAGES CXX
)

to the exact name of your project, i.e. using the previous name it will become:

project(
  MyNewProject
  VERSION 0.1.0
  LANGUAGES CXX
)

To install an already built project, you need to run the install target with CMake. For example:

cmake --build build --target install --config Release

# a more general syntax for that command is:
cmake --build <build_directory> --target install --config <desired_config>

Building the project

To build the project, all you need to do, after correctly installing the project, is run a similar CMake routine to the the one below:

mkdir build/ && cd build/
cmake .. -DCMAKE_INSTALL_PREFIX=/absolute/path/to/custom/install/directory
cmake --build . --target install

Note: The custom CMAKE_INSTALL_PREFIX can be omitted if you wish to install in the default install location.

More options that you can set for the project can be found in the cmake/StandardSettings.cmake file. For certain options additional configuration may be needed in their respective *.cmake files (i.e. Conan needs the CONAN_REQUIRES and might need the CONAN_OPTIONS to be setup for it work correctly; the two are set in the cmake/Conan.cmake file).

Generating the documentation

In order to generate documentation for the project, you need to configure the build to use Doxygen. This is easily done, by modifying the workflow shown above as follows:

mkdir build/ && cd build/
cmake .. -D<project_name>_ENABLE_DOXYGEN=1 -DCMAKE_INSTALL_PREFIX=/absolute/path/to/custom/install/directory
cmake --build . --target doxygen-docs

Note: This will generate a docs/ directory in the project's root directory.

Running the tests

By default, the template uses Google Test for unit testing. Unit testing can be disabled in the options, by setting the ENABLE_UNIT_TESTING (from cmake/StandardSettings.cmake) to be false. To run the tests, simply use CTest, from the build directory, passing the desire configuration for which to run tests for. An example of this procedure is:

cd build          # if not in the build directory already
ctest -C Release  # or `ctest -C Debug` or any other configuration you wish to test

# you can also run tests with the `-VV` flag for a more verbose output (i.e.
#GoogleTest output as well)

End to end tests

If applicable, should be presented here.

Coding style tests

If applicable, should be presented here.

Contributing

Please read CONTRIBUTING.md for details on our how you can become a contributor and the process for submitting pull requests to us.

Versioning

This project makes use of SemVer for versioning. A list of existing versions can be found in the project's releases.

Authors

License

This project is licensed under the Unlicense - see the LICENSE file for details

Issues
  • How to run GoogleTest and Static analyzers in local?

    How to run GoogleTest and Static analyzers in local?

    Hello, I'd like to know how to run GTest and cppcheck in my local, not github. Thanks

    bug question acknowledged fixed 
    opened by stoneboy100200 24
  • [BUG] msvc runtime library not setup at all.

    [BUG] msvc runtime library not setup at all.

    Describe the bug cmake build stage failed with the error msg below:

    [main] Building folder: QuicPlus 
    [build] Starting build
    [proc] Executing command: "C:\Program Files\CMake\bin\cmake.exe" --build d:/VS2019/QuicPlus/build --config Debug --target all -j 24 --
    [build] [1/2  50% :: 0.886] Building CXX object test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj
    [build] [2/2 100% :: 1.036] Linking CXX executable test\tmp_test_Tests.exe
    [build] FAILED: test/tmp_test_Tests.exe 
    [build] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=test\CMakeFiles\tmp_test_Tests.dir --rc="D:\Windows Kits\10\bin\10.0.19041.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.19041.0\x86\mt.exe" --manifests  -- "D:\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\link.exe" /nologo test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj  /out:test\tmp_test_Tests.exe /implib:test\tmp_test_Tests.lib /pdb:test\tmp_test_Tests.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  lib\Debug\QuicPlus.lib  D:\vcpkg\installed\x64-windows-static\debug\lib\manual-link\gtest_maind.lib  D:\vcpkg\installed\x64-windows-static\debug\lib\gtestd.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D D:\VS2019\QuicPlus\build\test && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file D:/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary D:/VS2019/QuicPlus/build/test/tmp_test_Tests.exe -installedDir D:/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
    [build] LINK Pass 1: command "D:\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x64\link.exe /nologo test\CMakeFiles\tmp_test_Tests.dir\src\tmp_test.cpp.obj /out:test\tmp_test_Tests.exe /implib:test\tmp_test_Tests.lib /pdb:test\tmp_test_Tests.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console lib\Debug\QuicPlus.lib D:\vcpkg\installed\x64-windows-static\debug\lib\manual-link\gtest_maind.lib D:\vcpkg\installed\x64-windows-static\debug\lib\gtestd.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:test\CMakeFiles\tmp_test_Tests.dir/intermediate.manifest test\CMakeFiles\tmp_test_Tests.dir/manifest.res" failed (exit code 1169) with the following output:
    [build] gtestd.lib(gtest-all.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: struct _Cvtvec __cdecl std::_Locinfo::_Getcvt(void)const " ([email protected][email protected]@@[email protected]@XZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: bool __cdecl std::ios_base::good(void)const " ([email protected][email protected]@@QEBA_NXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __cdecl std::ios_base::flags(void)const " ([email protected][email protected]@@QEBAHXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(void)const " ([email protected][email protected]@@QEBA_JXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(__int64)" ([email protected][email protected]@@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::basic_streambuf<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: virtual __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::~basic_streambuf<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: int __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __int64 __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::eback(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::gptr(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::pbase(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::pptr(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::egptr(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::gbump(int)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setg(char *,char *,char *)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::epptr(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEBAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: void __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::setp(char *,char *,char *)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: char * __cdecl std::basic_streambuf<char,struct std::char_traits<char> >::_Pninc(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@IEAAPEADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: virtual __cdecl std::basic_ios<char,struct std::char_traits<char> >::~basic_ios<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __cdecl std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __cdecl std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: char __cdecl std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " ([email protected][email protected][email protected]@[email protected]@@[email protected]@QEBADXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "protected: __cdecl std::basic_ios<char,struct std::char_traits<char> >::basic_ios<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: void __cdecl std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@QEAAXXZ) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]@Z) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __cdecl std::basic_iostream<char,struct std::char_traits<char> >::basic_iostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@Z) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: virtual __cdecl std::basic_iostream<char,struct std::char_traits<char> >::~basic_iostream<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in gtestd.lib(gtest-all.cc.obj)
    [build] libcpmtd.lib(locale0.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl std::_Facet_Register(class std::_Facet_base *)" ([email protected]@@[email protected]@@Z) already defined in msvcprtd.lib(locale0_implib.obj)
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" ([email protected]@[email protected]@[email protected]@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(bool)" ([email protected]@[email protected]@[email protected]@[email protected]) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" ([email protected][email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Locimp::_New_Locimp(class std::locale::_Locimp const &)" ([email protected][email protected]@[email protected]@[email protected]@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(cout.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(cerr.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(locale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(locale.obj) : error LNK2005: "private: static void __cdecl std::locale::_Locimp::_Locimp_Addfac(class std::locale::_Locimp *,class std::locale::facet *,unsigned __int64)" ([email protected][email protected]@[email protected]@[email protected]@[email protected][email protected]) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(iosptrs.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xlock.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::_Lockit(int)" ([email protected]@@[email protected]@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::~_Lockit(void)" ([email protected]@@[email protected]) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(wlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getdays(void)const " ([email protected][email protected]@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getmonths(void)const " ([email protected][email protected]@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " ([email protected][email protected]@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(wlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " ([email protected][email protected]@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getdays(void)const " ([email protected][email protected]@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: char const * __cdecl std::_Locinfo::_Getmonths(void)const " ([email protected][email protected]@@QEBAPEBDXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " ([email protected][email protected]@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xlocale.obj) : error LNK2005: "public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " ([email protected][email protected]@@QEBAPEBGXZ) already defined in msvcprtd.lib(MSVCP140D.dll)
    [build] libcpmtd.lib(xstol.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xstoul.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xstoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xstoull.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xmtx.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xstrcoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xdateord.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xwcscoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xwcsxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xgetwctype.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xtowlower.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xtowupper.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(xstrxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(StlCompareStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] libcpmtd.lib(StlLCMapStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in tmp_test.cpp.obj
    [build] LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
    [build] test\tmp_test_Tests.exe : fatal error LNK1169: one or more multiply defined symbols found
    [build] ninja: build stopped: subcommand failed.
    [build] Build finished with exit code 1
    

    The problem is casued by the missing of setup of msvc runtime library.

    To Reproduce

    1. Install vcpkg
    2. Install gtest via vcpkg.exe install gtest:x64-windows-static.
    3. Download and install vscode editor.
    4. Install c++ extension pack into the vscode editor.
    5. Git clone modern-cpp-template
    6. Open it from vscode editor
    7. Create a folder .vscode in the root folder and create a settings.json file in .vscode folder with the below content:
    {
      "cmake.configureSettings": {
        // "CMAKE_BUILD_TYPE": "Release", this does not take effetc. so use the vscode gui to control the build type
        "BUILD_SHARED_LIBS": "OFF",
        "VCPKG_TARGET_TRIPLET": "x64-windows-static",
        "CMAKE_TOOLCHAIN_FILE": "D:/vcpkg/scripts/buildsystems/vcpkg.cmake"
      }
    }
    

    Change D:/vcpkg/scripts/buildsystems/vcpkg.cmake to your own path. 7. config and build the project via vscode gui.

    Expected behavior config and build shoudl succeed. and tests shoudl all passed.

    Desktop (please complete the following information):

    • OS: Windows
    • Version 10
    • Editor: vscode

    Additional context I fixed up the issue by adding this line in my fork I am happy to create a PR when the issue is discussed and got alignment with the author.

    bug good first issue acknowledged fixed 
    opened by Kiddinglife 10
  • TODO

    TODO

    To be implemented:

    In progress:

    Done:

    • [x] Code coverage
    • [x] CI cache and GoogleTest build Release only
    • [x] CMake Windows export symbols and visibility preset (through CMakeGenerateExportHeader)
    • [x] GoogleMock integration
    • [x] VCPKG support
    • [x] Conan support
    • [x] Doxygen support
    • [x] Add separate file for sources and headers ro be used, rather than use GLOB_RECURSE)
    • [x] Move options to separate file
    • [x] Static Analyzers (Clang-Tidy & Cppcheck)
    • [x] Remove static only build of library
    enhancement 
    opened by filipdutescu 9
  • [FEATURE] Release workflow for github

    [FEATURE] Release workflow for github

    Is your feature request related to a problem? Please describe. No one should do manual deployments.

    Describe the solution you'd like Create a new tag or push on a release branch to trigger an automated release

    Provide usage examples There are already actions for the different tasks available: https://github.com/actions/create-release https://github.com/actions/upload-release-asset

    And filtering for specific branches and tags can be achieved by:

    on:
      push:
        branches:    
          - master
        tags:        
          - v1
    

    P.S.: Amazing work on the template. Working on a similar approach but using a strategy matrix https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix

    enhancement good first issue acknowledged implemented 
    opened by thebino 8
  • vs2022 build failure

    vs2022 build failure

    Hello, I am a newbie to cmake, I tried to clone the project and use vs2022 preview to generate it, but I got the error that gtest could not be found, I did not change any code.Do I need to manually download gtest and link to it somewhere.

    The system is: Windows - 10.0.19043 - AMD64
    Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
    Compiler: C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.30.30423/bin/Hostx64/x64/cl.exe 
    Build flags: 
    Id flags:  
    
    1> [CMake] -- Build unit tests for the project. Tests should always be found in the test folder
    1> [CMake] 
    1> [CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
    1> [CMake]   Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR
    1> [CMake]   GTEST_MAIN_LIBRARY)
    1> [CMake] Call Stack (most recent call first):
    1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
    1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.20/Modules/FindGTest.cmake:255 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
    1> [CMake]   test/CMakeLists.txt:46 (find_package)
    1> [CMake] -- Configuring incomplete, errors occurred!
    
    question acknowledged 
    opened by alazysun 6
  • How to make compilation warnings not work for third party libraries?

    How to make compilation warnings not work for third party libraries?

    Threr are many third party libraries in my project, I just let compilation warnings to work for my code´╝înot work for third party libraries. Could you please tell me what should I do?

    enhancement acknowledged fixed 
    opened by stoneboy100200 6
  • [FEATURE] Control which changes trigger github actions

    [FEATURE] Control which changes trigger github actions

    Is your feature request related to a problem? Please describe. Typo fixes in one of the *.md files will rerun the entire CI pipeline. Depending on how long the pipeline takes to run, this may become an issue.

    Describe the solution you'd like Control what triggers the CI pipeline via config.

    Describe alternatives you've considered Github actions doesn't seem to support skipping via a keyword in the commit message, so not sure there is an alternative.

    Provide usage examples See documentation link above

    Additional context I would create a PR, but I don't know if you want to implement a whilelist or a blacklist.

    enhancement good first issue acknowledged implemented 
    opened by php1ic 5
  • Remove redundant newline ('\n') characters on end the message.

    Remove redundant newline ('\n') characters on end the message.

    The message() command of the CMake inserts newline on the end of its argument.

    enhancement wontfix acknowledged 
    opened by ghost 4
  • [BUG] cmake fails when Project_BUILD_EXECUTABLE is true

    [BUG] cmake fails when Project_BUILD_EXECUTABLE is true

    Describe the bug If I try to build executable by setting -DProject_BUILD_EXECUTABLE=On, the cmake step fails with

    CMake Error at test/CMakeLists.txt:51 (target_link_libraries):
      Target "Project" of type EXECUTABLE may not be linked into another target.
      One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
      executables with the ENABLE_EXPORTS property set.
    

    To Reproduce Steps to reproduce the behavior:

    1. Clone project
    2. mkdir build && cd build
    3. cmake .. -DProject_BUILD_EXECUTABLE=On
    4. See error

    Expected behavior I'm just trying to build a simple executable, not a library

    Desktop (please complete the following information):

    • OS: Linux.
    • Version: Running inside custom Docker container based on ubuntu 20

    cmake --version cmake version 3.16.3

    Additional context Coming back to C++ after forever away, just learning about the build tooling etc, so it could be a basic mistake on my end. Just want to build an executable program not a library. I failed after tweaking things for my project, and then got the same failure in the vanilla template project with no tweaks.

    bug help wanted good first issue acknowledged fixed 
    opened by jmarca 4
  • [FEATURE] Use pip to install CMake in Dockerfile

    [FEATURE] Use pip to install CMake in Dockerfile

    Is your feature request related to a problem? Please describe. This is not really a problem, but you may not have to manually install cmake from source in the Dockerfile

    Describe the solution you'd like You can install cmake via pip

    Describe alternatives you've considered N/A

    Provide usage examples e.g. pip3 install cmake

    Additional context https://cmake-python-distributions.readthedocs.io/en/latest/index.html

    enhancement good first issue wontfix acknowledged 
    opened by arecarn 3
Releases(v3.1.0)
Owner
Filip Dutescu
Filip Dutescu
A template CMake project to get you started with C++ and tooling

cpp_starter_project Getting Started Use the Github template First, click the green Use this template button near the top of this page. This will take

Jason Turner 1.4k Sep 13, 2021
Type-safe zero-boilerplate interfaces for pure C99, implemented as a single-header library.

Interface99 Type-safe zero-boilerplate interfaces for pure C99, implemented as a single-header library. [ examples/state.c ] #include <interface99.h>

null 77 Sep 11, 2021
Starter project for cross platform WebGPU development in C++

A starter code for cross-platform (i.e., web & native) C++ WebGPU projects.

Will Usher 25 Sep 8, 2021
Pitchfork is a Set of C++ Project Conventions

Pitchfork Pitchfork is a set of conventions for native C and C++ projects. The most prominent being the project layout conventions. The layout specifi

null 550 Sep 12, 2021