@@ -168,6 +168,10 @@ include_directories(${PROJECT_BINARY_DIR}/third_party) # Tablegen'd files
168168add_subdirectory (include )
169169add_subdirectory (lib)
170170
171+ # find_package(PythonLibs REQUIRED)
172+ set (TRITON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR} " )
173+ set (TRITON_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR} " )
174+
171175# TODO: Figure out which target is sufficient to fix errors; triton is
172176# apparently not enough. Currently set linking libstdc++fs for all targets
173177# to support some old version GCC compilers like 8.3.0.
@@ -184,12 +188,24 @@ if(TRITON_BUILD_PYTHON_MODULE)
184188 set (PYTHON_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR} /python/src)
185189 include_directories (${PYTHON_SRC_PATH} )
186190
187- # Python Interpreter is used to run lit tests
188- find_package (Python3 REQUIRED COMPONENTS Development Interpreter)
189- find_package (pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB} " )
190191 if (PYTHON_INCLUDE_DIRS)
192+ # We have PYTHON_INCLUDE_DIRS set--this is what we expect when building
193+ # using pip install.
194+ include_directories (${PYTHON_INCLUDE_DIRS} )
195+ include_directories (${PYBIND11_INCLUDE_DIR} )
191196 message (STATUS "PYTHON_LIB_DIRS ${PYTHON_LIB_DIRS} " )
192197 link_directories (${PYTHON_LIB_DIRS} )
198+ else ()
199+ # Otherwise, we might be building from top CMakeLists.txt directly.
200+ # Try to find Python and pybind11 packages.
201+ find_package (Python3 REQUIRED COMPONENTS Development Interpreter)
202+ find_package (pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB} " )
203+ include_directories (${Python3_INCLUDE_DIRS} )
204+ include_directories (${pybind11_INCLUDE_DIR} )
205+ link_directories (${Python3_LIBRARY_DIRS} )
206+ link_libraries (${Python3_LIBRARIES} )
207+ add_link_options (${Python3_LINK_OPTIONS} )
208+ endif ()
193209
194210 if (DEFINED TRITON_PLUGIN_DIRS)
195211 foreach (PLUGIN_DIR ${TRITON_PLUGIN_DIRS} )
@@ -256,9 +272,6 @@ if(TRITON_BUILD_PYTHON_MODULE)
256272 LLVMAMDGPUCodeGen
257273 LLVMAMDGPUAsmParser
258274
259- Python3::Module
260- pybind11::headers
261-
262275 )
263276 if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR # Linux arm64
264277 CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR # macOS arm64
@@ -299,7 +312,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
299312 ${PYTHON_SRC_PATH} /llvm.cc)
300313
301314 # Link triton with its dependencies
302- target_link_libraries (triton PRIVATE ${TRITON_LIBRARIES} )
315+ target_link_libraries (triton PUBLIC ${TRITON_LIBRARIES} )
303316 if (WIN32 )
304317 target_link_libraries (triton PRIVATE ${CMAKE_DL_LIBS} )
305318 set_target_properties (triton PROPERTIES SUFFIX ".pyd" )
@@ -322,7 +335,7 @@ if(TRITON_BUILD_PYTHON_MODULE AND NOT WIN32)
322335 set (PYTHON_LDFLAGS "-undefined dynamic_lookup" )
323336 endif ()
324337
325- target_link_options (triton PRIVATE ${PYTHON_LDFLAGS} )
338+ target_link_libraries (triton PRIVATE ${PYTHON_LDFLAGS} )
326339endif ()
327340
328341if (NOT TRITON_BUILD_PYTHON_MODULE)
0 commit comments