Build system 与KDE
上一篇已经介绍到直接采用make就可以编译OpenNI2,这篇文章主要介绍下OpenNI2的makefile文件以及Linux下KDE集成开发环境的使用;
.
├── Makefile
├── Samples
│ ├── SimpleRead
│ │ └── Makefile
│ └── SimpleViewer
│ … └── Makefile
├── Source
│ ├── Core
│ │ └── Makefile
│ └── Drivers
│ … ├── DummyDevice
│ … │ └── Makefile
│ … ├── Kinect
│ … ├── OniFile
│ … │ └── Makefile
│ … ├── PS1080
│ … │ └── Makefile
│ … └── PSLink
│ … … └── Makefile
└── ThirdParty
… └── PSCommon
… ├── BuildSystem
… … ├── CommonCppMakefile
… … ├── CommonCSMakefile
… … ├── CommonDefs.mak
… … ├── CommonJavaMakefile
… … ├── CommonTargets.mak
… … ├── Platform.Arm
… … ├── Platform.x64
… … └── Platform.x86
顶层Makefile用于编译整个工程暂时先不去分析,我们先看下Sample目录下的Makefile
# SimpleViewer Makefile
include ../../ThirdParty/PSCommon/BuildSystem/CommonDefs.mak
BIN_DIR = ../../Bin
INC_DIRS = \
../../Include \
../../ThirdParty/GL/ \
../Common
SRC_FILES = *.cpp
ifeq ("$(OSTYPE)","Darwin")
CFLAGS += -DMACOS
LDFLAGS += -framework OpenGL -framework GLUT
else
CFLAGS += -DUNIX -DGLX_GLXEXT_LEGACY
USED_LIBS += glut GL
endif
USED_LIBS += OpenNI2
EXE_NAME = SimpleViewer
CFLAGS += -Wall
include ../../ThirdParty/PSCommon/BuildSystem/CommonCppMakefile
上面的各个变量都显而易见
- INC_DIRS 为头件目录
- SRC_FILES为源文件
- USED_LIBS为编译时需要链接的库
- EXE_NAME为生成可执行文件的名称
该文件主要定义EXE_NAME来表示该文件用于生成可执行文件,下面我们来看看CommonDefs.mak与CommonCppMakefile
# CommonDefs.mak
ifndef _COMMON_DEFS_MAKE_
_COMMON_DEFS_MAKE_=1
# some defaults
ifndef CFG
CFG = Release
endif
# find out the platform on which we're running
MACHINE = $(shell uname -m)
ifneq (,$(findstring x86_64,$(MACHINE)))
HOST_PLATFORM = x64
else ifneq (,$(findstring x86,$(MACHINE)))
HOST_PLATFORM = x86
else ifneq (,$(findstring i686,$(MACHINE)))
HOST_PLATFORM = x86
else ifneq (,$(findstring i386,$(MACHINE)))
HOST_PLATFORM = x86
else ifneq (,$(findstring arm,$(MACHINE)))
HOST_PLATFORM = Arm
else
DUMMY:=$(error Can't determine host platform)
endif
# now check if this is a cross-compilation or not
ifeq "$(PLATFORM)" ""
PLATFORM = $(HOST_PLATFORM)
else
ifneq "$(PLATFORM)" "$(HOST_PLATFORM)"
# cross compiling. Take CXX and STAGING_DIR from environment
PLATFORM_UPPER = $(shell echo $(PLATFORM) | tr 'a-z' 'A-Z')
DUMMY:=$(eval CXX = $($(PLATFORM_UPPER)_CXX))
DUMMY:=$(eval TARGET_SYS_ROOT = $($(PLATFORM_UPPER)_STAGING))
ifeq "$(and $(CXX), $(TARGET_SYS_ROOT))" ""
DUMMY:=$(error Cross-Compilation error. Can't find $(PLATFORM_UPPER)_CXX and $(PLATFORM_UPPER)_STAGING)
endif
endif
endif
# expand file list
SRC_FILES_LIST = $(wildcard $(SRC_FILES))
# define the intermediate directory
INT_DIR = $(BIN_DIR)/Intermediate/$(PLATFORM)-$(CFG)/$(OUTPUT_NAME)
# define output directory
OUT_DIR = $(BIN_DIR)/$(PLATFORM)-$(CFG)
# full path to output file
OUTPUT_FILE = $(OUT_DIR)/$(OUTPUT_NAME)
# take this file's dir
COMMON_MAK_DIR = $(dir $(lastword $(MAKEFILE_LIST)))
# get the OS type
OSTYPE := $(shell uname -s)
# platform specific args
include $(COMMON_MAK_DIR)Platform.$(PLATFORM)
endif # _COMMON_DEFS_MAKE_
# CommonCppMakefile
#############################################################################
# Primesense template makefile.
# This file should not be made, but only included from other makefiles.
# By default, this makefile compiles in release. To compile a debug version:
# make CFG=Debug
#
# Project makefile should define the following BEFORE including this file:
# SRC_FILES - a list of all source files
# Output name under one of the following:
# EXE_NAME (executable),
# LIB_NAME (dynamic library) or
# SLIB_NAME (static library) or
# BIN_DIR - Bin directory (output dir)
# INC_DIRS - a list of additional include directories
# LIB_DIRS - a list