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



##########
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:
       In normal use (not test use), users run `cmake --build ... --target 
install` before they use this module, right?
   If it's correct, `arrow.dll` should be located in the same directory as 
`arrow_matlab.dll` and `mexfcn.mexw64` by `cmake --build ... --target install`.
   
   If your explanation is correct (we need this for not test use too), we 
should use `install()`  
https://cmake.org/cmake/help/latest/command/install.html instead of 
`add_custom_target()`.
   
   I think that we can use one of them:
   
     * `install(IMPORTED_RUNTIME_ARTIFACTS)`: 
https://cmake.org/cmake/help/latest/command/install.html#imported-runtime-artifacts
       * This requires CMake 3.21.
     * install(FILES)`:  
https://cmake.org/cmake/help/latest/command/install.html#files




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