Skip to content

Commit 45d5b3d

Browse files
committed
Extend setup cmake ability
Summary: For executorch users, we see a common pattern that they have to: ```bash bash install_requirements.sh --pybind xnnpack cmake -S . -Bcmake-out ... cmake --build ... ``` This is repeating cmake build twice, the first one is inside setup.py. Here I'm adding a way to allow setup.py to install the libraries seperately, by passing `CMAKE_ARGS` and `CMAKE_BUILD_ARGS` into setup.py, through `install_requirements.sh`. After this change, user can do: ```bash export CMAKE_ARGS="-DCMAKE_INSTALL_PREFIX=<install dir> \ -DEXECUTORCH_BUILD_OPTIMIZED=ON \ ..." export CMAKE_BUILD_ARGS="--target install" bash install_requirements.sh --pybind xnnpack ``` Then we should be able to find `libxnnpack.a` `liboptimized_ops_lib.a` etc under install dir. Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent 590cbce commit 45d5b3d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

extension/data_loader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ target_compile_options(extension_data_loader PUBLIC ${_common_compile_options})
2525
# Install libraries
2626
install(
2727
TARGETS extension_data_loader
28-
DESTINATION ${CMAKE_BINARY_DIR}/lib
28+
DESTINATION lib
2929
INCLUDES
3030
DESTINATION ${_common_include_directories})

install_requirements.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fi
2727

2828
# Parse options.
2929
EXECUTORCH_BUILD_PYBIND=OFF
30-
CMAKE_ARGS=""
3130

3231
for arg in "$@"; do
3332
case $arg in
@@ -110,4 +109,5 @@ $PIP_EXECUTABLE install --extra-index-url "${TORCH_NIGHTLY_URL}" \
110109

111110
EXECUTORCH_BUILD_PYBIND="${EXECUTORCH_BUILD_PYBIND}" \
112111
CMAKE_ARGS="${CMAKE_ARGS}" \
112+
CMAKE_BUILD_ARGS="${CMAKE_BUILD_ARGS}" \
113113
$PIP_EXECUTABLE install . --no-build-isolation -v

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ def run(self):
398398
if "CMAKE_ARGS" in os.environ:
399399
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
400400

401+
# Allow adding extra build args through the environment. Used by some
402+
# tests and demos to expand the set of targets included in the pip
403+
# package.
404+
if "CMAKE_BUILD_ARGS" in os.environ:
405+
build_args += [
406+
item for item in os.environ["CMAKE_BUILD_ARGS"].split(" ") if item
407+
]
408+
401409
# Put the cmake cache under the temp directory, like
402410
# "pip-out/temp.<plat>/cmake-out".
403411
cmake_cache_dir = os.path.join(repo_root, self.build_temp, "cmake-out")

0 commit comments

Comments
 (0)