将Make转换为CMakeLists项目

时间:2019-01-15 14:58:09

标签: c++ makefile cmake

我正在尝试将包含.cpp和.h文件的SDK添加到我的CMakelists.txt项目中(我正在使用CLion)。该SDK是Spinnaker(https://www.ptgrey.com/support/downloads)。

当我下载SDK时,它由一系列* .deb文件组成。安装脚本运行

sudo dpkg -i <some_file_name>.deb

deb文件位于/home/username/Documents/spinnaker/

在此安装中,一堆.h文件放置在/usr/include/spinnaker/中,而libSpinnaker.so文件放置在/usr/lib/libSpinnaker.so

我试图弄清楚如何将此SDK添加到CMakeLists.txt项目。我已经尝试过include_directories(/usr/include/spinnaker)  但是我得到undefined reference to Spinnaker::System::GetInstance()',这告诉我我没有正确链接。

他们确实提供了一些带有Make文件的用户示例,但是Make文件对我来说比CMakelist更陌生。这是完整的Make文件,以 Acquisition。* 为例。 Make文件项目正确构建(在Acquisition示例文件夹中运行$ make

PROJECT_ROOT=../../
OPT_INC = ${PROJECT_ROOT}/common/make/common_spin.mk
-include ${OPT_INC}

ifeq ($(wildcard ${OPT_INC}),)
CFLAGS += -std=c++
CXX = g++ ${CFLAGS}
ODIR  = .obj/build${D}
SDIR  = .
MKDIR = mkdir -p
PLATFORM = $(shell uname)
ifeq ($(PLATFORM),Darwin)
OS = mac
endif
endif

OUTPUTNAME = Acquisition${D}
OUTDIR = ../../bin

SPINNAKER_LIB = -L../../lib -lSpinnaker${D} ${SPIN_DEPS}

_OBJ = Acquisition.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
INC = -I../../include -I/usr/include/spinnaker
ifneq ($(OS),mac)
LIB += -Wl,-Bdynamic ${SPINNAKER_LIB}
LIB += -Wl,-rpath-link=../../lib 
else
LIB += -rpath ../../lib/
LIB += ${SPINNAKER_LIB}
endif

${OUTPUTNAME}: ${OBJ}
${CXX} -o ${OUTPUTNAME} ${OBJ} ${LIB}
mv ${OUTPUTNAME} ${OUTDIR}

${OBJ}: ${ODIR}/%.o : ${SDIR}/%.cpp
@${MKDIR} ${ODIR}
${CXX} ${CFLAGS} ${INC} -Wall -D LINUX -c $< -o $@

clean_obj:
rm -f ${OBJ}
@echo "intermediate objects cleaned up!"

clean: clean_obj
rm -f ${OUTDIR}/${OUTPUTNAME}
@echo "all cleaned up!"

0 个答案:

没有答案