#============================================================================= # SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 #============================================================================= cmake_minimum_required(VERSION 3.26.4) list(APPEND CMAKE_MESSAGE_CONTEXT "legate") cmake_path(SET LEGATE_CMAKE_DIR NORMALIZE "${CMAKE_CURRENT_LIST_DIR}/cmake") if(APPLE) include("${LEGATE_CMAKE_DIR}/Modules/setup_macos_sdk_environ.cmake") legate_setup_macos_sdk_environ() endif() if(SKBUILD) set(legate_project_suffix python) else() set(legate_project_suffix cpp) endif() file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../VERSION" LEGATE_VERSION) string(STRIP "${LEGATE_VERSION}" LEGATE_VERSION) project(legate_${legate_project_suffix} VERSION ${LEGATE_VERSION} LANGUAGES CXX DESCRIPTION "Multi-node, Multi-GPU Parallel Runtime Library" HOMEPAGE_URL https://docs.nvidia.com/legate/latest/) # ######################################################################################## # * Compiler Version Checks -------------------------------------------------------- if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} is not supported. Minimum required version is 10.0. Please upgrade your compiler." ) endif() else() message(STATUS "Using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} - " "compiler support not explicitly validated") endif() # ######################################################################################## # * Common Core -------------------------------------------------------- option(AEDIFIX "Whether this configuration is being driven by aedifix" OFF) # ######################################################################################## # * Setup LEGATE_DIR and LEGATE_ARCH if(NOT DEFINED LEGATE_DIR) # this one we can figure out on our own set(LEGATE_DIR "${CMAKE_CURRENT_LIST_DIR}/..") endif() cmake_path(SET LEGATE_DIR NORMALIZE "${LEGATE_DIR}") set(LEGATE_DIR "${LEGATE_DIR}" CACHE PATH "Path to root legate source directory (not to be confused with legate_DIR which points to the root install directory)" FORCE) if(NOT DEFINED LEGATE_ARCH) set(bin_dir ${CMAKE_CURRENT_BINARY_DIR}) if(AEDIFIX) # We are being driven by Aedifix, that must mean our current binary path is # $LEGATE_DIR//cmake_build. That being said, this path should never be # exercised, because aedifix should be setting this value for us! if(NOT "${bin_dir}" MATCHES "cmake_build$") message(FATAL_ERROR "Could not locate LEGATE_ARCH directory, expected binary dir to end " "with 'cmake_build', but it is ${bin_dir}. Expected this directory structure " "because environment variable: AEDIFIX=1. Likely this indicates this environment " "variable is wrongly set.") endif() cmake_path(GET bin_dir PARENT_PATH bin_dir) endif() cmake_path(GET bin_dir STEM LEGATE_ARCH) unset(bin_dir) endif() # push it to cache set(LEGATE_ARCH "${LEGATE_ARCH}" CACHE STRING "Name of the legate arch directory" FORCE) cmake_path(SET LEGATE_ARCH_DIR NORMALIZE "${LEGATE_DIR}/${LEGATE_ARCH}") # ######################################################################################## # * C++ and CUDA standard ---------------------------------------------------- function(legate_set_language_standard LANG DEFAULT) if(NOT CMAKE_${LANG}_STANDARD) set(CMAKE_${LANG}_STANDARD ${DEFAULT}) endif() if(NOT "${CMAKE_${LANG}_STANDARD}" STREQUAL "${DEFAULT}") message(WARNING "CMAKE_${LANG}_STANDARD set to ${CMAKE_${LANG}_STANDARD}. " "Legate expects to be compiled with C++${DEFAULT}") endif() set(CMAKE_${LANG}_STANDARD ${CMAKE_${LANG}_STANDARD} PARENT_SCOPE) set(CMAKE_${LANG}_STANDARD_REQUIRED ON PARENT_SCOPE) endfunction() legate_set_language_standard(CXX 17) legate_set_language_standard(CUDA 17) # Tells cmake to re-run configure if any of these files have changed. This is needed # because these are all static files (i.e. not generated by some target), and cmake # provides no easy way to create a target for static resources. set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${LEGATE_CMAKE_DIR}/versions/versions.json" "${LEGATE_CMAKE_DIR}/versions/legion_version.json" "${LEGATE_CMAKE_DIR}/templates/uninstall.cmake.in" "${LEGATE_CMAKE_DIR}/templates/legate_defines.h.in" "${LEGATE_CMAKE_DIR}/templates/bin2c.cc.in" "${LEGATE_CMAKE_DIR}/templates/bin2c.h.in" "${LEGATE_CMAKE_DIR}/templates/git_version.cc.in" "${LEGATE_CMAKE_DIR}/templates/install_info.py.in") macro(set_ifndef variable value) if(NOT DEFINED ${variable}) set(${variable} ${value}) endif() endmacro() macro(set_parent_scope variable) set(${variable} ${${variable}} PARENT_SCOPE) endmacro() option(BUILD_MARCH "Target a specific CPU architecture" OFF) option(BUILD_MCPU "Tune for a specific CPU architecture" OFF) option(CMAKE_EXPORT_COMPILE_COMMANDS "Export CMake compile commands" ON) option(CMAKE_POSITION_INDEPENDENT_CODE "Build position independent code" ON) option(BUILD_SHARED_LIBS "Build shared libraries" ON) # ######################################################################################## # * rapids-cmake -------------------------------------------------------- include("${LEGATE_CMAKE_DIR}/Modules/include_rapids.cmake") legate_include_rapids() include(rapids-cmake) include(rapids-cpm) include(rapids-cuda) include(rapids-export) include(rapids-find) include(rapids-version) rapids_cmake_build_type(Release) # ######################################################################################## # * conda environment -------------------------------------------------------- include(GNUInstallDirs) rapids_cmake_support_conda_env(conda_env MODIFY_PREFIX_PATH) # We're building python extension libraries, which must always be installed under lib/, # even if the system normally uses lib64/. Rapids-cmake currently doesn't realize this # when we're going through scikit-build, see # https://github.com/rapidsai/rapids-cmake/issues/426 Do this before we include Legion, so # its build also inherits this setting. if(TARGET conda_env) set(CMAKE_INSTALL_LIBDIR "lib") else() rapids_cmake_install_lib_dir(CMAKE_INSTALL_LIBDIR) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(legate_PLATFORM_RPATH_ORIGIN "\$ORIGIN") elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") set(legate_PLATFORM_RPATH_ORIGIN "@loader_path") else() message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}, don't know how to set " "rpath 'origin' on this platform") endif() cmake_path(SET legate_DEP_INSTALL_LIBDIR NORMALIZE "${CMAKE_INSTALL_LIBDIR}/legate/deps") cmake_path(SET legate_DEP_INSTALL_INCLUDEDIR NORMALIZE "${CMAKE_INSTALL_INCLUDEDIR}/legate/deps") cmake_path(SET legate_DEP_INSTALL_BINDIR NORMALIZE "${CMAKE_INSTALL_DATAROOTDIR}/legate/${CMAKE_INSTALL_BINDIR}") add_subdirectory(${legate_project_suffix})