@@ -169,32 +169,19 @@ set(libname ROOTPythonizations)
169169
170170add_library (${libname} SHARED ${cpp_sources} )
171171
172- # To make sure that the library also ends up in the right subdirectory in the
173- # build directory tree.
174- if (MSVC )
175- set_target_properties (${libname}
176- PROPERTIES
177- RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} /bin/ROOT
178- RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} /bin/ROOT
179- RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR} /bin/ROOT
180- RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR} /bin/ROOT)
181- else ()
182- set_target_properties (${libname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib/ROOT)
183- endif ()
184-
185172# Insert the ROOTPythonizationsPySources in the dependency graph
186173add_dependencies (${libname} ROOTPythonizationsPySources)
187174
188175# Set the suffix to '.so' and the prefix to 'lib'
189176set_target_properties (${libname} PROPERTIES ${ROOT_LIBRARY_PROPERTIES_NO_VERSION} )
177+ target_link_libraries (${libname} PUBLIC Core Tree cppyy)
190178if (MSVC )
191179 set_target_properties (${libname} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE )
192180 set_target_properties (${libname} PROPERTIES SUFFIX ".pyd" )
193- target_link_libraries (${libname} PUBLIC Core Tree cppyy)
194181elseif (APPLE )
195- target_link_libraries (${libname} PUBLIC -Wl,-bind_at_load -Wl,-w -Wl,-undefined -Wl,dynamic_lookup Core Tree cppyy )
182+ target_link_libraries (${libname} PUBLIC -Wl,-bind_at_load -Wl,-w -Wl,-undefined -Wl,dynamic_lookup)
196183else ()
197- target_link_libraries (${libname} PUBLIC -Wl,--unresolved-symbols=ignore -all Core Tree cppyy )
184+ target_link_libraries (${libname} PUBLIC -Wl,--unresolved-symbols=ignore -all )
198185endif ()
199186
200187target_include_directories (${libname}
@@ -223,18 +210,49 @@ endforeach()
223210add_library (PyROOT INTERFACE )
224211target_link_libraries (PyROOT INTERFACE cppyy_backend cppyy ROOTPythonizations)
225212
226- # Install library
227- install (TARGETS ${libname} EXPORT ${CMAKE_PROJECT_NAME} Exports
228- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} /ROOT COMPONENT libraries
229- LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR} /ROOT COMPONENT libraries
230- ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR} /ROOT COMPONENT libraries)
213+ # Define library output directories for build and install trees
214+ set (pymoduledir_build "${localruntimedir} /ROOT" )
215+ set (pymoduledir_install "${CMAKE_INSTALL_FULL_PYTHONDIR} /ROOT" )
216+
217+ # To make sure that the library also ends up in the right subdirectory in the
218+ # build directory tree.
219+ if (MSVC )
220+ set_target_properties (${libname}
221+ PROPERTIES
222+ RUNTIME_OUTPUT_DIRECTORY_DEBUG ${pymoduledir_build}
223+ RUNTIME_OUTPUT_DIRECTORY_RELEASE ${pymoduledir_build}
224+ RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${pymoduledir_build}
225+ RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${pymoduledir_build} )
226+ else ()
227+ set_target_properties (${libname} PROPERTIES
228+ LIBRARY_OUTPUT_DIRECTORY ${pymoduledir_build} )
229+ endif ()
230+
231+ if (NOT MSVC )
232+ # Make sure that relative RUNPATH to main ROOT libraries is always correct.
233+
234+ file (RELATIVE_PATH pymoduledir_to_libdir_build ${pymoduledir_build} "${localruntimedir} " )
235+ file (RELATIVE_PATH pymoduledir_to_libdir_install ${pymoduledir_install} "${CMAKE_INSTALL_FULL_LIBDIR} " )
236+
237+ if (APPLE )
238+ set_target_properties (${libname} PROPERTIES
239+ BUILD_RPATH "@loader_path/${pymoduledir_to_libdir_build} "
240+ INSTALL_RPATH "@loader_path/${pymoduledir_to_libdir_install} "
241+ )
242+ else ()
243+ set_target_properties (${libname} PROPERTIES
244+ BUILD_RPATH "$ORIGIN/${pymoduledir_to_libdir_build} "
245+ INSTALL_RPATH "$ORIGIN/${pymoduledir_to_libdir_install} "
246+ )
247+ endif ()
248+
249+ endif ()
231250
232- # Install meta-target PyROOT3 (INTERFACE library)
233251# Install library
234- install (TARGETS PyROOT EXPORT ${CMAKE_PROJECT_NAME} Exports
235- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} /ROOT COMPONENT libraries
236- LIBRARY DESTINATION ${CMAKE_INSTALL_PYTHONDIR} /ROOT COMPONENT libraries
237- ARCHIVE DESTINATION ${CMAKE_INSTALL_PYTHONDIR} /ROOT COMPONENT libraries)
252+ install (TARGETS ${libname} EXPORT ${CMAKE_PROJECT_NAME} Exports
253+ RUNTIME DESTINATION ${pymoduledir_install} COMPONENT libraries
254+ LIBRARY DESTINATION ${pymoduledir_install} COMPONENT libraries
255+ ARCHIVE DESTINATION ${pymoduledir_install} COMPONENT libraries)
238256
239257# Install Python sources and bytecode
240258install (DIRECTORY ${localruntimedir} /ROOT
0 commit comments