.
├── CMakeLists.txt
├── app
│ └── main.cpp
├── include
│ ├── example.h
│ └── exampleConfig.h.in
├── src
│ └── example.cpp
└── tests
├── dummy.cpp
└── main.cpp
Sources go in src/, header files in include/, main programs in app/, and
tests go in tests/ (compiled to unit_tests
by default).
If you add a new executable, say app/hello.cpp
, you only need to add the following two lines to CMakeLists.txt:
add_executable(main app/main.cpp) # Name of exec. and location of file.
target_link_libraries(main PRIVATE ${LIBRARY_NAME}) # Link the executable to lib built from src/*.cpp (if it uses it).
You can find the example source code that builds the main
executable in app/main.cpp under the Build
section in CMakeLists.txt.
If the executable you made does not use the library in src/, then only the first line is needed.
Clone this repo with:
> git clone --recurse-submodules https://github.com/karlosos/vector_quantization
or fetch submodules manually.
Build by making a build directory (i.e. build/
), run cmake
in that dir, and then use make
to build the desired target.
Example:
> mkdir build && cd build
> cmake .. -DCMAKE_BUILD_TYPE=[Debug | Coverage | Release]
> make
> ./main
> make test # Makes and runs the tests.
> make coverage # Generate a coverage report.
> make doc # Generate html documentation.
I suggest using WSL https://docs.microsoft.com/en-us/windows/wsl/install-win10.
- Open project folder in
cmd.exe
or terminal of your choice. - Launch wsl with
bash
. - Update repositories
sudo apt-get update
. - Install CMake with
sudo apt-get install cmake
. - Install development tools with
sudo apt-get install build-essential
Then within the same terminal (on wsl) build project:
> mkdir build && cd build
> cmake ..
> make
> ./main
It's working. Great success! You can now work with code however you want. Below its described way of configuring VSCode.
Now open VSCode and install following extensions:
- Remote Development
- C++ Extension Pack
- CMake Tools
Close VSCode and launch it from wsl terminal in root folder of our project
cd .. # you should be in vector_quantization folder
code .
You will be asked by CMake Tools extension to configure project. Select compiler and you're good to go.
Debug application with F5
or run without debugging with CTRL+F5
.
If you have error could not find a.out then go to Run->Open Configuration
and check executable path to "program": "${workspaceFolder}/build/main"
.
Install CMAKE and then:
- In root folder run
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Debug
- Then build with:
cmake -build build
. - Go to build dir with
dir build
. - Run program with
.\Debug\main.exe
. - Run tests with
ctest -C Debug
.
- Install CMake
- Build project
> mkdir build && cd build
> cmake ..
> make
> ./main
- Install C++ and CMake Tools extension in VSCode and close it.
- Open VSCode from root folder
vector_quantization
. CMake Tools should ask you to chose compiler. - Debug application with
F5
or run withCTRL+F5
.
Refer to google cppguide.
Install Live Share extension for VSCode..
- https://isocpp.org/wiki/faq/exceptions#what-to-throw - good documentation for C++
- https://github.com/onqtam/doctest/blob/master/doc/markdown/assertions.md#exceptions - doctest features