cmake_minimum_required(VERSION 2.8.3)
project(project_name)
## Use C++11
# add_definitions(-std=c++11 -Wall)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -O3 -lpthread")
## Find catkin macros and libraries
find_package(catkin REQUIRED
COMPONENTS
message_generation
roscpp
sensor_msgs
std_msgs
)
## Find system libraries
#find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS system thread)
# add_message_files(
# FILES
# test.msg
# )
# add_service_files(
# FILES
# test.srv
# )
# generate_messages(
# DEPENDENCIES
# sensor_msgs
# std_msgs
# )
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
${PROJECT_NAME}_core
CATKIN_DEPENDS
roscpp
sensor_msgs
std_msgs
DEPENDS
Boost
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
message("-- check cpu frame: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64" )
message("x86_64-- Current cpu frame: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
include_directories(${PROJECT_SOURCE_DIR}/../third_party/2_x86_all/include)
link_directories(${PROJECT_SOURCE_DIR}/../third_party/2_x86_all/lib)
set(THIRD_PARTY_HEADERS ${PROJECT_SOURCE_DIR}/../third_party/2_x86_all/)
set(THIRD_PARTY_LIBS ${PROJECT_SOURCE_DIR}/../third_party/2_x86_all/lib/)
else(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
message("aarch64-- Current cpu frame: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
include_directories(${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/include)
link_directories(${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/lib)
set(THIRD_PARTY_HEADERS ${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/)
set(THIRD_PARTY_LIBS ${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/lib/)
endif()
## Declare a cpp library
add_library(${PROJECT_NAME}_core
src/test.cpp
)
## Declare cpp executables
add_executable(${PROJECT_NAME}_node
src/${PROJECT_NAME}_node.cpp
src/test_ros.cpp
)
## Add dependencies to exported targets, like ROS msgs or srvs
add_dependencies(${PROJECT_NAME}_core
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
add_dependencies(${PROJECT_NAME}_node
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS}
)
## Specify libraries to link executable targets against
target_link_libraries(${PROJECT_NAME}_core
${catkin_LIBRARIES}
${Boost_LIBRARIES}
glog
gflags
)
target_link_libraries(${PROJECT_NAME}_node
${PROJECT_NAME}_core
${catkin_LIBRARIES}
${Boost_LIBRARIES}
-lrt
)
#############
## Install ##
#############
# Mark executables and/or libraries for installation
install(
TARGETS ${PROJECT_NAME}_core
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(
TARGETS ${PROJECT_NAME}_node
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
# 安装项目结点头文件 可以指定目录include或其他
# file(GLOB_RECURSE ALL_LIBRARY_HDRS "include/*.h")
# set(INSTALL_SOURCE_HDRS ${ALL_LIBRARY_HDRS})
# foreach(HDR ${INSTALL_SOURCE_HDRS})
# file(RELATIVE_PATH REL_FIL ${PROJECT_SOURCE_DIR}/include ${HDR})
# get_filename_component(DIR ${REL_FIL} DIRECTORY)
# install(
# FILES ${HDR}
# DESTINATION include/${PROJECT_NAME}/${DIR}
# )
# endforeach()
# 安装第三方库头文件
install(DIRECTORY ${THIRD_PARTY_HEADERS}
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}/../third_party/
FILES_MATCHING PATTERN "*.h")
# 安装第三方库库文件
install(DIRECTORY ${THIRD_PARTY_LIBS}
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
# Mark cpp header files for installation
# 自动搜索统计目录下./inclue/下的*.h文件并安装至install/include/
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
# Mark other files for installation
install(
DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
1.1、设置第三方库路径变量
set(THIRD_PARTY_HEADERS ${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/)
set(THIRD_PARTY_LIBS ${PROJECT_SOURCE_DIR}/../third_party/1_arm_all/lib/)
1.2、安装第三方库文件到install指定目录下
# 安装第三方库头文件 只搜索路径下 *.h文件 复制到 install/include/third_party/ 目录下
install(DIRECTORY ${THIRD_PARTY_HEADERS}
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}/../third_party/
FILES_MATCHING PATTERN "*.h")
# 安装第三方库库文件 *.so *.a 到 install/lib/目录下
install(DIRECTORY ${THIRD_PARTY_LIBS}
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
2、安装一些共享文件或配置到 install/share/
# Mark other files for installation
install(
DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)