#*************** CMakeLists.txt *********************
# CMake 最低版本号要求
cmake_minimum_required(VERSION 3.16)
# arm嵌入式c,编译器使用这个
set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc")
# arm嵌入式c++,编译器使用这个
set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
# This project requires C++11.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# 自定义编译选项, 可以在cmakelist文件接下来的部分使用
# 与set 的区别, set有更丰富的 使用方法, 而option只能定义 ON 或者 OFF
option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)
option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)
option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
# 设置工程名、版本等信息
project (CANopen_Linux VERSION 1.22.0 LANGUAGES C CXX)
# 编译命令后缀 因为使用了线程,需要添加-lpthread
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lpthread")
# c++使用这个
set(CMAKE_CXX_FLAGS -lpthread)
# 包含头文件目录
include_directories (main CANopen/inc CANopen/inc/linux )
include_directories (CANopen/dictionary CANopen/hardware)
# 添加源代码目录
aux_source_directory(${PROJECT_SOURCE_DIR}/CANopen/src CANOPEN_SRC) #添加canopen源代码目录
aux_source_directory(${PROJECT_SOURCE_DIR}/CANopen/hardware CANOPEN_HARDWARE) #添加硬件源代码目录
aux_source_directory(${PROJECT_SOURCE_DIR}/CANopen/dictionary CANOPEN_DICTIONARY) #添加词典源代码目录
aux_source_directory(${PROJECT_SOURCE_DIR}/main MAIN_SRCS) #添加main程序入口代码目录
# 指定生成目标canopen_exe
add_executable(canopen_exe ${MAIN_SRCS} ${CANOPEN_HARDWARE} ${CANOPEN_SRC} ${CANOPEN_DICTIONARY})
标签:CMakeLists,set,CMAKE,CXX,CANopen,精讲,CANOPEN,CMake,源代码 From: https://www.cnblogs.com/suntroop/p/16944065.html