Skip to content

Commit 3d61733

Browse files
cyyeverpytorchmergebot
authored andcommitted
Simplify CMake code (pytorch#127683)
Due to the recent adoption of find(python), it is possible to further simplify some CMake code. Pull Request resolved: pytorch#127683 Approved by: https://github.com/ezyang
1 parent df75a9d commit 3d61733

File tree

4 files changed

+6
-52
lines changed

4 files changed

+6
-52
lines changed

aten/src/ATen/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ if(UNIX AND NOT APPLE)
386386
endif(UNIX AND NOT APPLE)
387387

388388
if(UNIX)
389+
include(CheckFunctionExists)
389390
set(CMAKE_EXTRA_INCLUDE_FILES "sys/mman.h")
390391
CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
391392
if(HAVE_MMAP)

caffe2/CMakeLists.txt

+4-44
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ add_custom_command(
346346
OUTPUT
347347
${TORCH_GENERATED_CODE}
348348
COMMAND
349-
"${Python_EXECUTABLE}" tools/setup_helpers/generate_code.py
349+
Python::Interpreter tools/setup_helpers/generate_code.py
350350
--native-functions-path "aten/src/ATen/native/native_functions.yaml"
351351
--tags-path "aten/src/ATen/native/tags.yaml"
352352
$<$<BOOL:${INTERN_DISABLE_AUTOGRAD}>:--disable-autograd>
@@ -1094,7 +1094,7 @@ if(BUILD_LITE_INTERPRETER AND SELECTED_OP_LIST)
10941094
add_custom_command(
10951095
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
10961096
COMMAND
1097-
"${Python_EXECUTABLE}"
1097+
Python::Interpreter
10981098
-m tools.code_analyzer.gen_oplist
10991099
--model_file_list_path "${SELECTED_OP_LIST}"
11001100
--output_dir "${CMAKE_BINARY_DIR}/aten/src/ATen"
@@ -1109,7 +1109,7 @@ if(BUILD_LITE_INTERPRETER AND SELECTED_OP_LIST)
11091109
add_custom_command(
11101110
OUTPUT ${CMAKE_BINARY_DIR}/aten/src/ATen/selected_mobile_ops.h
11111111
COMMAND
1112-
"${Python_EXECUTABLE}"
1112+
Python::Interpreter
11131113
-m tools.lite_interpreter.gen_selected_mobile_ops_header
11141114
--yaml_file_path "${SELECTED_OP_LIST}"
11151115
--output_file_path "${CMAKE_BINARY_DIR}/aten/src/ATen"
@@ -1887,50 +1887,10 @@ endif()
18871887
# only rerun when needed.
18881888

18891889
if(BUILD_PYTHON)
1890-
# Python site-packages
1891-
# Get canonical directory for python site packages (relative to install
1892-
# location). It varies from system to system.
1893-
# We should pin the path separator to the forward slash on Windows.
1894-
# More details can be seen at
1895-
# https://github.com/pytorch/pytorch/tree/main/tools/build_pytorch_libs.bat#note-backslash-munging-on-windows
1896-
pycmd(PYTHON_SITE_PACKAGES "
1897-
import os
1898-
import sysconfig
1899-
relative_site_packages = sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), '').lstrip(os.path.sep)
1900-
print(relative_site_packages)
1901-
")
1902-
file(TO_CMAKE_PATH ${PYTHON_SITE_PACKAGES} PYTHON_SITE_PACKAGES)
1903-
set(PYTHON_SITE_PACKAGES ${PYTHON_SITE_PACKAGES} PARENT_SCOPE) # for Summary
19041890
# ---[ Options.
1905-
set(PYTHON_LIB_REL_PATH "${PYTHON_SITE_PACKAGES}" CACHE STRING "Python installation path (relative to CMake installation prefix)")
1891+
set(PYTHON_LIB_REL_PATH "${Python_SITELIB}" CACHE STRING "Python installation path (relative to CMake installation prefix)")
19061892
message(STATUS "Using ${PYTHON_LIB_REL_PATH} as python relative installation path")
1907-
# Python extension suffix
1908-
# Try to get from python through sysconfig.get_env_var('EXT_SUFFIX') first,
1909-
# fallback to ".pyd" if windows and ".so" for all others.
1910-
pycmd(PY_EXT_SUFFIX "
1911-
def get_ext_suffix():
1912-
import sys
1913-
import sysconfig
1914-
return sysconfig.get_config_var('EXT_SUFFIX')
1915-
1916-
suffix = get_ext_suffix()
1917-
if suffix is not None:
1918-
print(suffix)
1919-
else:
1920-
print()
1921-
")
1922-
if("${PY_EXT_SUFFIX}" STREQUAL "")
1923-
if(MSVC)
1924-
set(PY_EXT_SUFFIX ".pyd")
1925-
else()
1926-
set(PY_EXT_SUFFIX ".so")
1927-
endif()
1928-
endif()
19291893

1930-
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
1931-
# Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 in EmbeddingBag.cpp
1932-
set_source_files_properties(../aten/src/ATen/native/EmbeddingBag.cpp PROPERTIES COMPILE_FLAGS -Wno-attributes)
1933-
endif()
19341894

19351895
set(build_files)
19361896
foreach(python_src ${PYTHON_SRCS})

cmake/MiscCheck.cmake

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
if(UNIX)
2-
# prevent Unknown CMake command "check_function_exists".
3-
include(CheckFunctionExists)
4-
endif()
5-
include(CheckIncludeFile)
6-
include(CheckCSourceCompiles)
7-
include(CheckCSourceRuns)
8-
include(CheckCCompilerFlag)
91
include(CheckCXXSourceCompiles)
102
include(CheckCXXCompilerFlag)
113
include(CMakePushCheckState)

cmake/Modules/FindAVX.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
INCLUDE(CheckCSourceRuns)
2+
INCLUDE(CheckCSourceCompiles)
23
INCLUDE(CheckCXXSourceRuns)
34

45
SET(AVX_CODE "

0 commit comments

Comments
 (0)