Skip to content

cpporchard/cmake_project_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Topics Covered

  1. CMake Simple Project Link
  2. CMake + Gtest (via Git Submodule) Link
  3. CMake + Boost Simple + GTest (via Git Submodule) Link*
  4. CMake + Boost Http Server Executable (via Git Submodule) Link*
  5. CMake + Gtest (via FetchContent) Link

'Link*' means popular project template.

Commands

Add Library

Via Git Submodule

Adding New Library - Google Test and Boost

  • Google Test
git submodule add https://github.com/google/googletest.git third_party/googletest
git submodule update --init --recursive
  • Boost

we noticed that we might need to download whole boost library to include just a subset of boost. We cd into boost and do --init --recursive to pull all the submodules inside boost.

git submodule add https://github.com/boostorg/boost.git third_party/boost
cd third_party/boost
git submodule update --init --recursive

Removing Previous Sub Module - Google Test in this case (Optional)

# commit or stash your changes b
git submodule deinit -f third_party/googletest
rm -rf .git/modules/third_party/googletest
rm -rf third_party/googletest

git config --file=.gitmodules --remove-section submodule.third_party/googletest
git config --file=.git/config --remove-section submodule.third_party/googletest
git rm --cached third_party/googletest

rm -rf .git/modules/*
rm -rf third_party
rm -rf .gitmodules

If the code already has the Sub Module -- Fetching the library

Once you clone the codebase, run this.

git submodule update --init --recursive

Now, you will have the third_party/*. Run the regular build.

Via CMake FetchContent

Only changes in CMakeList.txt files. Rest all are the same.

Build

  • Remove Previous Build (You won't make use of incremental build)
rm -rf build
  • Build third_party, src and test.
mkdir build && cd build
cmake ..
make -j$(nproc --all)

Run

Run Unit Test

cd build
./unittest/VectorTest

Run Executable

./build/src/HttpServer
🚀 Starting HTTP server on http://localhost:8080 ...


curl "http://localhost:8080/split?text=hi,there,test&delim=,"
["hi", "there", "test"]

FAQ

If CLion doesn't detect the Project as CMake.

Remove the .idea folder and reopen the CMake Project.

About

CMake, Google Test, Boost Http Server, Git Submodule, CMake FetchContent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published