Skip to content

Commit

Permalink
Use imported target for res_tool during cross compilation. (introlab#865
Browse files Browse the repository at this point in the history
)
  • Loading branch information
windelbouwman authored Sep 4, 2022
1 parent 8cd4a6f commit 8826f13
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 53 deletions.
29 changes: 6 additions & 23 deletions corelib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -725,29 +725,12 @@ endforeach(arg ${RESOURCES})
#MESSAGE(STATUS "RESOURCES = ${RESOURCES}")
#MESSAGE(STATUS "RESOURCES_HEADERS = ${RESOURCES_HEADERS}")

IF(ANDROID OR IOS)

IF(NOT RTABMAP_RES_TOOL)
find_host_program(RTABMAP_RES_TOOL rtabmap-res_tool PATHS ${PROJECT_BINARY_DIR}/../bin)
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(NOT RTABMAP_RES_TOOL)

ADD_CUSTOM_COMMAND(
OUTPUT ${RESOURCES_HEADERS}
COMMAND ${RTABMAP_RES_TOOL} -n rtabmap -p ${CMAKE_CURRENT_BINARY_DIR} ${RESOURCES}
COMMENT "[Creating resources]"
DEPENDS ${RESOURCES}
)
ELSE()
ADD_CUSTOM_COMMAND(
OUTPUT ${RESOURCES_HEADERS}
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rtabmap-res_tool -n rtabmap -p ${CMAKE_CURRENT_BINARY_DIR} ${RESOURCES}
COMMENT "[Creating resources]"
DEPENDS ${RESOURCES} res_tool
)
ENDIF()
ADD_CUSTOM_COMMAND(
OUTPUT ${RESOURCES_HEADERS}
COMMAND res_tool -n rtabmap -p ${CMAKE_CURRENT_BINARY_DIR} ${RESOURCES}
COMMENT "[Creating resources]"
DEPENDS ${RESOURCES}
)

####################################
# Generate resources files END
Expand Down
4 changes: 1 addition & 3 deletions utilite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ ENDIF(UNIX AND NOT ANDROID)

ADD_SUBDIRECTORY( src )

IF(NOT MOBILE_BUILD)
ADD_SUBDIRECTORY( resource_generator )
ENDIF(NOT MOBILE_BUILD)
ADD_SUBDIRECTORY( resource_generator )
77 changes: 50 additions & 27 deletions utilite/resource_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@

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)
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

# Some ideas there were used, not all.
# The target named 'res_tool' can be used elsewhere in all cases, when cross compiling or not.

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()

MESSAGE(STATUS "Using res_tool at ${RTABMAP_RES_TOOL}")

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()

0 comments on commit 8826f13

Please sign in to comment.