I am trying to compile a small project that uses a library (a header file and a .so file) for reading in images from a camera (on a RPI). The vendor (Arducam) provided a makefile example file, but not a CMake example file. The project is composed of:
test.cpp
(main file),
arducam_mipicamera.h
, and
libarducam_mipicamera.so
.
The makefile that compiles the project successfully is:
CROSS_PREFIX ?=
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
CFLAGS ?= -I. -g -O0 -std=gnu11
OPENCV_LIB = $(shell pkg-config --cflags --libs opencv)
ifeq ($(OPENCV_LIB), )
OPENCV_LIB = $(shell pkg-config --cflags --libs opencv4)
endif
CXXFLAGS?= -I. -g -std=gnu++11 ${OPENCV_LIB}
LDFLAGS ?=
LIBS := -larducam_mipicamera -lpthread
OLIB := lib
examples:= test
all: $(examples)
test : test.cpp
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
clean:
-rm -f *.o
-rm -f $(examples)
.PHONY: install
install:
sudo install -m 644 $(OLIB)/libarducam_mipicamera.so /usr/lib/
And the CMakefile I have so far is:
cmake_minimum_required(VERSION 3.11)
project( DisplayImage )
set(CMAKE_CXX_STANDARD 11)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage test.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
I am confused on how to add the arducam library to the CMakefile. The header file is in the same directory as the main file and the .so file is in a subdirectory under.
How do I go about adding this simple library to the CMakefile, so that it compiles successfully (like the makefile)? This is not meant to be a dumb question, I just finished reading the CMake documentation. I am just confused about how to go about adding this library to the CMakefile. Does it involve using calls like link_directories()
and target_link_libraries()
?