-
Notifications
You must be signed in to change notification settings - Fork 31
/
CMakeLists.txt
106 lines (84 loc) · 3.03 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.21.0)
project(torchdistx VERSION 0.3.0 LANGUAGES CXX)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE RelWithDebInfo)
endif()
include(cmake/Helpers.cmake)
# ------------------------------------------------------------
# Options
# ------------------------------------------------------------
include(CMakeDependentOption)
if(PROJECT_IS_TOP_LEVEL)
include(CTest)
endif()
option(TORCHDIST_BUILD_PYTHON "Generates build target for the Python C extension." ON)
option(TORCHDIST_BUILD_FOR_NATIVE "Builds for the processor type of the compiling machine." OFF)
option(TORCHDIST_TREAT_WARNINGS_AS_ERRORS "Treats compilation warnings as errors." OFF)
option(TORCHDIST_PERFORM_LTO "Performs link-time optimization." OFF)
option(TORCHDIST_INSTALL_STANDALONE "Installs with rpath." OFF)
option(TORCHDIST_RUN_CLANG_TIDY "Runs clang-tidy as static analyzer." OFF)
cmake_dependent_option(TORCHDIST_DEVELOP_PYTHON
#DESCRIPTION
"Copies the Python C extension to the source tree for `setup.py develop` mode."
#VALUE
ON
#DEPENDS_ON
TORCHDIST_BUILD_PYTHON
#FORCE
OFF
)
set(TORCHDIST_SANITIZERS
#DEFAULT
""
#TYPE
CACHE STRING
#DESCRIPTION
"The list of sanitizers with which to build. The supported values are 'asan', 'ubsan', and 'tsan'."
)
set_property(CACHE TORCHDIST_SANITIZERS PROPERTY
STRINGS
"" "asan" "ubsan" "tsan"
)
# ------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------
if(TORCHDIST_BUILD_PYTHON)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)
if(Python3_VERSION VERSION_LESS 3.7)
message(FATAL_ERROR "Only CPython 3.7 and later versions are supported.")
endif()
# We have to ensure that we use a version of pybind11 that is ABI compatible
# with PyTorch's version.
torchdist_add_third_party(pybind11)
else()
find_package(Python3 OPTIONAL COMPONENTS Interpreter)
endif()
if(Python3_EXECUTABLE)
execute_process(
COMMAND
${Python3_EXECUTABLE} -c "import torch; print(torch.utils.cmake_prefix_path)"
OUTPUT_VARIABLE
torch_cmake_prefix_path
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
find_package(Torch 1.13 REQUIRED PATHS ${torch_cmake_prefix_path})
# ------------------------------------------------------------
# Targets
# ------------------------------------------------------------
add_subdirectory(src/cc/torchdistx)
if(TORCHDIST_BUILD_PYTHON)
add_subdirectory(src/python/torchdistx/_C)
endif()
torchdist_install_package(torchdistx
#CONFIG_FILE
src/cc/torchdistx-config.cmake.in
)
if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
#TODO: Add catch2 tests.
endif()