Use imported target for res_tool during cross compilation. (#865)

This commit is contained in:
Windel Bouwman
2022-09-04 19:18:14 +02:00
committed by GitHub
parent 8cd4a6feff
commit 8826f136a9
3 changed files with 53 additions and 49 deletions

View File

@@ -1,28 +1,51 @@
SET(SRC_FILES
main.cpp
)
if (CMAKE_CROSSCOMPILING OR ANDROID OR IOS)
# See this page about tools being required in the build:
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/CrossCompiling#using-executables-in-the-build-created-during-the-build
SET(INCLUDE_DIRS
../include
)
# Some ideas there were used, not all.
# The target named 'res_tool' can be used elsewhere in all cases, when cross compiling or not.
# Make sure the compiler can find include files from our library.
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
IF(NOT RTABMAP_RES_TOOL)
FIND_PROGRAM(RTABMAP_RES_TOOL ${PROJECT_PREFIX}-res_tool)
IF(NOT RTABMAP_RES_TOOL)
MESSAGE( FATAL_ERROR "RTABMAP_RES_TOOL is not defined (it is the path to \"rtabmap-res_tool\" application created by a non-Android build)." )
ENDIF(NOT RTABMAP_RES_TOOL)
ENDIF()
# Add binary called "resource_tool" that is built from the source file "main.cpp".
# The extension is automatically found.
ADD_EXECUTABLE(res_tool ${SRC_FILES})
TARGET_LINK_LIBRARIES(res_tool rtabmap_utilite)
SET_TARGET_PROPERTIES(
res_tool
PROPERTIES
VERSION ${UTILITE_VERSION}
SOVERSION ${UTILITE_VERSION}
OUTPUT_NAME ${PROJECT_PREFIX}-res_tool
)
MESSAGE(STATUS "Using res_tool at ${RTABMAP_RES_TOOL}")
INSTALL(TARGETS res_tool
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime)
ADD_EXECUTABLE(res_tool IMPORTED GLOBAL)
SET_TARGET_PROPERTIES(res_tool PROPERTIES IMPORTED_LOCATION "${RTABMAP_RES_TOOL}")
else()
SET(SRC_FILES
main.cpp
)
SET(INCLUDE_DIRS
../include
)
# Make sure the compiler can find include files from our library.
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
# Add binary called "resource_tool" that is built from the source file "main.cpp".
# The extension is automatically found.
ADD_EXECUTABLE(res_tool ${SRC_FILES})
TARGET_LINK_LIBRARIES(res_tool rtabmap_utilite)
SET_TARGET_PROPERTIES(
res_tool
PROPERTIES
VERSION ${UTILITE_VERSION}
SOVERSION ${UTILITE_VERSION}
OUTPUT_NAME ${PROJECT_PREFIX}-res_tool
)
INSTALL(TARGETS res_tool
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime
BUNDLE DESTINATION "${CMAKE_BUNDLE_LOCATION}" COMPONENT runtime)
endif()