Skip to content

Commit c13c03a

Browse files
andrestrakerSSingh5845
authored andcommitted
CMakeLists.txt updates to copy the pyd file for Windows.
1 parent 6098fb5 commit c13c03a

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed
Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
cmake_minimum_required(VERSION 3.14)
22

3-
# IMPORTANT: Ensure the aditof target (which builds aditof.dll) is defined
4-
# BEFORE this copying logic runs. For example:
5-
# add_subdirectory(libaditof/sdk) # (Adjust path to where aditof target is defined)
3+
# Ensure aditof (and optionally aditofpython) targets are defined before this file's copy logic.
64

75
function(PopulateforPython targetdir)
86
add_subdirectory(${targetdir})
9-
# Optional: collect Python sources if you want to use them later
107
file(GLOB PythonSources "${CMAKE_CURRENT_SOURCE_DIR}/${targetdir}/*.py")
118
endfunction()
129

13-
# List of Python example directories (relative to this CMakeLists.txt)
1410
set(PY_EXAMPLES
1511
dnn
1612
first_frame
@@ -22,17 +18,14 @@ set(PY_EXAMPLES
2218
showPointCloud
2319
)
2420

25-
# Unconditionally add all example subdirectories
2621
foreach(ex ${PY_EXAMPLES})
2722
PopulateforPython("${ex}")
2823
endforeach()
2924

30-
# Copy .so files to each Python example directory
3125
if (NOT WIN32)
3226
if (TARGET aditof AND TARGET aditofpython)
33-
# Single aggregate target that depends on both libraries
3427
add_custom_target(copy_so_to_python_examples ALL
35-
COMMENT "Copying aditof.so and aditofpython.so to Python example directories."
28+
COMMENT "Copying aditofpython shared object to Python example directories (non-Windows)."
3629
)
3730
add_dependencies(copy_so_to_python_examples aditof aditofpython)
3831

@@ -44,38 +37,71 @@ if (NOT WIN32)
4437
COMMAND ${CMAKE_COMMAND} -E copy_if_different
4538
"$<TARGET_FILE:aditofpython>"
4639
"${CMAKE_CURRENT_BINARY_DIR}/${ex}/"
47-
COMMENT "Copied aditof.so and aditofpython.so to ${ex}"
40+
COMMENT "Copied aditofpython to ${ex}"
4841
)
4942
endforeach()
5043
else()
51-
message(WARNING
52-
"Targets 'aditof' or 'aditofpython' not found. Define them before this point.")
44+
message(WARNING "Targets 'aditof' or 'aditofpython' not found for non-Windows copy step.")
5345
endif()
5446
else()
55-
# Windows: copy aditof.dll (per configuration) into each example's build dir.
47+
# Windows-only copy logic.
48+
# Most likely bindings live under: <binary>/libaditof/bindings/python/<CONFIG>
49+
# Change this to ${CMAKE_BINARY_DIR}/build/libaditof/bindings/python if you truly have a nested build directory.
50+
set(ADITOF_PY_BINDINGS_BASE "${CMAKE_BINARY_DIR}/libaditof/bindings/python")
51+
52+
if (CMAKE_CONFIGURATION_TYPES)
53+
set(_ADITOF_PY_CFG "$<CONFIG>")
54+
else()
55+
if (NOT CMAKE_BUILD_TYPE)
56+
message(WARNING "CMAKE_BUILD_TYPE not set; defaulting to Release.")
57+
set(CMAKE_BUILD_TYPE "Release")
58+
endif()
59+
set(_ADITOF_PY_CFG "${CMAKE_BUILD_TYPE}")
60+
endif()
61+
62+
set(ADITOF_PY_BINDINGS_DIR "${ADITOF_PY_BINDINGS_BASE}/${_ADITOF_PY_CFG}")
63+
5664
if (TARGET aditof)
57-
# Single aggregate target that depends on 'aditof' and performs all copies.
58-
add_custom_target(copy_dll_to_examples ALL
59-
COMMENT "Copying aditof.dll to Python example directories (Windows)."
65+
add_custom_target(copy_runtime_to_examples ALL
66+
COMMENT "Copying aditof.dll and Python bindings (${_ADITOF_PY_CFG}) to Python example directories (Windows)."
6067
)
61-
add_dependencies(copy_dll_to_examples aditof)
68+
add_dependencies(copy_runtime_to_examples aditof)
69+
70+
# Optional: if a target producing the Python extension exists, depend on it too.
71+
if (TARGET aditofpython)
72+
add_dependencies(copy_runtime_to_examples aditofpython)
73+
endif()
6274

6375
foreach(ex ${PY_EXAMPLES})
76+
# Single command per example for cleaner output
6477
add_custom_command(
65-
TARGET copy_dll_to_examples
78+
TARGET copy_runtime_to_examples
6679
COMMAND ${CMAKE_COMMAND} -E make_directory
6780
"${CMAKE_CURRENT_BINARY_DIR}/${ex}"
6881
COMMAND ${CMAKE_COMMAND} -E copy_if_different
6982
"$<TARGET_FILE:aditof>"
7083
"${CMAKE_CURRENT_BINARY_DIR}/${ex}/aditof.dll"
71-
COMMENT "Copied aditof.dll to ${ex}"
84+
# Copy the entire configuration-specific bindings directory.
85+
COMMAND ${CMAKE_COMMAND} -E copy_directory
86+
"${ADITOF_PY_BINDINGS_DIR}"
87+
"${CMAKE_CURRENT_BINARY_DIR}/${ex}"
88+
COMMENT "Copied aditof.dll and Python bindings to ${ex}"
7289
)
90+
91+
# ------------------------------------------------------------------
92+
# Alternative (copy only the built Python extension module) - UNCOMMENT IF NEEDED:
93+
# if (TARGET aditofpython)
94+
# add_custom_command(
95+
# TARGET copy_runtime_to_examples
96+
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
97+
# "$<TARGET_FILE:aditofpython>"
98+
# "${CMAKE_CURRENT_BINARY_DIR}/${ex}/"
99+
# COMMENT "Copied aditofpython module to ${ex}"
100+
# )
101+
# endif()
102+
# ------------------------------------------------------------------
73103
endforeach()
74104
else()
75-
message(WARNING
76-
"Target 'aditof' not found. Define it before this point or add a fallback path.")
105+
message(WARNING "Target 'aditof' not found. Cannot copy runtime/bindings.")
77106
endif()
78-
endif()
79-
80-
# (Optional) Previous non-Windows Python install step removed since you stated Windows-only need.
81-
# If you still need install logic for other platforms, re-add it here.
107+
endif()

0 commit comments

Comments
 (0)