From 6e2dbbaa5d2fd96bac951dcb91698a8914a266aa Mon Sep 17 00:00:00 2001 From: Lukasz Dorau Date: Fri, 20 Oct 2023 15:48:06 +0200 Subject: [PATCH] Use add_umf_library() instead of add_ur_library() add_ur_library() is undefined in UMF now, because it is defined only in the UR project. Define and use add_umf_library() instead of add_ur_library(), so that UMF can be used as a stand-alone project. Fixes: #981 Signed-off-by: Lukasz Dorau --- .../unified_malloc_framework/CMakeLists.txt | 6 +- .../cmake/helpers.cmake | 63 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 source/common/unified_malloc_framework/cmake/helpers.cmake diff --git a/source/common/unified_malloc_framework/CMakeLists.txt b/source/common/unified_malloc_framework/CMakeLists.txt index a71b688b74..6f45326a13 100644 --- a/source/common/unified_malloc_framework/CMakeLists.txt +++ b/source/common/unified_malloc_framework/CMakeLists.txt @@ -3,6 +3,8 @@ # See LICENSE.TXT # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +include(cmake/helpers.cmake) + set(UMF_SOURCES src/memory_pool.c src/memory_provider.c @@ -21,11 +23,11 @@ if(UMF_BUILD_SHARED_LIBRARY) message(WARNING "Unified Malloc Framework is still an early work in progress." "There are no API/ABI backward compatibility guarantees. There will be breakages." "Do not use the shared library in production software.") - add_ur_library(unified_malloc_framework SHARED + add_umf_library(unified_malloc_framework SHARED ${UMF_SOURCES}) target_compile_definitions(unified_malloc_framework PUBLIC UMF_SHARED_LIBRARY) else() - add_ur_library(unified_malloc_framework STATIC + add_umf_library(unified_malloc_framework STATIC ${UMF_SOURCES}) endif() diff --git a/source/common/unified_malloc_framework/cmake/helpers.cmake b/source/common/unified_malloc_framework/cmake/helpers.cmake new file mode 100644 index 0000000000..959984352d --- /dev/null +++ b/source/common/unified_malloc_framework/cmake/helpers.cmake @@ -0,0 +1,63 @@ +# Copyright (C) 2023 Intel Corporation +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. +# See LICENSE.TXT +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# +# helpers.cmake -- helper functions for the UMF's top-level CMakeLists.txt +# + +function(add_umf_target_compile_options name) + if(NOT MSVC) + target_compile_options(${name} PRIVATE + -fPIC + -Wall + -Wpedantic + -Wempty-body + -Wunused-parameter + $<$:-fdiagnostics-color=always> + $<$:-fcolor-diagnostics> + ) + if (CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2) + endif() + if(UR_DEVELOPER_MODE) + target_compile_options(${name} PRIVATE + -Werror + -fno-omit-frame-pointer + -fstack-protector-strong + ) + endif() + elseif(MSVC) + target_compile_options(${name} PRIVATE + $<$:/MP> # clang-cl.exe does not support /MP + /W3 + /MD$<$:d> + /GS + ) + + if(UR_DEVELOPER_MODE) + target_compile_options(${name} PRIVATE /WX /GS) + endif() + endif() +endfunction() + +function(add_umf_target_link_options name) + if(NOT MSVC) + if (NOT APPLE) + target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now") + endif() + elseif(MSVC) + target_link_options(${name} PRIVATE + /DYNAMICBASE + /HIGHENTROPYVA + /NXCOMPAT + ) + endif() +endfunction() + +function(add_umf_library name) + add_library(${name} ${ARGN}) + add_umf_target_compile_options(${name}) + add_umf_target_link_options(${name}) +endfunction()