目录结构示例
image.png
工程化-proj root dir
cmake_minimum_required(VERSION 2.8.3)
################proj:############################
#input:
#set proj and compenents
#set proj_args
get_filename_component(projname ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" projname ${projname})
project(${projname})
#project(driver_example)
message(STATUS "PROJECT_NAME is ${PROJECT_NAME}")
#set compenents modules args
#MODULE_1
set(MODULE_1_DIR compenents/Lidar_r2000)
add_subdirectory(${MODULE_1_DIR})
include_directories(
${MODULE_1_DIR}/include
)
#set Release arg
IF(NOT CMAKE_BUILD_TYPE)
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
#set(CMAKE_BUILD_TYPE RelWithDebInfo)
ENDIF(NOT CMAKE_BUILD_TYPE)
#set env:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x -Wfatal-errors")
SET(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
#find lib:
#set include_dir:
#set src_set:
AUX_SOURCE_DIRECTORY(. SRC_SET_${MODULE_NAME}) #add src by dir
#set(SRC_SET_${MODULE_NAME} driver_example.cpp ) #add src file by name
message(STATUS "SRC_SET_${MODULE_NAME} is ${SRC_SET_${MODULE_NAME}}")
#######################################################
#output:
add_executable(${PROJECT_NAME} ${SRC_SET_${MODULE_NAME}})
target_link_libraries(${PROJECT_NAME}
r2000_driver
)
#######################################################
module
cmake_minimum_required(VERSION 2.8.3)
################module:#######################
#input:
#config:
#set module_args
#get_filename_component(projname ${CMAKE_CURRENT_SOURCE_DIR} NAME)
#string(REPLACE " " "_" projname ${projname})
#project(${projname})
#project(driver_example)
set(MODULE_NAME r2000_driver)
message(STATUS "PROJECT_NAME is ${PROJECT_NAME}")
option (USE_BOOST "need link boost" ON)
#set env:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x -Wfatal-errors")
SET(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
#find lib:
if (USE_BOOST)
find_package(Boost REQUIRED COMPONENTS
thread
)
endif (USE_BOOST)
#set include_dir:
include_directories(
include
${Boost_INCLUDE_DIRS}
)
#set src_set:
AUX_SOURCE_DIRECTORY(. SRC_SET_${MODULE_NAME})
#output:
add_library(${MODULE_NAME} ${SRC_SET_${MODULE_NAME}})
target_link_libraries(${MODULE_NAME}
${Boost_LIBRARIES}
)
############################################
网友评论