Skip to content

Commit e2c09d7

Browse files
authored
[PROTON] Explicitly list all cpp files (#5756)
Otherwise, sometimes on macOS we may generate unnecessary files with a `_` prefix after unpacking a tar file.
1 parent 9dfab8f commit e2c09d7

File tree

8 files changed

+88
-16
lines changed

8 files changed

+88
-16
lines changed

third_party/proton/CMakeLists.txt

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,73 @@
1-
project(Proton CXX)
1+
project(Proton LANGUAGES CXX)
22

3-
set(PROTON_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/csrc)
4-
set(PROTON_EXTERN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern)
5-
file(GLOB_RECURSE PROTON_SRC ${PROTON_SRC_DIR}/lib/*.cpp)
6-
add_library(proton SHARED ${PROTON_SRC} ${PROTON_SRC_DIR}/${PROJECT_NAME}.cpp)
3+
set(PROTON_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/csrc")
74

5+
# ============ Check for includes =============
86
if(NOT CUPTI_INCLUDE_DIR)
97
message(FATAL_ERROR "CUPTI include directory not defined")
108
endif()
119
if(NOT ROCTRACER_INCLUDE_DIR)
1210
message(FATAL_ERROR "ROCTRACER include directory not defined")
1311
endif()
14-
if (NOT JSON_INCLUDE_DIR)
12+
if(NOT JSON_INCLUDE_DIR)
1513
message(FATAL_ERROR "JSON include directory not defined")
1614
endif()
1715

18-
include_directories(${JSON_INCLUDE_DIR})
19-
include_directories(${PROTON_SRC_DIR}/include)
20-
include_directories(${PROTON_EXTERN_DIR})
21-
16+
# ============ Dependencies =============
2217
find_package(Python3 REQUIRED Interpreter Development.Module)
2318
find_package(pybind11 CONFIG REQUIRED HINTS "${Python3_SITELIB}")
2419

25-
# Check if the platform is MacOS
20+
# ============ Define a GLOBAL property to store object-libraries ============
21+
set_property(GLOBAL PROPERTY PROTON_LIBS "")
22+
23+
# ============ Define a function to create object libraries ============
24+
function(add_proton_library name)
25+
add_library(${name} OBJECT ${ARGN})
26+
27+
target_link_libraries(${name} PRIVATE Python3::Module pybind11::headers)
28+
29+
target_include_directories(${name}
30+
PRIVATE
31+
"${CUPTI_INCLUDE_DIR}"
32+
"${ROCTRACER_INCLUDE_DIR}"
33+
"${JSON_INCLUDE_DIR}"
34+
"${PROTON_SRC_DIR}/include"
35+
)
36+
37+
# If HIP is AMD-based
38+
target_compile_definitions(${name} PRIVATE __HIP_PLATFORM_AMD__)
39+
40+
# Append this library name to the GLOBAL property "PROTON_LIBS"
41+
set_property(GLOBAL APPEND PROPERTY PROTON_LIBS ${name})
42+
endfunction()
43+
44+
# ============ Add subdirectory with actual code that calls add_proton_library ============
45+
add_subdirectory("${PROTON_SRC_DIR}")
46+
47+
# ============ Possibly handle macOS specifics ============
2648
if(APPLE)
2749
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
2850
# Other platforms build with -flto, but we found that this adds significant overhead to our macos CI without providing a major benefit.
2951
set(PROTON_PYTHON_LDFLAGS "-undefined dynamic_lookup")
3052
endif()
3153

32-
include_directories(${CUPTI_INCLUDE_DIR})
33-
include_directories(SYSTEM ${ROCTRACER_INCLUDE_DIR})
34-
target_compile_definitions(proton PRIVATE __HIP_PLATFORM_AMD__)
54+
# ============ Collect all object libraries from property and build final shared lib ============
55+
get_property(_proton_obj_libs GLOBAL PROPERTY PROTON_LIBS)
56+
57+
if(NOT _proton_obj_libs)
58+
message(WARNING "No object libraries were defined in 'PROTON_LIBS'!")
59+
endif()
60+
61+
set(_proton_obj_sources "")
62+
foreach(_lib IN LISTS _proton_obj_libs)
63+
list(APPEND _proton_obj_sources $<TARGET_OBJECTS:${_lib}>)
64+
message(STATUS "Collecting object files from ${_lib}")
65+
endforeach()
66+
67+
add_library(proton SHARED ${_proton_obj_sources})
3568

36-
target_link_libraries(proton PRIVATE Python3::Module pybind11::headers)
37-
target_link_options(proton PRIVATE ${PROTON_PYTHON_LDFLAGS})
69+
target_link_libraries(proton PRIVATE Python3::Module)
70+
# Apply any macOS linker flags or extra link options
71+
if(PROTON_PYTHON_LDFLAGS)
72+
target_link_options(proton PRIVATE ${PROTON_PYTHON_LDFLAGS})
73+
endif()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_proton_library(Proton
2+
Proton.cpp
3+
)
4+
5+
add_subdirectory(lib)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_subdirectory(Context)
2+
add_subdirectory(Data)
3+
add_subdirectory(Driver)
4+
add_subdirectory(Profiler)
5+
add_subdirectory(Session)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_proton_library(ProtonContext
2+
Context.cpp
3+
Python.cpp
4+
Shadow.cpp
5+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_proton_library(ProtonData
2+
Data.cpp
3+
TraceData.cpp
4+
TreeData.cpp
5+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_proton_library(ProtonDriver
2+
Device.cpp
3+
GPU/CudaApi.cpp
4+
GPU/CuptiApi.cpp
5+
GPU/HipApi.cpp
6+
GPU/HsaApi.cpp
7+
GPU/RoctracerApi.cpp
8+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_proton_library(ProtonProfiler
2+
Cupti/CuptiPCSampling.cpp
3+
Cupti/CuptiProfiler.cpp
4+
RocTracer/RoctracerProfiler.cpp
5+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_proton_library(ProtonSession
2+
Session.cpp
3+
)

0 commit comments

Comments
 (0)