Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ rocm_setup_version(VERSION 2.16.0)
math(EXPR MIGRAPHX_SO_MAJOR_VERSION "(${PROJECT_VERSION_MAJOR} * 1000 * 1000) + (${PROJECT_VERSION_MINOR} * 1000) + ${PROJECT_VERSION_PATCH}")
set(MIGRAPHX_SO_VERSION ${MIGRAPHX_SO_MAJOR_VERSION}.0)

option( BUILD_SHARED_LIBS "Build as a shared library" ON )
option(BUILD_SHARED_LIBS "Build as a shared library" ON )
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUILD_SHARED_LIBS is declared twice in the top-level CMakeLists (once near the top and again here). Having duplicate option(BUILD_SHARED_LIBS ...) definitions can lead to confusing/help-text mismatches and makes it unclear which one is authoritative; consider keeping a single option() definition and removing the duplicate.

Suggested change
option(BUILD_SHARED_LIBS "Build as a shared library" ON )

Copilot uses AI. Check for mistakes.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("--cuda-host-only -x hip" HAS_HIP)
Expand Down Expand Up @@ -346,6 +347,23 @@ rocm_enable_cppcheck(
include(ROCMCreatePackage)
include(ROCMTest)

function(enable_static_init LIB)
get_target_property(_type ${LIB} TYPE)
if(_type STREQUAL "STATIC_LIBRARY")
if(APPLE)
target_link_options(${LIB} INTERFACE
"LINKER:-force_load,$<TARGET_FILE:${LIB}>")
elseif(MSVC)
target_link_options(${LIB} INTERFACE
"LINKER:/WHOLEARCHIVE:$<TARGET_FILE:${LIB}>")
else()
# GNU ld / LLD / gold
target_link_options(${LIB} INTERFACE
"LINKER:--push-state,--whole-archive,$<TARGET_FILE:${LIB}>,--pop-state")
endif()
endif()
endfunction()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
Expand Down
4 changes: 2 additions & 2 deletions cmake/Embed.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function(add_embed_library EMBED_NAME)
target_sources(${INTERNAL_EMBED_LIB} PRIVATE ${OUTPUT_FILES})
endif()
target_include_directories(${INTERNAL_EMBED_LIB} PRIVATE "${EMBED_DIR}/include")
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations)
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations -Wno-c++11-narrowing)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Wno-c++11-narrowing is added unconditionally. This warning flag is compiler-specific (typically Clang) and can produce “unrecognized option” warnings or failures on other toolchains; consider guarding it with a compiler/flag check (e.g., check_cxx_compiler_flag) or applying it only for Clang.

Suggested change
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE -Wno-reserved-identifier -Wno-extern-initializer -Wno-missing-variable-declarations -Wno-c++11-narrowing)
target_compile_options(${INTERNAL_EMBED_LIB} PRIVATE
-Wno-reserved-identifier
-Wno-extern-initializer
-Wno-missing-variable-declarations
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Clang>>:-Wno-c++11-narrowing>
)

Copilot uses AI. Check for mistakes.
set_target_properties(${INTERNAL_EMBED_LIB} PROPERTIES POSITION_INDEPENDENT_CODE On)
add_library(${EMBED_NAME} INTERFACE)
if(EMBED_USE STREQUAL "RC")
Expand All @@ -268,6 +268,6 @@ function(add_embed_library EMBED_NAME)
else()
target_sources(${EMBED_NAME} INTERFACE $<TARGET_OBJECTS:${INTERNAL_EMBED_LIB}>)
endif()
target_include_directories(${EMBED_NAME} INTERFACE "${EMBED_DIR}/include")
target_include_directories(${EMBED_NAME} INTERFACE "$<BUILD_INTERFACE:${EMBED_DIR}/include>")
endfunction()

2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ add_library(migraphx
verify_args.cpp
)

enable_static_init(migraphx)

file(GLOB BUILDER_SRCS CONFIGURE_DEPENDS op/builder/*.cpp)
target_sources(migraphx PRIVATE ${BUILDER_SRCS})

Expand Down
9 changes: 5 additions & 4 deletions src/onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,15 +24,15 @@
find_package(protobuf QUIET CONFIG)

if(protobuf_FOUND)
add_library(onnx-proto STATIC)
add_library(onnx-proto OBJECT)
protobuf_generate(TARGET onnx-proto PROTOS onnx.proto)
target_include_directories(onnx-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(onnx-proto PRIVATE ${PROTOBUF_LIBRARY})
target_link_libraries(onnx-proto PRIVATE protobuf::libprotobuf)
else()
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS onnx.proto)
add_library(onnx-proto STATIC ${PROTO_SRCS})
add_library(onnx-proto OBJECT ${PROTO_SRCS})
target_include_directories(onnx-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(onnx-proto PRIVATE ${PROTOBUF_LIBRARY})
endif()
Expand All @@ -51,11 +51,12 @@ set_target_properties(migraphx_onnx PROPERTIES EXPORT_NAME onnx)
migraphx_generate_export_header(migraphx_onnx)
rocm_set_soversion(migraphx_onnx ${MIGRAPHX_SO_VERSION})
rocm_clang_tidy_check(migraphx_onnx)
target_link_libraries(migraphx_onnx PRIVATE onnx-proto)
target_link_libraries(migraphx_onnx PRIVATE $<BUILD_INTERFACE:onnx-proto>)
if(NOT WIN32)
target_link_libraries(migraphx_onnx PRIVATE "-Wl,--exclude-libs,ALL")
endif()
target_link_libraries(migraphx_onnx PUBLIC migraphx)
enable_static_init(migraphx_onnx)

rocm_install_targets(
PRIVATE
Expand Down
3 changes: 2 additions & 1 deletion src/targets/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -53,6 +53,7 @@ add_library(migraphx_cpu
target.cpp
write_literals.cpp
)
enable_static_init(migraphx_cpu)
set_target_properties(migraphx_cpu PROPERTIES EXPORT_NAME cpu)
rocm_set_soversion(migraphx_cpu ${MIGRAPHX_SO_VERSION})

Expand Down
4 changes: 3 additions & 1 deletion src/targets/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ add_library(migraphx_gpu
${MIOPEN_SRCS}
)

enable_static_init(migraphx_gpu)

set_target_properties(migraphx_gpu PROPERTIES EXPORT_NAME gpu)
migraphx_generate_export_header(migraphx_gpu)

Expand Down Expand Up @@ -406,7 +408,7 @@ add_subdirectory(hiprtc)

rocm_install_targets(
PRIVATE
TARGETS migraphx_gpu migraphx_device compile_for_gpu
TARGETS migraphx_gpu migraphx_device compile_for_gpu migraphx_kernels
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migraphx_kernels is an embed-generated INTERFACE target that references build-tree generated sources/headers and an internal target (embed_lib_migraphx_kernels). Adding it to rocm_install_targets() is likely to produce an unusable installed target (or export/install errors) unless the generated headers and the internal embed library are also installed/exported. Consider either removing migraphx_kernels from the install set or making it an installable library (and installing its generated headers).

Suggested change
TARGETS migraphx_gpu migraphx_device compile_for_gpu migraphx_kernels
TARGETS migraphx_gpu migraphx_device compile_for_gpu

Copilot uses AI. Check for mistakes.
INCLUDE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
Expand Down
9 changes: 5 additions & 4 deletions src/tf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,7 @@
find_package(protobuf QUIET CONFIG)

if(protobuf_FOUND)
add_library(tf-proto STATIC ${PROTO_SRCS})
add_library(tf-proto OBJECT ${PROTO_SRCS})
protobuf_generate(
TARGET tf-proto
PROTOS
Expand Down Expand Up @@ -57,7 +57,7 @@ else()
op_def.proto
versions.proto
)
add_library(tf-proto STATIC ${PROTO_SRCS})
add_library(tf-proto OBJECT ${PROTO_SRCS})
target_include_directories(tf-proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(tf-proto PRIVATE ${PROTOBUF_LIBRARY})
endif()
Expand All @@ -76,11 +76,12 @@ target_include_directories(migraphx_tf PRIVATE include)
set_target_properties(migraphx_tf PROPERTIES EXPORT_NAME tf)
rocm_set_soversion(migraphx_tf ${MIGRAPHX_SO_VERSION})
rocm_clang_tidy_check(migraphx_tf)
target_link_libraries(migraphx_tf PRIVATE tf-proto)
target_link_libraries(migraphx_tf PRIVATE $<BUILD_INTERFACE:tf-proto>)
if(NOT WIN32)
target_link_libraries(migraphx_tf PRIVATE "-Wl,--exclude-libs,ALL")
endif()
target_link_libraries(migraphx_tf PUBLIC migraphx)
enable_static_init(migraphx_tf)

rocm_install_targets(
PRIVATE
Expand Down
Loading