Files
TheRock/third-party/sysdeps/common/mpfr/CMakeLists.txt
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

142 lines
4.8 KiB
CMake

# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# When included in TheRock, we download sources and set up the sub-project.
set(_source_dir "${CMAKE_CURRENT_BINARY_DIR}/source")
set(_download_stamp "${_source_dir}/download.stamp")
therock_subproject_fetch(therock-mpfr-sources
SOURCE_DIR "${_source_dir}"
# Originally mirrored from: https://www.mpfr.org/mpfr-current/mpfr-4.2.2.tar.xz
URL "https://rocm-third-party-deps.s3.us-east-2.amazonaws.com/mpfr-4.2.2.tar.xz"
URL_HASH "SHA512=eb9e7f51b5385fb349cc4fba3a45ffdf0dd53be6dfc74932dc01258158a10514667960c530c47dd9dfc5aa18be2bd94859d80499844c5713710581e6ac6259a9"
TOUCH "${_download_stamp}"
# We need DOWNLOAD_EXTRACT_TIMESTAMP set to TRUE to preserve the timestamp
# of the extracted sources, otherwise the build system will notice
# changes and will try to re-run autotools, causing issues.
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
therock_cmake_subproject_declare(therock-mpfr
USE_DIST_AMDGPU_TARGETS
EXTERNAL_SOURCE_DIR .
FPRINT_SOURCE_DIR "${_source_dir}"
FPRINT_FILE_GLOBS "${CMAKE_CURRENT_LIST_DIR}/*"
BINARY_DIR build
NO_MERGE_COMPILE_COMMANDS
BACKGROUND_BUILD
OUTPUT_ON_FAILURE
CMAKE_ARGS
"-DSOURCE_DIR=${_source_dir}"
"-DPATCHELF=${PATCHELF}"
"-DPython3_EXECUTABLE=${Python3_EXECUTABLE}"
RUNTIME_DEPS
therock-gmp
INSTALL_DESTINATION
lib/rocm_sysdeps
INTERFACE_LINK_DIRS
lib/rocm_sysdeps/lib
INTERFACE_INSTALL_RPATH_DIRS
lib/rocm_sysdeps/lib
INTERFACE_PKG_CONFIG_DIRS
lib/rocm_sysdeps/lib/pkgconfig
EXTRA_DEPENDS
"${_download_stamp}"
)
therock_cmake_subproject_provide_package(therock-mpfr mpfr lib/rocm_sysdeps/lib/cmake/mpfr)
therock_cmake_subproject_activate(therock-mpfr)
therock_test_validate_shared_lib(
PATH build/dist/lib/rocm_sysdeps/lib
LIB_NAMES libmpfr.so
)
add_test(
NAME mpfr_header_test_1
COMMAND ls "${CMAKE_CURRENT_BINARY_DIR}/build/dist/lib/rocm_sysdeps/include/mpfr.h"
)
add_test(
NAME mpfr_header_test_2
COMMAND ls "${CMAKE_CURRENT_BINARY_DIR}/build/dist/lib/rocm_sysdeps/include/mpf2mpfr.h"
)
return()
endif()
# Otherwise, this is the sub-project build.
cmake_minimum_required(VERSION 3.25)
project(MPFR_BUILD VERSION "4.2.2")
# MPFR depends on GMP, so we need to pass the GMP prefix to MPFR's configure.
# Extract that information now.
# Create a temporary variable to hold the list we are filtering
# We use CMAKE_PREFIX_PATH as it contains the gmp stage prefix.
set(temp_gmp_paths ${CMAKE_PREFIX_PATH})
# Filter the temporary list to include only the item that contains the gmp
# stage prefix we are looking for.
list(FILTER temp_gmp_paths INCLUDE REGEX "/gmp/build/stage")
# Store our path or complain.
if(temp_gmp_paths)
list(GET temp_gmp_paths 0 GMP_PREFIX)
message(STATUS "Extracted GMP_PREFIX: ${GMP_PREFIX}")
else()
message(SEND_ERROR "Did not find a path containing '/gmp/build/stage' in CMAKE_LIBRARY_PATH.")
endif()
# Apply patch source only on Linux
set(patch_source_commands)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND patch_source_commands COMMAND
bash "${CMAKE_CURRENT_SOURCE_DIR}/patch_source.sh" "${SOURCE_DIR}")
endif()
add_custom_target(
build ALL
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
#
# OPTIONAL: Patching of the sources should happen here.
#
COMMAND
${patch_source_commands}
COMMAND
"${CMAKE_COMMAND}" -E env
"PKG_CONFIG_PATH=$ENV{PKG_CONFIG_PATH}"
# We don't insert rpath here because there are multiple layers of
# escaping going on (cmake, configure, shell, libtool), and making
# our $ORIGIN string survive through all that is complex and
# potentially fragile. We use a patchelf step instead.
"LDFLAGS=${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version.lds"
--
"${SOURCE_DIR}/configure"
--prefix "${CMAKE_INSTALL_PREFIX}"
--libdir "${CMAKE_INSTALL_PREFIX}/lib"
--with-gmp="${GMP_PREFIX}"
COMMAND
make V=1
COMMAND
make install
COMMAND
# Patch in the RUNPATH.
${PATCHELF} --set-rpath '\$\$ORIGIN:\$\$ORIGIN/rocm_sysdeps/lib' ${CMAKE_INSTALL_PREFIX}/lib/librocm_sysdeps_mpfr.so
COMMAND
"${CMAKE_COMMAND}" -E env
"PATCHELF=${PATCHELF}"
"THEROCK_SOURCE_DIR=${THEROCK_SOURCE_DIR}"
"Python3_EXECUTABLE=${Python3_EXECUTABLE}" --
"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/patch_install.py" ${CMAKE_INSTALL_PREFIX}
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/mpfr-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/mpfr-config.cmake
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mpfr-config.cmake" DESTINATION lib/cmake/mpfr)