upload
This commit is contained in:
16
cmake/templates/vslamConfig.cmake.in
Normal file
16
cmake/templates/vslamConfig.cmake.in
Normal file
@@ -0,0 +1,16 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
# Sinh boi vslam_add_library() cho goi @VSLAM_PKG_NAME@.
|
||||
#
|
||||
# Day la file ma ca obstacle_detection_core lan xloc_cpp deu thieu: khong co
|
||||
# no thi find_package() that bai du da co Targets.cmake, vi Targets.cmake
|
||||
# tham chieu cac target import (Eigen3::Eigen, PCL, ...) ma chua ai
|
||||
# find_dependency() ra ca.
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
@VSLAM_FIND_DEPS_BLOCK@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@VSLAM_PKG_NAME@Targets.cmake")
|
||||
|
||||
check_required_components(@VSLAM_PKG_NAME@)
|
||||
234
cmake/vslam_helpers.cmake
Normal file
234
cmake/vslam_helpers.cmake
Normal file
@@ -0,0 +1,234 @@
|
||||
# ---------------------------------------------------------------------------
|
||||
# vslam_helpers.cmake
|
||||
#
|
||||
# Ham dung chung cho 7 lib trong libs/. Muc tieu: moi CMakeLists.txt cua lib
|
||||
# chi con khai bao NGUON PHU THUOC va DANH SACH HEADER CONG KHAI, khong lap
|
||||
# lai boilerplate install/export.
|
||||
#
|
||||
# Khuon mau lay tu /home/quangtrung/obstacle_detection_core/CMakeLists.txt,
|
||||
# co ba khac biet co y:
|
||||
# 1. Sinh <name>Config.cmake -- ca obstacle_detection_core lan xloc_cpp deu
|
||||
# thieu file nay, nen find_package() ma README cua chung hua hen hien
|
||||
# KHONG chay duoc (chi co Targets.cmake, va Targets.cmake tham chieu
|
||||
# ${PCL_LIBRARIES} dang duong dan tuyet doi ma khong find_dependency).
|
||||
# 2. Header cai vao include/vslam/ chu khong phai include/<ten_lib>/, vi
|
||||
# voi 7 lib thi header cua lib nay phai #include header cua lib kia --
|
||||
# duong dan in-tree va duong dan da cai buoc phai giong nhau.
|
||||
# 3. GLOB_RECURSE co CONFIGURE_DEPENDS: khong co no thi them file .cc moi
|
||||
# se khong duoc build cho toi khi chay lai cmake bang tay.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# vslam_add_library(<NAME>
|
||||
# [PUBLIC_HDRS <header ...>] # ten file trong include/vslam/, se duoc cai
|
||||
# [PUBLIC_DEPS <target ...>] # lan sang consumer
|
||||
# [PRIVATE_DEPS <target ...>] # khong lan
|
||||
# [DEFINES <def ...>] # PRIVATE compile definitions
|
||||
# [PUBLIC_DEFINES <def ...>] # PUBLIC compile definitions
|
||||
# [FIND_DEPS <pkg ...>] # sinh find_dependency() trong Config.cmake
|
||||
# )
|
||||
#
|
||||
# Header nao KHONG liet ke trong PUBLIC_HDRS thi la noi bo: van compile duoc
|
||||
# trong cay nguon nhung khong phat hanh. Day la quy tac 8 cua khuon mau
|
||||
# (xloc_cpp/CMakeLists.txt dong 232-253 dung list(REMOVE_ITEM) cho cung viec).
|
||||
# ---------------------------------------------------------------------------
|
||||
function(vslam_add_library NAME)
|
||||
cmake_parse_arguments(A
|
||||
""
|
||||
""
|
||||
"PUBLIC_HDRS;PUBLIC_DEPS;PRIVATE_DEPS;DEFINES;PUBLIC_DEFINES;FIND_DEPS"
|
||||
${ARGN})
|
||||
|
||||
file(GLOB_RECURSE _srcs CONFIGURE_DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
if(NOT _srcs)
|
||||
message(FATAL_ERROR "vslam_add_library(${NAME}): khong tim thay nguon nao trong src/")
|
||||
endif()
|
||||
|
||||
add_library(${NAME} SHARED ${_srcs})
|
||||
add_library(vslam::${NAME} ALIAS ${NAME})
|
||||
|
||||
# KHONG dat CXX_VISIBILITY_PRESET hidden. Ca obstacle_detection_core lan
|
||||
# xloc_cpp deu export mac dinh va chi gan visibility("default") tuong minh
|
||||
# len rieng C API; lam khac di thi moi ky hieu C++ bi an va khong link duoc
|
||||
# tu ngoai. Neu sau nay muon thu nho .so thi phai them mot macro VSLAM_API
|
||||
# tren tung lop cong khai TRUOC, khong phai bat co nay truoc.
|
||||
set_target_properties(${NAME} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR})
|
||||
|
||||
target_include_directories(${NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
|
||||
if(A_PUBLIC_DEPS)
|
||||
target_link_libraries(${NAME} PUBLIC ${A_PUBLIC_DEPS})
|
||||
endif()
|
||||
if(A_PRIVATE_DEPS)
|
||||
target_link_libraries(${NAME} PRIVATE ${A_PRIVATE_DEPS})
|
||||
endif()
|
||||
if(A_DEFINES)
|
||||
target_compile_definitions(${NAME} PRIVATE ${A_DEFINES})
|
||||
endif()
|
||||
if(A_PUBLIC_DEFINES)
|
||||
target_compile_definitions(${NAME} PUBLIC ${A_PUBLIC_DEFINES})
|
||||
endif()
|
||||
|
||||
# --- Header cong khai ----------------------------------------------------
|
||||
foreach(_h ${A_PUBLIC_HDRS})
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/include/vslam/${_h})
|
||||
message(FATAL_ERROR
|
||||
"vslam_add_library(${NAME}): PUBLIC_HDRS liet ke '${_h}' nhung "
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/vslam/${_h} khong ton tai")
|
||||
endif()
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/vslam/${_h}
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vslam)
|
||||
endforeach()
|
||||
|
||||
# --- Install + export ----------------------------------------------------
|
||||
install(TARGETS ${NAME}
|
||||
EXPORT ${NAME}Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
install(EXPORT ${NAME}Targets
|
||||
FILE ${NAME}Targets.cmake
|
||||
NAMESPACE vslam::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME})
|
||||
|
||||
# --- <name>Config.cmake --------------------------------------------------
|
||||
# Sinh tu template chung. Danh sach FIND_DEPS duoc noi thanh cac dong
|
||||
# find_dependency() -- day la thu ma ca hai project mau deu thieu.
|
||||
set(_find_deps_block "")
|
||||
foreach(_d ${A_FIND_DEPS})
|
||||
string(APPEND _find_deps_block "find_dependency(${_d})\n")
|
||||
endforeach()
|
||||
set(VSLAM_PKG_NAME ${NAME})
|
||||
set(VSLAM_FIND_DEPS_BLOCK "${_find_deps_block}")
|
||||
|
||||
configure_package_config_file(
|
||||
${VSLAM_CMAKE_DIR}/templates/vslamConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${NAME}Config.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME})
|
||||
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${NAME}ConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${NAME}Config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${NAME}ConfigVersion.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${NAME})
|
||||
endfunction()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# vslam_link_pcl(<target> <PUBLIC|PRIVATE> <component ...>)
|
||||
#
|
||||
# PCL bom -march=native -msse4.2 -mfpmath=sse vao PCL_DEFINITIONS. Tren arm64
|
||||
# may co SSE nay lam compile fail thang; -march=native con la hazard ODR khi
|
||||
# mot phan cay nguon build voi no va phan kia thi khong.
|
||||
#
|
||||
# xloc_cpp/CMakeLists.txt:104-111 co block loc nhung KHONG chay: bien
|
||||
# BLACKLISTED_PCL_DEFINITIONS o do la MOT CHUOI " -march=native -msse4.2 ... "
|
||||
# chu khong phai list, nen list(FIND ...) so sanh ca chuoi voi tung phan tu va
|
||||
# khong bao gio khop. Ban nay dung list that.
|
||||
# ---------------------------------------------------------------------------
|
||||
function(vslam_link_pcl TARGET SCOPE)
|
||||
set(_components ${ARGN})
|
||||
find_package(PCL REQUIRED COMPONENTS ${_components})
|
||||
|
||||
target_include_directories(${TARGET} SYSTEM ${SCOPE} ${PCL_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET} ${SCOPE} ${PCL_LIBRARIES})
|
||||
target_link_directories(${TARGET} ${SCOPE} ${PCL_LIBRARY_DIRS})
|
||||
|
||||
set(_blacklist -march=native -msse4.2 -mfpmath=sse -mavx -mavx2 -msse3 -msse4.1)
|
||||
set(_kept "")
|
||||
foreach(_def ${PCL_DEFINITIONS})
|
||||
# PCL_DEFINITIONS co the la " -DFOO -march=native " (mot chuoi nhieu co),
|
||||
# nen phai tach ra truoc khi loc.
|
||||
string(REPLACE " " ";" _parts "${_def}")
|
||||
foreach(_p ${_parts})
|
||||
if(_p STREQUAL "")
|
||||
continue()
|
||||
endif()
|
||||
list(FIND _blacklist "${_p}" _idx)
|
||||
if(_idx GREATER -1)
|
||||
message(STATUS "vslam_link_pcl(${TARGET}): bo co PCL '${_p}'")
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _kept "${_p}")
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
if(_kept)
|
||||
list(REMOVE_DUPLICATES _kept)
|
||||
target_compile_options(${TARGET} ${SCOPE} ${_kept})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# vslam_embed_assets(<target> <OUT_VAR> <asset_dir> <file ...>)
|
||||
#
|
||||
# Nhung file tinh (html/js/css) thanh mang unsigned char trong .so, de Jetson
|
||||
# ngoai hien truong phuc vu duoc web UI ke ca khi /var/lib chua duoc .deb dien,
|
||||
# va de khong bao gio lech phien ban giua .so va UI.
|
||||
#
|
||||
# CMake thuan, khong can Python hay tool ngoai.
|
||||
# ---------------------------------------------------------------------------
|
||||
function(vslam_embed_assets TARGET OUT_VAR ASSET_DIR)
|
||||
set(_files ${ARGN})
|
||||
set(_gen ${CMAKE_CURRENT_BINARY_DIR}/web_assets_generated.cc)
|
||||
|
||||
set(_body "// Sinh tu dong boi vslam_embed_assets(). Dung sua bang tay.\n")
|
||||
string(APPEND _body "#include <cstddef>\n#include <map>\n#include <string>\n\n")
|
||||
string(APPEND _body "namespace vslam {\nnamespace {\n\n")
|
||||
|
||||
set(_registry "")
|
||||
set(_idx 0)
|
||||
foreach(_f ${_files})
|
||||
set(_path ${ASSET_DIR}/${_f})
|
||||
if(NOT EXISTS ${_path})
|
||||
message(FATAL_ERROR "vslam_embed_assets: khong tim thay ${_path}")
|
||||
endif()
|
||||
|
||||
# Bat CMake chay lai khi file asset doi.
|
||||
#
|
||||
# file(READ) chay o thi CONFIGURE, nen neu khong khai bao phu thuoc nay
|
||||
# thi sua www/app.js roi build lai se VAN phuc vu ban cu -- khong loi,
|
||||
# khong canh bao, chi la trinh duyet nhan noi dung tu lan configure truoc.
|
||||
# Da mac phai mot lan; mat thoi gian vi no trong nhu loi o phia JS.
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_path})
|
||||
|
||||
file(READ ${_path} _hex HEX)
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," _carr "${_hex}")
|
||||
string(LENGTH "${_hex}" _hexlen)
|
||||
math(EXPR _len "${_hexlen} / 2")
|
||||
|
||||
string(APPEND _body "const unsigned char kAsset${_idx}[] = {${_carr}};\n")
|
||||
string(APPEND _registry
|
||||
" {\"${_f}\", {kAsset${_idx}, ${_len}}},\n")
|
||||
math(EXPR _idx "${_idx} + 1")
|
||||
endforeach()
|
||||
|
||||
string(APPEND _body "\n} // namespace\n\n")
|
||||
string(APPEND _body "struct EmbeddedAsset { const unsigned char* data; std::size_t size; };\n\n")
|
||||
string(APPEND _body "const std::map<std::string, EmbeddedAsset>& EmbeddedAssets() {\n")
|
||||
string(APPEND _body " static const std::map<std::string, EmbeddedAsset> kMap = {\n")
|
||||
string(APPEND _body "${_registry}")
|
||||
string(APPEND _body " };\n return kMap;\n}\n\n")
|
||||
string(APPEND _body "} // namespace vslam\n")
|
||||
|
||||
file(GENERATE OUTPUT ${_gen} CONTENT "${_body}")
|
||||
set(${OUT_VAR} ${_gen} PARENT_SCOPE)
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user