|
| 1 | +# Copyright (C) 2022-2023 Intel Corporation |
| 2 | +# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + |
| 5 | +cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR) |
| 6 | +project(unified-memory-framework VERSION 0.1.0) |
| 7 | + |
| 8 | +include(CTest) |
| 9 | + |
| 10 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 11 | +include(helpers) |
| 12 | + |
| 13 | +# Build Options |
| 14 | +option(UMF_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF) |
| 15 | +option(UMF_BUILD_SHARED_LIBRARY "Build UMF as shared library" OFF) |
| 16 | + |
| 17 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 18 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 19 | +set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 20 | +if(MSVC) |
| 21 | + set(CMAKE_UMF_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>) |
| 22 | +endif() |
| 23 | + |
| 24 | +# Define a path for custom commands to work around MSVC |
| 25 | +set(CUSTOM_COMMAND_BINARY_DIR ${CMAKE_UMF_OUTPUT_DIRECTORY}) |
| 26 | +if(MSVC) |
| 27 | + # MSVC implicitly adds $<CONFIG> to the output path |
| 28 | + set(CUSTOM_COMMAND_BINARY_DIR ${CUSTOM_COMMAND_BINARY_DIR}/$<CONFIG>) |
| 29 | +endif() |
| 30 | + |
| 31 | +# Obtain files for clang-format and license check |
| 32 | +set(format_glob) |
| 33 | +set(license_glob) |
| 34 | +foreach(dir examples include source test tools) |
| 35 | + list(APPEND format_glob |
| 36 | + "${dir}/*.h" |
| 37 | + "${dir}/*.c" |
| 38 | + "${dir}/**/*.h" |
| 39 | + "${dir}/**/*.c") |
| 40 | + list(APPEND license_glob |
| 41 | + "${dir}/*.yml" |
| 42 | + "${dir}/**/*.yml" |
| 43 | + "${dir}/*.py" |
| 44 | + "${dir}/**/*.py" |
| 45 | + "${dir}/**/CMakeLists.txt" |
| 46 | + "${dir}/CMakeLists.txt" |
| 47 | + ) |
| 48 | +endforeach() |
| 49 | +file(GLOB_RECURSE format_src ${format_glob}) |
| 50 | +file(GLOB_RECURSE license_src ${license_glob}) |
| 51 | + |
| 52 | +# A header only library to specify include directories in transitive |
| 53 | +# dependencies. |
| 54 | +add_library(umf_headers INTERFACE) |
| 55 | +# Alias target to support FetchContent. |
| 56 | +add_library(${PROJECT_NAME}::headers ALIAS umf_headers) |
| 57 | +target_include_directories(umf_headers INTERFACE |
| 58 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 59 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 60 | + |
| 61 | +# Add the include directory and the headers target to the install. |
| 62 | +install( |
| 63 | + DIRECTORY "${PROJECT_SOURCE_DIR}/include/" |
| 64 | + DESTINATION include COMPONENT umf_headers) |
| 65 | +install( |
| 66 | + TARGETS umf_headers |
| 67 | + EXPORT ${PROJECT_NAME}-targets) |
| 68 | + |
| 69 | +add_subdirectory(src) |
| 70 | +add_subdirectory(test) |
| 71 | + |
| 72 | +# Add the list of installed targets to the install. This includes the namespace |
| 73 | +# which all installed targets will be prefixed with, e.g. for the headers |
| 74 | +# target users will depend on ${PROJECT_NAME}::headers. |
| 75 | +install( |
| 76 | + EXPORT ${PROJECT_NAME}-targets |
| 77 | + FILE ${PROJECT_NAME}-targets.cmake |
| 78 | + NAMESPACE ${PROJECT_NAME}:: |
| 79 | + DESTINATION lib/cmake/${PROJECT_NAME}) |
| 80 | + |
| 81 | +# Configure the package versions file for use in find_package when installed. |
| 82 | +write_basic_package_version_file( |
| 83 | + ${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake |
| 84 | + COMPATIBILITY SameMajorVersion) |
| 85 | +# Configure the package file that is searched for by find_package when |
| 86 | +# installed. |
| 87 | +configure_package_config_file( |
| 88 | + ${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in |
| 89 | + ${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake |
| 90 | + INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}) |
| 91 | + |
| 92 | +# Add the package files to the install. |
| 93 | +install( |
| 94 | + FILES |
| 95 | + ${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config.cmake |
| 96 | + ${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}-config-version.cmake |
| 97 | + DESTINATION lib/cmake/${PROJECT_NAME}) |
0 commit comments