lafiona commented on a change in pull request #12004:
URL: https://github.com/apache/arrow/pull/12004#discussion_r789144232



##########
File path: matlab/CMakeLists.txt
##########
@@ -212,56 +233,113 @@ if(MATLAB_BUILD_TESTS)
     # C++ libraries that are built from source.
     build_arrow(BUILD_GTEST)
   else()
+    # GTest is found, on Windows, IMPORTED_LOCATION needs to be set to 
indicate where the shared
+    # libraries live
+    if(WIN32)
+      set(GTEST_SHARED_LIB_DIR "${GTEST_ROOT}/bin")
+      set(GTEST_SHARED_LIBRARY_FILENAME
+          "${CMAKE_SHARED_LIBRARY_PREFIX}gtest${CMAKE_SHARED_LIBRARY_SUFFIX}")
+      set(GTEST_SHARED_LIBRARY_LIB
+          "${GTEST_SHARED_LIB_DIR}/${GTEST_SHARED_LIBRARY_FILENAME}")
+
+      set(GTEST_MAIN_SHARED_LIB_DIR "${GTEST_ROOT}/bin")
+      set(GTEST_MAIN_SHARED_LIBRARY_FILENAME
+          
"${CMAKE_SHARED_LIBRARY_PREFIX}gtest_main${CMAKE_SHARED_LIBRARY_SUFFIX}")
+      set(GTEST_MAIN_SHARED_LIBRARY_LIB
+          "${GTEST_MAIN_SHARED_LIB_DIR}/${GTEST_MAIN_SHARED_LIBRARY_FILENAME}")
+
+      set_target_properties(GTest::gtest PROPERTIES IMPORTED_LOCATION
+                                                    
"${GTEST_SHARED_LIBRARY_LIB}")
+
+      set_target_properties(GTest::gtest_main
+                            PROPERTIES IMPORTED_LOCATION
+                                       "${GTEST_MAIN_SHARED_LIBRARY_LIB}")
+    endif()
+
     find_package(Arrow)
     if(NOT Arrow_FOUND)
       # Trigger an automatic build of the Arrow C++ libraries.
       build_arrow()
     endif()
   endif()
+
 else()
   find_package(Arrow)
   if(NOT Arrow_FOUND)
     build_arrow()
   endif()
 endif()
 
+# On Windows: copy arrow.dll into the directory where the MATLAB C++ tests 
reside,
+# since Windows require runtime DLLs that are depended on by executables to be 
in
+# the same directory (or on the %PATH%).
+if(WIN32)
+  get_property(ARROW_SHARED_LIB
+               TARGET arrow_shared
+               PROPERTY IMPORTED_LOCATION)
+
+  add_custom_target(copy_arrow_to_build_output_dir ALL
+                    COMMAND ${CMAKE_COMMAND} -E make_directory 
${MATLAB_BUILD_OUTPUT_DIR}
+                    COMMAND ${CMAKE_COMMAND} -E copy_if_different 
${ARROW_SHARED_LIB}
+                            ${MATLAB_BUILD_OUTPUT_DIR}
+                    COMMENT "Start copying arrow.dll from ${ARROW_SHARED_LIB} 
to ${MATLAB_BUILD_OUTPUT_DIR}"
+  )

Review comment:
       Thank you for this feedback, @kou! I have thought more about how we are 
structuring the source files and libraries for deployment.
   
   As you mentioned, it is advantageous to use `install()` to move `arrow.dll` 
to the installed location for normal use.
   
   With the previous behavior of copying to the build tree, the MATLAB tests 
were able to find `mexfcn` and its dependencies by adding the path to the build 
tree to the MATLAB Search Path. However, enabling the install step allows a 
user to install the interface files (including source files and mex functions) 
to any location that the user specifies. Therefore, we enabled options to add 
the install directory, specified by `CMAKE_INSTALL_PREFIX`, to the MATLAB 
Search Path, as part of the install step. I have updated the pull request 
description with more details to reflect the changes we have made.
   
   For running the C++ tests on Windows and macOS, the paths to 
`arrow.dll`/`libarrow.dylib` are added to the `ctest` environment to eliminate 
the need to copy at all.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to