CMake & make
Keys:
Reference:
- CMakeList.txt檔負責分配source code彼此間的關係。
- Include directory
- Files path (source, output)
- Set library and executable (connection)
- Install setting (在 linux 底下預設的 CMAKE_INSTALL_PREFIX = /usr/local)
- 執行指令cmake後會產生Makefile檔(組態檔),再輸入make指令compile後,若compile無誤,make install指令將自動安裝CMakeList.txt設定好的東西(install rules)。
Makefile example:
# General parameters
CC := g++
EXE := main
# Advanced parameters
INC_DIR := -I../include -I/usr/include -I/usr/include/m3api -I/usr/include/eigen3/Eigen -I/usr/include/opencv -I/usr/include/opencv2 -I/usr/local/cuda-10.0/include `pkg-config --cflags opencv`
CPPSOURCES += $(wildcard *.cpp) #Get all .c files
OBJECTS := $(CPPSOURCES:.cpp=.o) #Replace all .cpp files as .o files
CFLAGS = -c -Wall -g $(INC_DIR)
LIBS = -L/usr/lib -lm3api -lvisionworks -lvisionworks_sfm -lvisionworks_tracking `pkg-config --libs opencv`
DEBUG_DIR := ../Debug
EXE_DIR := ../Debug/
all: $(EXE)
mkdir -p $(DEBUG_DIR)
cp $(EXE) $(DEBUG_DIR)
cd $(EXE_DIR)
./$(EXE)
$(EXE): $(OBJECTS)
$(CC) $(OBJECTS) -o $@ $(LIBS)
.cpp.o:
$(CC) $(CFLAGS) -std=c++14 $(INC_DIR) $< -o $@
clean:
@echo $Delete target = $(OBJECTS) $(EXE)
rm -rf $(OBJECTS) $(EXE)
- CMake 簡單入門
- 2017/5/29, 2017/8/1筆記
- http://mropengate.blogspot.com/2018/01/makefile.html
留言
張貼留言