@@ -126,6 +126,8 @@ if (MSVC)
126126 target_link_libraries (tvm_ffi_objs PRIVATE DbgHelp.lib)
127127 target_link_libraries (tvm_ffi_shared PRIVATE DbgHelp.lib)
128128 target_link_libraries (tvm_ffi_static PRIVATE DbgHelp.lib)
129+ # produce pdb file
130+ target_link_options (tvm_ffi_shared PRIVATE /DEBUG)
129131endif ()
130132
131133# expose the headers as public dependencies
@@ -141,24 +143,21 @@ if (NOT ${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
141143 return ()
142144endif ()
143145
144- option (TVM_FFI_USE_RELEASE_FLAGS "Set O3 with RelWithDebInfo, useful to get lineno " OFF )
146+ option (TVM_FFI_ATTACH_DEBUG_SYMBOLS "Attach debug symbols even in release mode " OFF )
145147option (TVM_FFI_BUILD_TESTS "Adding test targets." OFF )
146148
147- # related options
148- if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
149- if (TVM_FFI_USE_RELEASE_FLAGS)
150- message (STATUS "Targeting global CXX flags to -O3 for optimized build" )
151- target_compile_options (tvm_ffi_objs PRIVATE -O3 -g)
152- target_compile_options (tvm_ffi_shared PRIVATE -O3)
153- target_compile_options (tvm_ffi_static PRIVATE -O3)
149+ if (TVM_FFI_ATTACH_DEBUG_SYMBOLS)
150+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
151+ target_compile_options (tvm_ffi_objs PRIVATE -g1)
154152 endif ()
155153endif ()
156154
157-
158155include (cmake/Utils/CxxWarning.cmake)
159156include (cmake/Utils/Sanitizer.cmake)
160157
161- tvm_ffi_add_cxx_warning(tvm_ffi_objs)
158+ # remap the file name to the source directory so we can see the
159+ # exact file name in traceback relative to the project source root
160+ tvm_ffi_add_prefix_map(tvm_ffi_objs ${CMAKE_SOURCE_DIR} )
162161
163162########## Adding cpp tests ##########
164163
@@ -169,21 +168,7 @@ if (TVM_FFI_BUILD_TESTS)
169168 message (STATUS "Enable Testing" )
170169 include (cmake/Utils/AddGoogleTest.cmake)
171170 add_subdirectory (tests/cpp/)
172- endif ()
173-
174- ########## Install the related for normal cmake library ##########
175-
176- install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /include /tvm/ffi/ DESTINATION include /tvm/ffi/)
177- install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /3rdparty/dlpack/include / DESTINATION include /)
178-
179- if (WIN32 )
180- # on windows, install by target is more robust as sometimes target may
181- # append subfolders lib/Release in msbuild
182- install (TARGETS tvm_ffi_shared tvm_ffi_static DESTINATION lib)
183- else ()
184- # on mac and other platforms, install by dir helps to also copy
185- # .dSYM over for debugging symbols
186- install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /lib/ DESTINATION lib)
171+ tvm_ffi_add_cxx_warning(tvm_ffi_objs)
187172endif ()
188173
189174########## Adding python module ##########
@@ -208,9 +193,12 @@ if (TVM_FFI_BUILD_PYTHON_MODULE)
208193 ${CMAKE_CURRENT_SOURCE_DIR} /python/tvm_ffi/cython/object.pxi
209194 ${CMAKE_CURRENT_SOURCE_DIR} /python/tvm_ffi/cython/string .pxi
210195 )
196+ # set working directory to source so we can see the exact file name in traceback
197+ # relatived to the project source root
211198 add_custom_command (
212199 OUTPUT ${core_cpp}
213200 COMMAND ${Python_EXECUTABLE} -m cython --cplus ${core_pyx} -o ${core_cpp}
201+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
214202 COMMENT "Transpiling ${core_pyx} to ${core_cpp} "
215203 DEPENDS ${cython_sources}
216204 VERBATIM
@@ -247,3 +235,18 @@ if (TVM_FFI_BUILD_PYTHON_MODULE)
247235 install (FILES ${CMAKE_CURRENT_SOURCE_DIR} /CMakeLists.txt DESTINATION .)
248236 install (FILES ${CMAKE_CURRENT_SOURCE_DIR} /cmake/tvm_ffi-config.cmake DESTINATION lib/cmake/tvm_ffi/)
249237endif ()
238+
239+ ########## Install the related for normal cmake library ##########
240+
241+ install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /include /tvm/ffi/ DESTINATION include /tvm/ffi/)
242+ install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /3rdparty/dlpack/include / DESTINATION include /)
243+ install (TARGETS tvm_ffi_shared DESTINATION lib)
244+ # ship additional dSYM files for debugging symbols on if available
245+ if (APPLE )
246+ install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /lib/ DESTINATION lib FILES_MATCHING PATTERN "*.dSYM" )
247+ endif ()
248+
249+ if (NOT TVM_FFI_BUILD_PYTHON_MODULE)
250+ # when building wheel, we do not ship static as we already ships source and dll
251+ install (TARGETS tvm_ffi_static DESTINATION lib)
252+ endif ()
0 commit comments