From a46376b456434ff1f76a4dfb29912672035c781d Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 11:53:50 +0100 Subject: [PATCH 1/7] WIP: installing to the correct catkin spots --- CMakeLists.txt | 72 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a817712..e4cbc5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ -cmake_minimum_required(VERSION 3.0.2) +cmake_minimum_required(VERSION 3.5.0) project(torch_vendor) +#set(CMAKE_CUDA_ARCHITECTURES "native") +include(FetchContent) + +cmake_policy(SET CMP0135 NEW) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) @@ -9,10 +13,42 @@ find_package(catkin REQUIRED) ## System dependencies are found with CMake's conventions # find_package(Boost REQUIRED COMPONENTS system) -## Uncomment this if the package has a setup.py. This macro ensures -## modules and global scripts declared therein get installed -## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html -# catkin_python_setup() +set(FETCHCONTENT_QUIET FALSE) +FetchContent_Declare( + libtorch + URL https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.1%2Bcu121.zip + OVERRIDE_FIND_PACKAGE + DOWNLOAD_EXTRACT_TIMESTAMP +) +#FetchContent_Populate(Torch) +FetchContent_MakeAvailable(libtorch) +#FetchContent_GetProperties(Torch) +#if(NOT torch_POPULATED) +# FetchContent_Populate(torch) +# add_subdirectory(${torch_SOURCE_DIR}) +# add_subdirectory(${torch_BINARY_DIR}) +#endif() +#list(APPEND CMAKE_PREFIX_PATH "${torch_SOURCE_DIR}") + +find_package(Torch REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH) +message(WARNING "Torch_FOUND: ${Torch_FOUND}") +message(WARNING "TORCH_FOUND: ${TORCH_FOUND}") +message(WARNING "TORCH_INCLUDE_DIRS: ${TORCH_INCLUDE_DIRS}") +message(WARNING "TORCH_LIBRARIES: ${TORCH_LIBRARIES}") +message(WARNING "TORCH_LIBRARY: ${TORCH_LIBRARY}") +message(WARNING "libtorch_SOURCE_DIR: ${libtorch_SOURCE_DIR}") +message(WARNING "libtorch_BINARY_DIR: ${libtorch_BINARY_DIR}") +message(WARNING "CATKIN_PACKAGE_LIB_DESTINATION: ${CATKIN_PACKAGE_LIB_DESTINATION}") +message(WARNING "CATKIN_GLOBAL_BIN_DESTINATION: ${CATKIN_GLOBAL_BIN_DESTINATION}") +message(WARNING "CATKIN_PACKAGE_INCLUDE_DESTINATION: ${CATKIN_PACKAGE_INCLUDE_DESTINATION}") + +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") + +#get_cmake_property(_variableNames VARIABLES) +#list (SORT _variableNames) +#foreach (_variableName ${_variableNames}) +# message(WARNING "${_variableName}=${${_variableName}}") +#endforeach() ################################### ## catkin specific configuration ## @@ -24,10 +60,10 @@ find_package(catkin REQUIRED) ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( -# INCLUDE_DIRS include -# LIBRARIES torch_vendor +# INCLUDE_DIRS "${TORCH_INCLUDE_DIRS}" +# LIBRARIES "${TORCH_LIBRARIES}" # CATKIN_DEPENDS other_catkin_pkg -# DEPENDS system_lib +# DEPENDS TORCH ) ########### @@ -93,18 +129,18 @@ include_directories( ## Mark libraries for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html -# install(TARGETS ${PROJECT_NAME} -# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} -# ) + install(TARGETS TORCH + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} + ) ## Mark cpp header files for installation -# install(DIRECTORY include/${PROJECT_NAME}/ -# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -# FILES_MATCHING PATTERN "*.h" -# PATTERN ".svn" EXCLUDE -# ) + install(DIRECTORY ${Torch_INCLUDE_DIRS} + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} + FILES_MATCHING PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) ## Mark other files for installation (e.g. launch and bag files, etc.) # install(FILES From 95b45a9ad0d9972ddd8f7d271cba74a7898cdaab Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 13:57:38 +0100 Subject: [PATCH 2/7] Installing include, lib and share dirs But nothin in the devel space yet --- CMakeLists.txt | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4cbc5d..8b99166 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,15 +20,7 @@ FetchContent_Declare( OVERRIDE_FIND_PACKAGE DOWNLOAD_EXTRACT_TIMESTAMP ) -#FetchContent_Populate(Torch) FetchContent_MakeAvailable(libtorch) -#FetchContent_GetProperties(Torch) -#if(NOT torch_POPULATED) -# FetchContent_Populate(torch) -# add_subdirectory(${torch_SOURCE_DIR}) -# add_subdirectory(${torch_BINARY_DIR}) -#endif() -#list(APPEND CMAKE_PREFIX_PATH "${torch_SOURCE_DIR}") find_package(Torch REQUIRED PATHS ${libtorch_SOURCE_DIR} NO_DEFAULT_PATH) message(WARNING "Torch_FOUND: ${Torch_FOUND}") @@ -60,7 +52,7 @@ message(WARNING "CATKIN_PACKAGE_INCLUDE_DESTINATION: ${CATKIN_PACKAGE_INCLUDE_DE ## CATKIN_DEPENDS: catkin_packages dependent projects also need ## DEPENDS: system dependencies of this project that dependent projects also need catkin_package( -# INCLUDE_DIRS "${TORCH_INCLUDE_DIRS}" + INCLUDE_DIRS ${libtorch_SOURCE_DIR}/include/ # LIBRARIES "${TORCH_LIBRARIES}" # CATKIN_DEPENDS other_catkin_pkg # DEPENDS TORCH @@ -129,18 +121,18 @@ include_directories( ## Mark libraries for installation ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html - install(TARGETS TORCH - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} - ) +# install(TARGETS ${PROJECT_NAME} +# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} +# ) ## Mark cpp header files for installation - install(DIRECTORY ${Torch_INCLUDE_DIRS} - DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} - FILES_MATCHING PATTERN "*.h" - PATTERN ".svn" EXCLUDE - ) +# install(DIRECTORY include/${PROJECT_NAME}/ +# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +# FILES_MATCHING PATTERN "*.h" +# PATTERN ".svn" EXCLUDE +# ) ## Mark other files for installation (e.g. launch and bag files, etc.) # install(FILES @@ -149,6 +141,17 @@ include_directories( # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} # ) +install(DIRECTORY ${libtorch_SOURCE_DIR}/include/ + DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} +) +install(DIRECTORY ${libtorch_SOURCE_DIR}/lib/ + DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} +) + +install(DIRECTORY ${libtorch_SOURCE_DIR}/share/ + DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} +) + ############# ## Testing ## ############# From e94b97909b51835b4e78c5fc936765cffd4f45d5 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 14:12:53 +0100 Subject: [PATCH 3/7] Set min cmake version to 3.16 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b99166..f7a0c13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.16.0) project(torch_vendor) #set(CMAKE_CUDA_ARCHITECTURES "native") include(FetchContent) From 467b347c8df7b780296244453428205d910d2f06 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 14:13:14 +0100 Subject: [PATCH 4/7] Don't set CMP0135 policy as it requires 3.24 --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7a0c13..ab0ce30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,6 @@ project(torch_vendor) #set(CMAKE_CUDA_ARCHITECTURES "native") include(FetchContent) -cmake_policy(SET CMP0135 NEW) - ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages From 58f658673fdb7ba115ce09358e60db8c729ef7a5 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 14:41:22 +0100 Subject: [PATCH 5/7] Add buildtool dep on cmake --- package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/package.xml b/package.xml index 6a4ec69..70c889a 100644 --- a/package.xml +++ b/package.xml @@ -34,6 +34,7 @@ catkin + cmake From 1d6fd4b0cf5b7a88c00e24b3d9c343654407071b Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 14:48:13 +0100 Subject: [PATCH 6/7] Remove commented set --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0ce30..4de600a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.16.0) project(torch_vendor) -#set(CMAKE_CUDA_ARCHITECTURES "native") include(FetchContent) ## Find catkin macros and libraries From 5fbf1ce8c0b485719913a83132d1c03605d77cc2 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Tue, 5 Dec 2023 14:48:49 +0100 Subject: [PATCH 7/7] Set CMP0135 policy to new --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4de600a..d377360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ -cmake_minimum_required(VERSION 3.16.0) +cmake_minimum_required(VERSION 3.24.0) project(torch_vendor) include(FetchContent) +cmake_policy(SET CMP0135 NEW) + ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages