一个典型的cmakelists.txt
目录结构:
TestBin/third/ffmpeg/
TestBin/src/photo/photo.cpp
TestBin/src/record/record.cpp
在编译时设定机型, 以便在代码中使用编译宏区分不同的功能等.
# mkdir build
# cd build
# cmake .. -DBIN_TARGET=target1
# make -jcmake_minimum_required(VERSION 3.16.3)set (CMAKE_SYSTEM_NAME Linux)
set (CMAKE_CROSSCOMPILING TRUE)set (CMAKE_C_COMPILER gcc)
set (CMAKE_CXX_COMPILER g++)project(TestBin)set(CMAKE_CXX_FLAGS "-std=c++17 -O2 -g -rdynamic -Wall")#预定义机型,全局宏,代码中无需再定义.
add_definitions(-DTARGET_TYPE_1=0x1)
add_definitions(-DTARGET_TYPE_2=0x2)#当前编译的机型
if (${BIN_TARGET} STREQUAL "target1")
add_definitions(-DTARGET_TYPE=0x1)
else()
add_definitions(-DTARGET_TYPE=0x2)
endif()#子目录的库输出目