kou commented on code in PR #34563:
URL: https://github.com/apache/arrow/pull/34563#discussion_r1137743156
##########
matlab/CMakeLists.txt:
##########
@@ -202,13 +207,12 @@ endif()
option(MATLAB_BUILD_TESTS "Build the C++ tests for the MATLAB interface" OFF)
-# Grab CMAKE Modules from the CPP interface.
-set(CPP_CMAKE_MODULES "${CMAKE_SOURCE_DIR}/../cpp/cmake_modules")
-if(EXISTS "${CPP_CMAKE_MODULES}")
- set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CPP_CMAKE_MODULES})
-endif()
+# Add tools/cmake directory to the CMAKE_MODULE_PATH.
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/tools/cmake)
Review Comment:
How about using `list(PREPEND)`?
https://cmake.org/cmake/help/latest/command/list.html#prepend
```suggestion
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/tools/cmake)
```
##########
matlab/CMakeLists.txt:
##########
@@ -32,8 +32,13 @@ function(build_arrow)
message(SEND_ERROR "Error: unrecognized arguments:
${ARG_UNPARSED_ARGUMENTS}")
endif()
- # If Arrow needs to be built, the default location will be within the build
tree.
- set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix")
+ # If Arrow build available, set ARROW_PREFIX to the ARROW_HOME specified
with cmake.
+ if(Arrow_FOUND)
+ set(ARROW_PREFIX "${ARROW_HOME}")
+ else()
+ # If Arrow needs to be built, the default location will be within the
build tree.
+ set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep-prefix")
+ endif()
Review Comment:
Do we need this change?
If we use system Arrow C++, we don't link to `arrow_shared_for_gtest`. So
all `arrow_shared_for_gtest` related properties are ignored.
##########
matlab/CMakeLists.txt:
##########
@@ -202,13 +207,12 @@ endif()
option(MATLAB_BUILD_TESTS "Build the C++ tests for the MATLAB interface" OFF)
-# Grab CMAKE Modules from the CPP interface.
-set(CPP_CMAKE_MODULES "${CMAKE_SOURCE_DIR}/../cpp/cmake_modules")
-if(EXISTS "${CPP_CMAKE_MODULES}")
- set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CPP_CMAKE_MODULES})
-endif()
+# Add tools/cmake directory to the CMAKE_MODULE_PATH.
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/tools/cmake)
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules)
+# Get find_package(Arrow) by setting Arrow_DIR to CPP interface
ArrowConfig.cmake
+# TODO: Make sure this works on all platforms submitting
+set(CMAKE_PREFIX_PATH "${ARROW_HOME}/lib/cmake/Arrow")
Review Comment:
If we want to use `CMAKE_PREFIX_PATH`, this should be `set(CMAKE_PREFIX_PATH
"${ARROW_HOME}")`.
But using `Arrow_ROOT` or `Arrow_DIR` is better than `CMAKE_PREFIX_PATH`
because `CMAKE_PREFIX_PATH` affects all `find_package(XXX)`:
```cmake
if(ARROW_HOME AND NOT Arrow_ROOT)
set(Arrow_ROOT "${ARROW_HOME}")
end
```
See also:
https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
##########
matlab/tools/cmake/BuildMatlabArrowInterface.cmake:
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# -------
+# Config
+# -------
+
+# Build configuration for libmexclass.
+set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp")
+set(CUSTOM_PROXY_FACTORY_SOURCES
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc")
+set(CUSTOM_PROXY_SOURCES
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc")
+set(CUSTOM_PROXY_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}")
+set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB})
+# On Windows, arrow.dll must be installed regardless of
+# whether Arrow_FOUND is true or false. Therefore, we explicitly
+# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy.
+set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB})
+set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h")
+set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory")
Review Comment:
It seems that libmexclass's build process uses files in this repository.
Can we reconsider this approach? I think that this approach has the
following problems:
* We can't use CMake targets to link. (We need to extract library path,
include path and so on manually from CMake targets as you did.)
* It's difficult to control how to build our sources in our CMake.
I'm familiar with libmexclass but how about the following approach?
* libmexclass provides a library and a CMake package that don't depend on
external files (files in our repository)
* The CMake package provides a helper function to use the libmexclass
library easily (Or the CMake package provides a CMake target)
* We build our source files with the libmexclass library in our CMake
configurations (`target_link_libraries()` and so on) instead of
`ExternalProject_Add()`
##########
matlab/tools/cmake/BuildMatlabArrowInterface.cmake:
##########
@@ -0,0 +1,80 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# -------
+# Config
+# -------
+
+# Build configuration for libmexclass.
+set(CUSTOM_PROXY_FACTORY_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy;${CMAKE_SOURCE_DIR}/src/cpp")
+set(CUSTOM_PROXY_FACTORY_SOURCES
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/proxy/factory.cc")
+set(CUSTOM_PROXY_SOURCES
"${CMAKE_SOURCE_DIR}/src/cpp/arrow/matlab/array/proxy/float64_array.cc")
+set(CUSTOM_PROXY_INCLUDE_DIR
"${CMAKE_SOURCE_DIR}/src/cpp;${ARROW_INCLUDE_DIR}")
+set(CUSTOM_PROXY_LINK_LIBRARIES ${ARROW_LINK_LIB})
+# On Windows, arrow.dll must be installed regardless of
+# whether Arrow_FOUND is true or false. Therefore, we explicitly
+# copy ARROW_SHARED_LIB to the installation folder +libmexclass/+proxy.
+set(CUSTOM_PROXY_RUNTIME_LIBRARIES ${ARROW_SHARED_LIB})
+set(CUSTOM_PROXY_FACTORY_HEADER_FILENAME "factory.h")
+set(CUSTOM_PROXY_FACTORY_CLASS_NAME "arrow::matlab::proxy::Factory")
+
+# -------
+# Build
+# -------
+
+# Build libmexclass as an external project.
+include(ExternalProject)
+ExternalProject_Add(
+ libmexclass
+ # TODO: Consider using SSH URL for the Git Repository when
+ # libmexclass is accessible for CI without permission issues.
+ GIT_REPOSITORY https://github.com/mathworks/libmexclass.git
+ GIT_TAG main
+ SOURCE_SUBDIR libmexclass/cpp
+ CMAKE_CACHE_ARGS "-D
CUSTOM_PROXY_FACTORY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_FACTORY_INCLUDE_DIR}"
+ "-D
CUSTOM_PROXY_FACTORY_SOURCES:STRING=${CUSTOM_PROXY_FACTORY_SOURCES}"
+ "-D CUSTOM_PROXY_SOURCES:STRING=${CUSTOM_PROXY_SOURCES}"
+ "-D
CUSTOM_PROXY_INCLUDE_DIR:STRING=${CUSTOM_PROXY_INCLUDE_DIR}"
+ "-D
CUSTOM_PROXY_LINK_LIBRARIES:STRING=${CUSTOM_PROXY_LINK_LIBRARIES}"
+ "-D
CUSTOM_PROXY_RUNTIME_LIBRARIES:STRING=${CUSTOM_PROXY_RUNTIME_LIBRARIES}"
+ "-D
CUSTOM_PROXY_FACTORY_HEADER_FILENAME:STRING=${CUSTOM_PROXY_FACTORY_HEADER_FILENAME}"
+ "-D
CUSTOM_PROXY_FACTORY_CLASS_NAME:STRING=${CUSTOM_PROXY_FACTORY_CLASS_NAME}"
+ INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install
Review Comment:
This may be redundant.
--
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]