From a09a5e5da84bdc40b824e33046d94ce1ba3cc21c Mon Sep 17 00:00:00 2001 From: Kenji Brameld Date: Sat, 17 Sep 2022 10:35:24 +0000 Subject: [PATCH] Revert "More alot (#419)" This reverts commit 9ea89084cff3227844d42ae2009c2b1be14f842c. Signed-off-by: Kenji Brameld (cherry picked from commit 1a78fcbc09e89be6f1ad43956b72cb79f595d874) --- cv_bridge/CMakeLists.txt | 12 +++-- cv_bridge/src/CMakeLists.txt | 84 ++++++++++++++++++++---------- cv_bridge/test/CMakeLists.txt | 6 +-- image_geometry/CMakeLists.txt | 47 ++++++++++------- image_geometry/test/CMakeLists.txt | 8 +-- 5 files changed, 97 insertions(+), 60 deletions(-) diff --git a/cv_bridge/CMakeLists.txt b/cv_bridge/CMakeLists.txt index 00e7c225b..6ef5c91bf 100644 --- a/cv_bridge/CMakeLists.txt +++ b/cv_bridge/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.5) project(cv_bridge) find_package(ament_cmake_ros REQUIRED) @@ -33,7 +33,7 @@ if(NOT ANDROID) endif() endif() else() - find_package(Boost REQUIRED COMPONENTS python) + find_package(Boost REQUIRED) endif() find_package(rcpputils REQUIRED) @@ -79,10 +79,14 @@ ament_export_dependencies( sensor_msgs ) -ament_export_targets(export_${PROJECT_NAME}) +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) # install the include folder -install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME}) +install( + DIRECTORY include/${PROJECT_NAME}/ + DESTINATION include/${PROJECT_NAME} +) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin diff --git a/cv_bridge/src/CMakeLists.txt b/cv_bridge/src/CMakeLists.txt index 7eea3ee38..71c96bd87 100644 --- a/cv_bridge/src/CMakeLists.txt +++ b/cv_bridge/src/CMakeLists.txt @@ -2,20 +2,17 @@ add_library(${PROJECT_NAME} cv_bridge.cpp rgb_colors.cpp) include(GenerateExportHeader) generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${PROJECT_NAME}/${PROJECT_NAME}_export.h) -target_include_directories(${PROJECT_NAME} PUBLIC - "$" - "$" - "$") -target_link_libraries(${PROJECT_NAME} PUBLIC - ${sensor_msgs_TARGETS} - opencv_core - opencv_imgproc - opencv_imgcodecs) -target_link_libraries(${PROJECT_NAME} PRIVATE - Boost::headers - rcpputils::rcpputils) - -install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} +target_include_directories(${PROJECT_NAME} + PUBLIC "$" + ${PROJECT_SOURCE_DIR}/include + ${Boost_INCLUDE_DIRS}) +ament_target_dependencies(${PROJECT_NAME} + "OpenCV" + "sensor_msgs" +) +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBRARIES} rcpputils::rcpputils) + +install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin @@ -23,25 +20,56 @@ install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}_export.h - DESTINATION include/${PROJECT_NAME}/${PROJECT_NAME}) + DESTINATION include/${PROJECT_NAME}) if(NOT ANDROID) - find_package(Python3 REQUIRED COMPONENTS Development NumPy) +# add a Boost Python library +find_package(PythonInterp REQUIRED) +find_package(PythonLibs "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") - Python3_add_library(${PROJECT_NAME}_boost MODULE module.cpp module_opencv3.cpp) - target_link_libraries(${PROJECT_NAME}_boost PRIVATE - ${PROJECT_NAME} - Boost::python - Python3::NumPy) - target_compile_definitions(${PROJECT_NAME}_boost PRIVATE PYTHON3) +# Get the numpy include directory from its python module +if(NOT PYTHON_NUMPY_INCLUDE_DIR) + execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.get_include())" + RESULT_VARIABLE PYTHON_NUMPY_PROCESS + OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) - if(OpenCV_VERSION_MAJOR VERSION_EQUAL 4) - target_compile_definitions(${PROJECT_NAME}_boost PRIVATE OPENCV_VERSION_4) + if(PYTHON_NUMPY_PROCESS EQUAL 0) + file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" PYTHON_NUMPY_INCLUDE_CMAKE_PATH) + set(PYTHON_NUMPY_INCLUDE_DIR ${PYTHON_NUMPY_INCLUDE_CMAKE_PATH} CACHE PATH "Numpy include directory") + else() + message(SEND_ERROR "Could not determine the NumPy include directory, verify that NumPy was installed correctly.") endif() +endif() + +include_directories(${PYTHON_INCLUDE_PATH} ${PYTHON_NUMPY_INCLUDE_DIR}) + +if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3) + add_definitions(-DPYTHON3) +endif() + +if(OpenCV_VERSION_MAJOR VERSION_EQUAL 4) + add_definitions(-DOPENCV_VERSION_4) +endif() + +if(OpenCV_VERSION_MAJOR VERSION_LESS 3) + add_library(${PROJECT_NAME}_boost module.cpp module_opencv2.cpp) +else() + add_library(${PROJECT_NAME}_boost module.cpp module_opencv3.cpp) +endif() +target_link_libraries(${PROJECT_NAME}_boost + ${PYTHON_LIBRARIES} + ${PROJECT_NAME} +) +set_target_properties(${PROJECT_NAME}_boost PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost/ + PREFIX "" +) +if(APPLE) set_target_properties(${PROJECT_NAME}_boost PROPERTIES - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/boost/ - PREFIX "" - ) - install(TARGETS ${PROJECT_NAME}_boost DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/boost/) + SUFFIX ".so") +endif() + +install(TARGETS ${PROJECT_NAME}_boost DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME}/boost/) endif() diff --git a/cv_bridge/test/CMakeLists.txt b/cv_bridge/test/CMakeLists.txt index 1bf4ef77f..cbc03e98d 100644 --- a/cv_bridge/test/CMakeLists.txt +++ b/cv_bridge/test/CMakeLists.txt @@ -21,10 +21,8 @@ ament_add_gtest(${PROJECT_NAME}-utest APPEND_LIBRARY_DIRS "${cv_bridge_lib_dir}") target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME} - Boost::headers - opencv_core - opencv_imgcodecs - ${sensor_msgs_TARGETS}) + ${OpenCV_LIBRARIES} +) # enable cv_bridge python tests find_package(ament_cmake_pytest REQUIRED) diff --git a/image_geometry/CMakeLists.txt b/image_geometry/CMakeLists.txt index 0e330915c..a76aadf57 100644 --- a/image_geometry/CMakeLists.txt +++ b/image_geometry/CMakeLists.txt @@ -18,40 +18,47 @@ endif() find_package(OpenCV REQUIRED COMPONENTS calib3d core highgui imgproc) find_package(sensor_msgs REQUIRED) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include + ${OpenCV_INCLUDE_DIRS} +) + +# add a library add_library(${PROJECT_NAME} - src/pinhole_camera_model.cpp - src/stereo_camera_model.cpp + src/pinhole_camera_model.cpp src/stereo_camera_model.cpp +) +target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES}) +ament_target_dependencies( + ${PROJECT_NAME} + OpenCV + sensor_msgs +) + +install(DIRECTORY include/${PROJECT_NAME}/ + DESTINATION include/${PROJECT_NAME} ) -target_include_directories(${PROJECT_NAME} PUBLIC - "$" - "$") -target_link_libraries(${PROJECT_NAME} PUBLIC - opencv_calib3d - opencv_core - opencv_highgui - opencv_imgproc - ${sensor_msgs_TARGETS}) - -install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME}) # Causes the visibility macros to use dllexport rather than dllimport, # which is appropriate when building the dll but not consuming it. target_compile_definitions(${PROJECT_NAME} PRIVATE "IMAGE_GEOMETRY_BUILDING_DLL") -install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} +install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +# image_geometry_lib_dir is passed as APPEND_LIBRARY_DIRS for each ament_add_gtest call so +# the project library that they link against is on the library path. +# This is especially important on Windows. +# This is overwritten each loop, but which one it points to doesn't really matter. +set(image_geometry_lib_dir "$") + +# add tests if(BUILD_TESTING) - find_package(ament_cmake_gtest REQUIRED) - ament_add_gtest(${PROJECT_NAME}-utest test/utest.cpp) - target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME}) + add_subdirectory(test) endif() -ament_export_targets(export_${PROJECT_NAME}) +ament_export_libraries(${PROJECT_NAME}) ament_export_dependencies(OpenCV) -ament_export_dependencies(sensor_msgs) - +ament_export_include_directories(include) ament_package() diff --git a/image_geometry/test/CMakeLists.txt b/image_geometry/test/CMakeLists.txt index 3c52fe506..e4dd8ea83 100644 --- a/image_geometry/test/CMakeLists.txt +++ b/image_geometry/test/CMakeLists.txt @@ -4,8 +4,8 @@ find_package(ament_cmake_gtest REQUIRED) # ament_add_pytest_test(directed.py "directed.py") -ament_add_gtest(${PROJECT_NAME}-utest utest.cpp) -target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME}) +ament_add_gtest(${PROJECT_NAME}-utest utest.cpp APPEND_LIBRARY_DIRS "${image_geometry_lib_dir}") +target_link_libraries(${PROJECT_NAME}-utest ${PROJECT_NAME} ${OpenCV_LIBS}) -ament_add_gtest(${PROJECT_NAME}-utest-equi utest_equi.cpp) -target_link_libraries(${PROJECT_NAME}-utest-equi ${PROJECT_NAME}) +ament_add_gtest(${PROJECT_NAME}-utest-equi utest_equi.cpp APPEND_LIBRARY_DIRS "${image_geometry_lib_dir}") +target_link_libraries(${PROJECT_NAME}-utest-equi ${PROJECT_NAME} ${OpenCV_LIBS})