Skip to content

C++, cmake, cpm, opeani code review, googletest example

Notifications You must be signed in to change notification settings

ChaoticRoman/cmake-hello

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake Hello

For starting a new project, see ModernCppStarter repo from original author of CPM.

Testing how to set up cmake for project with following structure:

.
├── CMakeLists.txt
├── include
│   ├── low
│   │   └── low.h
│   └── mid
│       └── mid.h
├── Makefile
├── README.md
├── src
│   ├── low
│   │   └── low.cpp
│   ├── main.cpp
│   └── mid
│       └── mid.cpp
└── tests
    ├── CMakeLists.txt
    └── low
        └── test_low.cpp

and following dependencies (A -> B means A depends on B):

main -> mid -> low

Check commits one-by-one as they:

  • start with not using CMake at all and building the thing using plain g++,
  • use the simplest CMake
  • hide the growing complexity to Makefile
  • adds configure, build and test to GitHub pipeline.
  • use hierarchical CMake files
  • add unit tests
  • adds AI based code review
  1. Use external dependencies
  2. Use CPM

TODO

  1. Linting

No build system

Without any build system help we are getting nasty g++ invocation like this:

mkdir build
g++ -I include -o build/hello src/main.cpp src/mid/mid.cpp src/low/low.cpp

You can run your program using

./build/hello

It works, but it is not nice and for more complicated project this would get much more ugly.

Using CMake

All configuration is set in the CMakeLists.txt file.

Configure is required when modifying configuration, adding, renaming or moving files, or when inter-files dependencies are changed and for the first run of coure. It is done for make build system by

cmake -S . -B build/

or e.g. to use ninja

cmake -S . -B build/ -G Ninja

The build itself then goes with:

cmake --build build/

You can run your program using

./build/hello

Hiding the complexity

It started to get bit ugly in previous section so we added helper Makefile to run previous commands. Now you can just use make run

Debugging cmake projects with VS code

This guide describes how to get debugger working. It is surprisingly neat, only thing to be aware of is that it does not binds to built-in Debug/Run (F5/Ctrl+F5) functionality but uses bottom bar buttons.

References

About

C++, cmake, cpm, opeani code review, googletest example

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages