Skip to content

Commit 45457a0

Browse files
committed
Change CMake system.
1 parent 6668e67 commit 45457a0

9 files changed

Lines changed: 442 additions & 229 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ libtorch/
4545
build-release/
4646
libtorch_static/
4747
examples/vgg/**/*.pt
48-
segmentation_models.pytorch/
48+
segmentation_models.pytorch/
49+
.idea/
50+
cmake-build-debug/

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ add_custom_command(
292292

293293
# ./vgg images/frog.jpg
294294

295+
add_subdirectory(bridge)
296+
295297
add_subdirectory(examples)
296298
add_subdirectory("test")
297299
add_subdirectory(demos)

bridge/CMakeLists.txt

Lines changed: 10 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -1,223 +1,14 @@
1-
cmake_minimum_required(VERSION 3.31 FATAL_ERROR)
2-
# project(MyProject LANGUAGES CXX)
1+
add_library(BridgeUtil INTERFACE)
32

4-
include(CMakePrintHelpers)
5-
6-
# set(CMAKE_VERBOSE_MAKEFILE ON)
7-
8-
if(UNIX AND NOT APPLE)
9-
set(LINUX TRUE)
10-
endif()
11-
12-
set(CMAKE_C_COMPILER "clang")
13-
set(CMAKE_CXX_COMPILER "clang++")
14-
set(CMAKE_CXX_STANDARD 17)
15-
16-
17-
set(PROJECT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
18-
set(PROJECT_BINARY_DIR "${CMAKE_BINARY_DIR}")
19-
20-
21-
# For ExternalProject_Add
22-
include(FetchContent)
23-
include(ExternalProject)
24-
25-
# ------------------------------------------------------------------------------
26-
# 1) External project: build PyTorch (libtorch) from source as STATIC
27-
# ------------------------------------------------------------------------------
28-
29-
# Where to place PyTorch after installation
30-
# set(PYTORCH_INSTALL_DIR "${PROJECT_BINARY_DIR}/pytorch-install")
31-
# set(PYTORCH_BUILD_DIR "${PROJECT_BINARY_DIR}/pytorch-prefix/src/pytorch-build")
32-
33-
# set(PYTORCH_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/pytorch-install-prefix")
34-
# file(MAKE_DIRECTORY "${PYTORCH_INSTALL_PREFIX}")
35-
36-
# ExternalProject_Add can fetch from Git, a local path, or a release tarball.
37-
# Here, for simplicity, we'll fetch from Git. In practice, you might want
38-
# a fixed commit or a release tarball for reproducible builds.
39-
40-
# ExternalProject_Add(
41-
# pytorch
42-
# GIT_REPOSITORY https://github.com/pytorch/pytorch.git
43-
# GIT_TAG v2.6.0 # Example: specify a particular release
44-
# UPDATE_COMMAND "" # Don’t auto-run 'git pull'
45-
# PATCH_COMMAND "" # No custom patch step
46-
47-
# # DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/pytorch-download" # Where to download the repo
48-
49-
# # We need all PyTorch submodules. By default, ExternalProject won't do submodule init.
50-
# # So we can do that in a separate step if we want a full build. For a minimal CPU build,
51-
# # you might not need them all, but let's be safe:
52-
# STEP_TARGETS clone
53-
# # After 'clone', run "git submodule update --init --recursive"
54-
# # to fetch all submodules.
55-
# # We can use a little trick with COMMAND.
56-
# # PATCH_COMMAND "git submodule update --init --recursive"
57-
58-
# # CMAKE_ARGS
59-
# # -DBUILD_SHARED_LIBS=OFF # Build static libraries
60-
# # -DBUILD_PYTHON=OFF # Don’t build Python bindings
61-
# # -DBUILD_TEST=OFF # Don’t build tests
62-
# # -DUSE_CUDA=OFF # Disable CUDA
63-
# # -DUSE_CUDNN=OFF # Disable cuDNN
64-
# # -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
65-
# # # -DBUILD_BINARY=ON
66-
# # # -DUSE_DISTRIBUTED=ON
67-
# # # -DBUILD_STATIC_RUNTIME_BENCHMARK=ON
68-
# # # -DBUILD_LITE_INTERPRETER=ON
69-
# # # -DUSE_STATIC_MKL=ON
70-
# # # -DSTATIC_DISPATCH_BACKEND=ON
71-
# # # -DCAFFE2_USE_MSVC_STATIC_RUNTIME=ON
72-
# # # -DUSE_DISTRIBUTED=ON
73-
# # # -DCMAKE_BUILD_TYPE=Release
74-
# # -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
75-
# # # -DCMAKE_POLICY_VERSION_MINIMUM=3.5
76-
# CMAKE_ARGS
77-
# -DBUILD_SHARED_LIBS=OFF # Build static libraries
78-
# -DBUILD_PYTHON=OFF # Don’t build Python bindings
79-
# -DBUILD_TEST=OFF # Don’t build tests
80-
# -DUSE_CUDA=OFF # Disable CUDA
81-
# -DUSE_CUDNN=OFF # Disable cuDNN
82-
# -DUSE_MKLDNN=OFF # Disable MKLDNN for simplicity
83-
# -DCMAKE_BUILD_TYPE=Release
84-
# -DCMAKE_INSTALL_PREFIX=${PYTORCH_INSTALL_DIR}
85-
86-
# INSTALL_DIR ${PYTORCH_INSTALL_DIR} # Where to install
87-
88-
# # LOG_DOWNLOAD ON
89-
# # LOG_UPDATE ON
90-
# # LOG_PATCH ON
91-
# # LOG_CONFIGURE ON
92-
# # LOG_BUILD ON
93-
# # LOG_INSTALL ON
94-
95-
# )
96-
97-
set(PYTORCH_INSTALL_DIR "${PROJECT_ROOT_DIR}/libtorch")
98-
# file(GLOB_RECURSE PYTORCH_INCLUDES "${PYTORCH_INSTALL_DIR}/include" "*.h")
99-
# file(GLOB_RECURSE PYTORCH_LIBS "${PYTORCH_INSTALL_DIR}/lib" "*.a")
100-
101-
102-
# set(PYTORCH_LIBS_LINKER_ARGS "-L/Users/jade/Development/libtorch/libtorch/lib") # Will hold the list of "-l..." flags.
103-
# foreach(lib_path IN LISTS PYTORCH_LIBS)
104-
# # Get just the filename without the directory or extension
105-
# get_filename_component(lib_name "${lib_path}" NAME_WE)
106-
# # If it starts with "lib", strip that off
107-
# string(REGEX REPLACE "^lib" "" lib_name "${lib_name}")
108-
# # Now prepend "-l" to the actual library name
109-
# list(APPEND MY_LIBS "-l${lib_name}")
110-
# endforeach()
111-
112-
113-
find_package(chpl REQUIRED HINTS ${PROJECT_ROOT_DIR}/cmake/chapel)
114-
list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake")
115-
list(APPEND CMAKE_MODULE_PATH "${PROJECT_ROOT_DIR}/cmake/chapel")
116-
117-
project(MyProject LANGUAGES CXX C CHPL)
118-
119-
# ------------------------------------------------------------------------------
120-
# 2) Create an INTERFACE library to wrap the installed static libs
121-
# ------------------------------------------------------------------------------
122-
123-
# We'll create a dummy target that depends on 'pytorch' so that
124-
# building your own code will first build/install PyTorch.
125-
126-
# add_library(torch_interface INTERFACE)
127-
128-
# # Ensure that our 'torch_interface' target isn't used until PyTorch is built
129-
# # add_dependencies(torch_interface pytorch)
130-
131-
# # Include directories for PyTorch
132-
# target_include_directories(torch_interface INTERFACE
133-
# "${PYTORCH_INSTALL_DIR}/include"
134-
# "${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
135-
# # "${PYTORCH_BUILD_DIR}/aten/src/include"
136-
# )
137-
138-
# # Link the relevant static libraries. For a minimal CPU-only build,
139-
# # you'll likely need at least these (names can vary by version).
140-
# # The exact set can differ depending on which components got built.
141-
142-
# target_link_libraries(torch_interface INTERFACE
143-
# "${PYTORCH_INSTALL_DIR}/lib/libtorch.a"
144-
# "${PYTORCH_INSTALL_DIR}/lib/libtorch_cpu.a"
145-
# "${PYTORCH_INSTALL_DIR}/lib/libc10.a"
146-
147-
# # ${PYTORCH_LIBS}
148-
149-
# # System libraries often needed:
150-
# pthread
151-
# dl
152-
# rt
153-
# )
154-
155-
156-
157-
add_executable(CHPLTest lib/CHPLTest.chpl)
158-
159-
160-
add_library(torchbridge OBJECT "${PROJECT_ROOT_DIR}/lib/bridge.cpp" "${PROJECT_ROOT_DIR}/include/bridge.h")
161-
# add_dependencies(torchbridge torch_interface)
162-
163-
target_include_directories(torchbridge PRIVATE
164-
"${PYTORCH_INSTALL_DIR}/include"
165-
"${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
166-
"${PROJECT_ROOT_DIR}/include"
167-
# # "${PYTORCH_BUILD_DIR}/aten/src/include"
3+
# Tell consumers where to find the headers
4+
target_include_directories(BridgeUtil
5+
INTERFACE # usage requirement
6+
${CMAKE_CURRENT_SOURCE_DIR}/util
1687
)
169-
# target_link_directories(torchbridge PUBLIC
170-
# "${PYTORCH_INSTALL_DIR}/lib"
171-
# )
172-
# target_link_libraries(torchbridge
173-
# PRIVATE
174-
# # torch_interface
175-
# # ${PYTORCH_LIBS}
176-
177-
# pthread
178-
# dl
179-
# rt
180-
# )
181-
182-
183-
184-
185-
186-
add_executable(Bridge lib/Bridge.chpl include/bridge.h)
187-
# add_dependencies(TorchBridge torchbridge)
188-
add_dependencies(Bridge torchbridge)
189-
190-
target_link_options(Bridge
191-
PRIVATE
192-
"${PROJECT_ROOT_DIR}/include/bridge.h"
193-
"-L${PROJECT_BINARY_DIR}"
194-
# "-ltorchbridge"
195-
# -L.
196-
"-ltorchbridge"
197-
# "-I${PROJECT_BINARY_DIR}"
198-
"-L${PYTORCH_INSTALL_DIR}/lib"
199-
# "-I${PYTORCH_INSTALL_DIR}/include"
200-
# "-I${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include"
201-
"-ltorch"
202-
"-ltorch_cpu"
203-
# "-lcpuinfo"
204-
"-lc10"
205-
# "-lsleef"
206-
# "-lclog"
207-
# "-lprotoc"
208-
# ${PYTORCH_LIBS_LINKER_ARGS}
209-
# "-lpthread"
210-
# "-ldl"
211-
)
212-
213-
214-
215-
# ------------------------------------------------------------------------------
216-
# 3) Build your own executable that uses torch_interface
217-
# ------------------------------------------------------------------------------
218-
219-
# add_executable(my_app src/main.cpp)
2208

221-
# # Link your app against our interface library
222-
# target_link_libraries(my_app PRIVATE torch_interface)
9+
# (optional) expose compile options / definitions
10+
# target_compile_features(myheaders INTERFACE cxx_std_20)
11+
# target_compile_definitions(myheaders INTERFACE MYLIB_USE_SOMETHING=1)
22312

13+
# (optional) make an alias so callers can use myproject::myheaders
14+
# add_library(BridgeUtil::myheaders ALIAS myheaders)

0 commit comments

Comments
 (0)