Skip to content

Commit

Permalink
优化 CMake 信息提示与部分编译选项
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxi-scut committed Apr 27, 2024
1 parent 2a341a0 commit a8fb765
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 90 deletions.
51 changes: 36 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ include(cmake/RMVLVersion.cmake)
set(para_template_path "${CMAKE_SOURCE_DIR}/cmake/templates" CACHE INTERNAL "GenPara template path" FORCE)
include(cmake/RMVLGenPara.cmake)

# ----------------------------------------------------------------------------
# RMVL 3rdparty libraries
# ----------------------------------------------------------------------------
find_package(OpenCV REQUIRED)
find_package(Eigen3 REQUIRED)

# ----------------------------------------------------------------------------
# Process subdirectories
# ----------------------------------------------------------------------------
Expand All @@ -94,7 +100,7 @@ endif(BUILD_EXAMPLES)
# Documents generation
# ----------------------------------------------------------------------------
if(BUILD_DOCS)
find_package(Doxygen)
find_package(Doxygen REQUIRED)
if(DOXYGEN_FOUND)
add_custom_target(
doxygen
Expand Down Expand Up @@ -163,15 +169,13 @@ endif()
status(" ccache:" ENABLE_CCACHE AND CCACHE_FOUND THEN YES ELSE NO)

# =================== Other third-party libraries ===================
find_package(OpenCV QUIET)
find_package(Eigen3 QUIET)
status("")
status(" Other third-party libraries:")
status(" OpenCV: (*)" OpenCV_FOUND THEN "YES (ver ${OpenCV_VERSION})" ELSE NO)
status(" Eigen library: (*)" Eigen3_FOUND THEN "YES (ver ${EIGEN3_VERSION_STRING})" ELSE NO)
status(" onnxruntime:" WITH_ONNXRUNTIME THEN YES ELSE NO)
status(" onnxruntime:" WITH_ONNXRUNTIME THEN "YES (ver ${Ort_VERSION})" ELSE NO)
status(" apriltag:" WITH_APRILTAG THEN YES ELSE NO)
status(" open62541:" WITH_OPEN62541 THEN YES ELSE NO)
status(" open62541:" WITH_OPEN62541 THEN "YES (ver ${open62541_VERSION})" ELSE NO)

# =============================== SDK ===============================
status("")
Expand All @@ -183,18 +187,35 @@ status(" OPT:" BUILD_rmvl_opt_camera THEN YES ELSE NO)
status(" Light controller:")
status(" OPT:" BUILD_rmvl_opt_light_control THEN YES ELSE NO)

# ===================== Inference engine in RMVL ====================
status("")
status(" Inference engine in RMVL:")
status(" Ort:" BUILD_rmvl_ort THEN YES ELSE NO)

# ========================== RMVL modules ===========================
string(REGEX REPLACE "rmvl_" " " modules_public_dir ${RMVL_MODULES_PUBLIC})
string(REGEX REPLACE "rmvl_" " " modules_interface_dir ${RMVL_MODULES_INTERFACE})
set(RMVL_MAIN_MODULES_BUILD ${RMVL_MODULES_BUILD})
foreach(m ${RMVL_EXTRA_MODULE})
string(TOUPPER "${m}" mUP)
list(REMOVE_ITEM RMVL_MAIN_MODULES_BUILD ${RMVL_${mUP}_MODULES_BUILD} rmvl_types)
if("${m}" STREQUAL "types")
continue()
endif()
string(REGEX REPLACE "rmvl_" " " ${m}_modules ${RMVL_${mUP}_MODULES_BUILD})
endforeach()
string(REGEX REPLACE "rmvl_" " " main_modules ${RMVL_MAIN_MODULES_BUILD})

status("")
status(" RMVL main modules:")
status(" To be built:" ${main_modules})
status("")
status(" RMVL extra modules:" BUILD_EXTRA THEN YES ELSE NO)
if(BUILD_EXTRA)
status(" To be built:")
foreach(m ${RMVL_EXTRA_MODULE})
if("${m}" STREQUAL "types")
continue()
endif()
status(" ${m}:" ${${m}_modules})
endforeach()
endif()
status("")
status(" RMVL modules:")
status(" public modules:" ${modules_public_dir})
status(" interface modules:" ${modules_interface_dir})
status(" Documents (Doxygen):" BUILD_DOCS THEN "YES (ver ${DOXYGEN_VERSION})" ELSE NO)


# ======================== Test and examples ========================
status("")
Expand Down
26 changes: 24 additions & 2 deletions cmake/FindOrt.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# ------------------------------------------------------------------------------
# find onnxruntime root path
# ------------------------------------------------------------------------------
if(NOT ort_root_path)
set(ort_root_path "/usr/local")
endif()

# add the include directories path
# ------------------------------------------------------------------------------
# find onnxruntime include directory
# ------------------------------------------------------------------------------
find_path(
Ort_INCLUDE_DIR
PATHS "${ort_root_path}/include/onnxruntime"
Expand All @@ -13,14 +18,19 @@ find_path(
NO_DEFAULT_PATH
)

# add libraries
# ------------------------------------------------------------------------------
# find onnxruntime library file
# ------------------------------------------------------------------------------
find_library(
Ort_LIB
NAMES "libonnxruntime.so"
PATHS "${ort_root_path}/lib"
NO_DEFAULT_PATH
)

# ------------------------------------------------------------------------------
# create imported target: onnxruntime
# ------------------------------------------------------------------------------
if(NOT TARGET onnxruntime)
add_library(onnxruntime SHARED IMPORTED)
set_target_properties(onnxruntime PROPERTIES
Expand All @@ -31,12 +41,24 @@ endif()

mark_as_advanced(Ort_INCLUDE_DIR Ort_LIB)

# ------------------------------------------------------------------------------
# set onnxruntime cmake variables and version variables
# ------------------------------------------------------------------------------
set(Ort_LIBS "onnxruntime")
set(Ort_INCLUDE_DIRS "${Ort_INCLUDE_DIR}")

file(STRINGS "${Ort_INCLUDE_DIR}/onnxruntime_c_api.h" Ort_VERSION
REGEX "#define ORT_API_VERSION [0-9]+"
)
string(REGEX REPLACE "#define ORT_API_VERSION ([0-9]+)" "1.\\1" Ort_VERSION "${Ort_VERSION}")

# ------------------------------------------------------------------------------
# handle the package
# ------------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
Ort
VERSION_VAR Ort_VERSION
REQUIRED_VARS Ort_LIB Ort_INCLUDE_DIR
)
13 changes: 9 additions & 4 deletions cmake/RMVLCompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,17 @@ option(BUILD_OPEN62541 "Build the 3rd party: open62541" OFF)
if(BUILD_OPEN62541)
add_subdirectory(${CMAKE_SOURCE_DIR}/3rdparty/open62541)
endif()
find_package(open62541 QUIET)
if(BUILD_OPEN62541 OR open62541_FOUND)
if(BUILD_OPEN62541)
unset(WITH_OPEN62541 CACHE)
option(WITH_OPEN62541 "Enable open62541 support" ON)
else()
unset(WITH_OPEN62541 CACHE)
option(WITH_OPEN62541 "Enable open62541 support" OFF)
find_package(open62541 QUIET)
if(open62541_FOUND)
option(WITH_OPEN62541 "Enable open62541 support" ON)
else()
unset(WITH_OPEN62541 CACHE)
option(WITH_OPEN62541 "Enable open62541 support" OFF)
endif()
endif()

# onnxruntime
Expand Down
19 changes: 7 additions & 12 deletions cmake/RMVLModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
# 全局变量
#
# RMVL_MODULES_BUILD
# RMVL_MODULES_PUBLIC
# RMVL_MODULES_INTERFACE
#
# RMVL_MODULE_${the_module}_LOCATION
# RMVL_MODULE_${the_module}_BINARY_DIR

set(RMVL_MODULES_BUILD "" CACHE INTERNAL "List of RMVL modules included into the build")
set(RMVL_MODULES_PUBLIC "" CACHE INTERNAL "List of RMVL public modules marked for export")
set(RMVL_MODULES_INTERFACE "" CACHE INTERNAL "List of RMVL interface modules marked for export")
set(RMVL_MODULES_BUILD "" CACHE INTERNAL "List of RMVL modules included into the build")

# ----------------------------------------------------------------------------
# 将预处理定义添加至指定目标
Expand Down Expand Up @@ -70,7 +66,11 @@ function(rmvl_install_directories _dir)
endfunction(rmvl_install_directories)

# ----------------------------------------------------------------------------
# 在当前目录中添加新的 RMVL 模块
# 在当前目录中添加新的 RMVL 模块,并会依次添加至
# - 局部变量 modules_build
# - 缓存变量 RMVL_MODULES_BUILD
# 中
#
# 用法:
# rmvl_add_module(<name> [INTERFACE] [EXTRA_HEADER <list of other include directories>]
# [EXTRA_SOURCE <list of other source directories>] [DEPENDS <list of rmvl dependencies>]
Expand Down Expand Up @@ -190,12 +190,7 @@ macro(rmvl_add_module _name)
ARCHIVE DESTINATION ${RMVL_LIB_INSTALL_PATH}
LIBRARY DESTINATION ${RMVL_LIB_INSTALL_PATH}
)

if(NOT MD_INTERFACE) # public library
set(RMVL_MODULES_PUBLIC ${RMVL_MODULES_PUBLIC} "${the_module}" CACHE INTERNAL "List of RMVL public modules marked for export" FORCE)
else() # interface library
set(RMVL_MODULES_INTERFACE ${RMVL_MODULES_INTERFACE} "${the_module}" CACHE INTERNAL "List of RMVL interface modules marked for export" FORCE)
endif(NOT MD_INTERFACE)
list(APPEND modules_build ${the_module})
set(RMVL_MODULES_BUILD ${RMVL_MODULES_BUILD} "${the_module}" CACHE INTERNAL "List of RMVL modules included into the build" FORCE)
endif()
unset(the_module)
Expand Down
2 changes: 1 addition & 1 deletion cmake/templates/RMVLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ endforeach()
# =============================================================
find_package_handle_standard_args(RMVL
REQUIRED_VARS RMVL_INSTALL_PATH
VERSION_VAR RMVL_VERSION HANDLE_COMPONENTS
VERSION_VAR RMVL_VERSION
)
10 changes: 5 additions & 5 deletions extra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ file(GLOB module_extra_st RELATIVE "${cur_path}" "${cur_path}/*")

set(RMVL_EXTRA_MODULE "")
foreach(m ${module_extra_st})
if(IS_DIRECTORY ${cur_path}/${m} AND (NOT (${m} STREQUAL include)))
list(APPEND RMVL_EXTRA_MODULE "${m}")
endif()
if(IS_DIRECTORY ${cur_path}/${m} AND (NOT (${m} STREQUAL include)))
list(APPEND RMVL_EXTRA_MODULE "${m}")
endif()
endforeach()

set(RMVL_EXTRA_MODULE ${RMVL_EXTRA_MODULE} CACHE INTERNAL "List of main modules" FORCE)
set(RMVL_EXTRA_MODULE ${RMVL_EXTRA_MODULE} CACHE INTERNAL "List of main modules")

# core modules
foreach(m ${RMVL_EXTRA_MODULE})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${m})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/${m})
endforeach()

unset(module_extra_st)
12 changes: 11 additions & 1 deletion extra/combo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ----------------------------------------------------------------------------
# Generate para and add module for each combo
# ----------------------------------------------------------------------------
rmvl_add_module(
combo
DEPENDS feature camera
Expand Down Expand Up @@ -25,11 +28,18 @@ rmvl_add_module(

rmvl_generate_module_para(combo)

# build the test program
# ----------------------------------------------------------------------------
# build the test program
# ----------------------------------------------------------------------------
if(BUILD_TESTS)
rmvl_add_test(
combo Unit
DEPENDS armor rune
DEPEND_TESTS GTest::gtest_main
)
endif(BUILD_TESTS)

# ----------------------------------------------------------------------------
# Export the combo modules
# ----------------------------------------------------------------------------
set(RMVL_COMBO_MODULES_BUILD ${modules_build} CACHE INTERNAL "modules to be built")
24 changes: 16 additions & 8 deletions extra/compensator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
# ----------------------------------------------------------------------------
# Generate para and add module for each compensator
# ----------------------------------------------------------------------------
rmvl_add_module(
compensator INTERFACE
DEPENDS group
)

# gravity_compensator
rmvl_generate_para(
gravity_compensator
MODULE compensator
)

rmvl_generate_para(
gyro_compensator
MODULE compensator
)

# gravity_compensator
rmvl_add_module(
gravity_compensator
DEPENDS compensator
)

# gyro_compensator
rmvl_generate_para(
gyro_compensator
MODULE compensator
)
rmvl_add_module(
gyro_compensator
DEPENDS compensator gyro_group
)

rmvl_generate_module_para(compensator)

# Tests
# ----------------------------------------------------------------------------
# Build the test program
# ----------------------------------------------------------------------------
if(BUILD_TESTS)
rmvl_add_test(
compensator Unit
DEPENDS gravity_compensator
DEPEND_TESTS GTest::gtest_main
)
endif()

# ----------------------------------------------------------------------------
# Export the compensator modules
# ----------------------------------------------------------------------------
set(RMVL_COMPENSATOR_MODULES_BUILD ${modules_build} CACHE INTERNAL "modules to be built")
12 changes: 11 additions & 1 deletion extra/decider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ----------------------------------------------------------------------------
# Generate para and add module for each decider
# ----------------------------------------------------------------------------
rmvl_add_module(
decider INTERFACE
DEPENDS detector compensator predictor
Expand Down Expand Up @@ -35,8 +38,15 @@ rmvl_add_module(

rmvl_generate_module_para(decider)

# build the test program
# ----------------------------------------------------------------------------
# Build the test program
# ----------------------------------------------------------------------------
if(BUILD_TESTS)

endif(BUILD_TESTS)

# ----------------------------------------------------------------------------
# Export the decider modules
# ----------------------------------------------------------------------------
set(RMVL_DECIDER_MODULES_BUILD ${modules_build} CACHE INTERNAL "modules to be built")

13 changes: 12 additions & 1 deletion extra/detector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# ----------------------------------------------------------------------------
# Generate para and add module for each detector
# ----------------------------------------------------------------------------
rmvl_add_module(
detector INTERFACE
DEPENDS imgproc group
Expand Down Expand Up @@ -50,11 +53,19 @@ endif()

rmvl_generate_module_para(detector)

# build the test program
# ----------------------------------------------------------------------------
# Build the test program
# ----------------------------------------------------------------------------
if(BUILD_TESTS)
rmvl_add_test(
detector Unit
DEPENDS armor_detector rune_detector gyro_detector
DEPEND_TESTS GTest::gtest_main
)
endif(BUILD_TESTS)

# ----------------------------------------------------------------------------
# Export the detector modules
# ----------------------------------------------------------------------------
set(RMVL_DETECTOR_MODULES_BUILD ${modules_build} CACHE INTERNAL "modules to be built")

Loading

0 comments on commit a8fb765

Please sign in to comment.