Skip to content

Some CMake templates for building C/C++ projects quickly

Notifications You must be signed in to change notification settings

henryzhuhr/CMake-Templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMake-Templates

English | 简体中文

CMake is good

Compile the project

  • build && compile
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make -j8
  • run the executable file
cd ../bin
./<your_program>

Directory Structure

.
├─app               # test file
├─bin               # binary output
├─build             # cmake build and make output
├─include           # head file
|   ├─LinkedList.hpp
|   └─...
├─src               # source file
├─tools             # compile tools chain
├─.clang-format     # clang-format custom file
├─build.ps1         # build script in powershell
├─build.sh          # build script in bash
├─CMakeLists.txt    # CMake configuration
└─README.md

CMake

global configuration

compile executable file

see directory exe for detail that how to compile an executable file

compile dynamic link library

see directory dynamic-library for details that how to compile dynamic link library

compile static link library

see directory static-library for detail that how to compile static link library

build some useful 3rd-party

gflags

download gflags in GitHub, see "Installing a binary distribution package"

Opencv

Download the same version of opencv and opencv_contrib in Releases orMirrors

Compile from source:

In Windows cmd:

cd opencv-4.5.2

md build

md build\3rdparty\ffmpeg
copy ..\download\*.cmake build\3rdparty\ffmpeg\
copy ..\download\*.dll  build\3rdparty\ffmpeg\

md build\downloads\wechat_qrcode
copy ..\download\*.caffemodel   build\downloads\wechat_qrcode
copy ..\download\*.prototxt     build\downloads\wechat_qrcode

md build\downloads\xfeatures2d\
copy ..\download\*.i build\downloads\xfeatures2d\

md build\testdata\cv\face\
copy ..\download\face_landmark_model.dat build\testdata\cv\face\

cd build

cmake .. ^
    -G "MinGW Makefiles" ^
    -D CMAKE_INSTALL_PREFIX=C:/Users/Henryzhu/Programs/opencv ^
    -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.2/modules ^
    -D CMAKE_BUILD_TYPE=Release ^
    -DBUILD_opencv_python2=OFF ^
    -DBUILD_opencv_python3=OFF ^
    -D OPENCV_GENERATE_PKGCONFIG=ON ^
    -D BUILD_SHARED_LIBS=OFF^
    -D WITH_CUDA=ON ^
    -D OPENCV_DNN_CUDA=ON ^
    -D WITH_ONNX=ON ^
    -D WITH_1394=OFF
make -j8
make install

Some file must be downloaded for OpenCV compiled. After cmake command, see build/CMakeDownloadLog.txt to get the files need to be downloaded, then download and put them to the corresponded folder:

Clang-Format

Download

In LLVM official website, choose corresponding Clang-Format Release for your OS in Other builds.

Then, you can download LLVM in this page or in Github Release

when installing LLVM, in page Install Options, select if add LLVM to the system

  • Do not add LLVM to the system PATH
  • Add LLVM to the system PATH for all user
  • Add LLVM to the system PATH for current user

Usage

use clang-format with parameter -style and -i

  • -style LLVM、Google、Chromium、Mozilla、WebKit or file(.clang-format)
  • -i
clang-format -style=LLVM -i test.c

or you can edit your custom format file .clang-format,

clang-format -i test.c

see Clang documentation for more detail of using Clang-Format

git

in file .git/config

[remote "origin"]
	url = https://gitee.com/<user_name>/<repo_name>.git
	url = https://github.com/<user_name>/<repo_name>.git
	fetch = +refs/heads/*:refs/remotes/origin/*

Wget

A command-line utility for retrieving files using HTTP, HTTPS and FTP protocols.

Download:

About

Some CMake templates for building C/C++ projects quickly

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published