From 8826f136a9664bc0839cf84fc0eaf28cde1e954b Mon Sep 17 00:00:00 2001 From: Windel Bouwman Date: Sun, 4 Sep 2022 19:18:14 +0200 Subject: [PATCH] Use imported target for res_tool during cross compilation. (#865) --- corelib/src/CMakeLists.txt | 29 ++------- utilite/CMakeLists.txt | 4 +- utilite/resource_generator/CMakeLists.txt | 77 +++++++++++++++-------- 3 files changed, 57 insertions(+), 53 deletions(-) diff --git a/corelib/src/CMakeLists.txt b/corelib/src/CMakeLists.txt index f99d5123a3..ae087af189 100644 --- a/corelib/src/CMakeLists.txt +++ b/corelib/src/CMakeLists.txt @@ -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 diff --git a/utilite/CMakeLists.txt b/utilite/CMakeLists.txt index 39caf123f0..b152c0f719 100644 --- a/utilite/CMakeLists.txt +++ b/utilite/CMakeLists.txt @@ -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 ) diff --git a/utilite/resource_generator/CMakeLists.txt b/utilite/resource_generator/CMakeLists.txt index 40489b1404..a41de3bfbf 100644 --- a/utilite/resource_generator/CMakeLists.txt +++ b/utilite/resource_generator/CMakeLists.txt @@ -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) \ No newline at end of file +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()