From 1726f1b53b7ff5a13b2bd3cec98f0c5d1952300d Mon Sep 17 00:00:00 2001 From: xufang Date: Wed, 12 Jun 2024 11:09:36 +0800 Subject: [PATCH 1/5] enable __FILE__ trim --- CMakeLists.txt | 12 ++++++++++++ cmake/compilers/AppleClang.cmake | 4 ++++ cmake/compilers/Clang.cmake | 4 ++++ cmake/compilers/GNU.cmake | 4 ++++ cmake/compilers/MSVC.cmake | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19232a9920..ac9627b0b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,7 @@ option(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH "Disable HWLOC automatic search by pkg option(TBB_ENABLE_IPO "Enable Interprocedural Optimization (IPO) during the compilation" ON) option(TBB_FUZZ_TESTING "Enable fuzz testing" OFF) option(TBB_INSTALL "Enable installation" ON) +option(TBB_FILE_TRIM "Enable __FILE__ trim" ON) if(APPLE) option(TBB_BUILD_APPLE_FRAMEWORKS "Build as Apple Frameworks" OFF) endif() @@ -226,6 +227,17 @@ if (TBB_ENABLE_IPO AND BUILD_SHARED_LIBS AND NOT ANDROID_PLATFORM AND NOT TBB_SA endif() endif() +if (TBB_FILE_TRIM) + file(RELATIVE_PATH TBB_RELATIVE_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) + if(CMAKE_VERSION VERSION_LESS 3.20) + file(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} NATIVE_TBB_PROJECT_ROOT_DIR) + file(TO_NATIVE_PATH ${TBB_RELATIVE_BIN_PATH} NATIVE_TBB_RELATIVE_BIN_PATH) + else() + cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR NATIVE_TBB_PROJECT_ROOT_DIR) + cmake_path(NATIVE_PATH TBB_RELATIVE_BIN_PATH NATIVE_TBB_RELATIVE_BIN_PATH) + endif() +endif () + set(TBB_COMPILER_SETTINGS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compilers/${CMAKE_CXX_COMPILER_ID}.cmake) if (EXISTS ${TBB_COMPILER_SETTINGS_FILE}) include(${TBB_COMPILER_SETTINGS_FILE}) diff --git a/cmake/compilers/AppleClang.cmake b/cmake/compilers/AppleClang.cmake index 5ebbdbd1a6..016473e888 100644 --- a/cmake/compilers/AppleClang.cmake +++ b/cmake/compilers/AppleClang.cmake @@ -42,6 +42,10 @@ if ("${_tbb_target_architectures}" MATCHES "(x86_64|amd64|AMD64)") # OSX systems endif() unset(_tbb_target_architectures) +if (TBB_FILE_TRIM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10) + set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -ffile-prefix-map=${NATIVE_TBB_PROJECT_ROOT_DIR}/= -ffile-prefix-map=${NATIVE_TBB_RELATIVE_BIN_PATH}/=) +endif () + # TBB malloc settings set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions) diff --git a/cmake/compilers/Clang.cmake b/cmake/compilers/Clang.cmake index f56b5fba0f..fb3dc249d2 100644 --- a/cmake/compilers/Clang.cmake +++ b/cmake/compilers/Clang.cmake @@ -76,6 +76,10 @@ if (MINGW) list(APPEND TBB_COMMON_COMPILE_FLAGS -U__STRICT_ANSI__) endif() +if (TBB_FILE_TRIM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10) + set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -ffile-prefix-map=${NATIVE_TBB_PROJECT_ROOT_DIR}/= -ffile-prefix-map=${NATIVE_TBB_RELATIVE_BIN_PATH}/=) +endif () + set(TBB_IPO_COMPILE_FLAGS $<$>:-flto>) set(TBB_IPO_LINK_FLAGS $<$>:-flto>) diff --git a/cmake/compilers/GNU.cmake b/cmake/compilers/GNU.cmake index b1e1911742..eef7804113 100644 --- a/cmake/compilers/GNU.cmake +++ b/cmake/compilers/GNU.cmake @@ -110,6 +110,10 @@ if (NOT CMAKE_CXX_FLAGS MATCHES "_FORTIFY_SOURCE") set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$>:-D_FORTIFY_SOURCE=2> ) endif () +if (TBB_FILE_TRIM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8) + set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -ffile-prefix-map=${NATIVE_TBB_PROJECT_ROOT_DIR}/= -ffile-prefix-map=${NATIVE_TBB_RELATIVE_BIN_PATH}/=) +endif () + # TBB malloc settings set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions) set(TBB_OPENMP_FLAG -fopenmp) diff --git a/cmake/compilers/MSVC.cmake b/cmake/compilers/MSVC.cmake index 6568ec7eb8..b5a25a8354 100644 --- a/cmake/compilers/MSVC.cmake +++ b/cmake/compilers/MSVC.cmake @@ -77,6 +77,12 @@ if (TBB_WINDOWS_DRIVER) set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /D _UNICODE /DUNICODE /DWINAPI_FAMILY=WINAPI_FAMILY_APP /D__WRL_NO_DEFAULT_LIB__) endif() +if (TBB_FILE_TRIM) + add_compile_options( + "$<$:/d1trimfile:${NATIVE_TBB_PROJECT_ROOT_DIR}\\>" + "$<$:/d1trimfile:${CMAKE_SOURCE_DIR}/>") +endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "(Clang|IntelLLVM)") if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86|AMD64|i.86)") set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm -mwaitpkg) From 9c4769a03e5ade7d2e0bcf4e43b50560c9b750b4 Mon Sep 17 00:00:00 2001 From: xufang Date: Thu, 13 Jun 2024 10:26:27 +0800 Subject: [PATCH 2/5] update README --- cmake/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/README.md b/cmake/README.md index 60df73c072..afc20d5663 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -20,6 +20,7 @@ TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default) TBB_ENABLE_IPO - Enable Interprocedural Optimization (IPO) during the compilation (ON by default) TBB_BUILD_APPLE_FRAMEWORKS - Enable the Apple* frameworks instead of dylibs, only available on the Apple platform. (OFF by default) +TBB_FILE_TRIM - Enable __FILE__ trim (ON by default) ``` ## Configure, Build, and Test From 5cb6c777c0d8069394b684b66a9dce36ecbcc0df Mon Sep 17 00:00:00 2001 From: xufang Date: Fri, 14 Jun 2024 09:32:30 +0800 Subject: [PATCH 3/5] update based on comment --- CMakeLists.txt | 9 ++------- cmake/README.md | 3 ++- cmake/compilers/AppleClang.cmake | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac9627b0b7..dbb236778c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -229,13 +229,8 @@ endif() if (TBB_FILE_TRIM) file(RELATIVE_PATH TBB_RELATIVE_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) - if(CMAKE_VERSION VERSION_LESS 3.20) - file(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} NATIVE_TBB_PROJECT_ROOT_DIR) - file(TO_NATIVE_PATH ${TBB_RELATIVE_BIN_PATH} NATIVE_TBB_RELATIVE_BIN_PATH) - else() - cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR NATIVE_TBB_PROJECT_ROOT_DIR) - cmake_path(NATIVE_PATH TBB_RELATIVE_BIN_PATH NATIVE_TBB_RELATIVE_BIN_PATH) - endif() + file(TO_NATIVE_PATH ${CMAKE_SOURCE_DIR} NATIVE_TBB_PROJECT_ROOT_DIR) + file(TO_NATIVE_PATH ${TBB_RELATIVE_BIN_PATH} NATIVE_TBB_RELATIVE_BIN_PATH) endif () set(TBB_COMPILER_SETTINGS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/compilers/${CMAKE_CXX_COMPILER_ID}.cmake) diff --git a/cmake/README.md b/cmake/README.md index afc20d5663..11f71a93fb 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -20,7 +20,8 @@ TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default) TBB_ENABLE_IPO - Enable Interprocedural Optimization (IPO) during the compilation (ON by default) TBB_BUILD_APPLE_FRAMEWORKS - Enable the Apple* frameworks instead of dylibs, only available on the Apple platform. (OFF by default) -TBB_FILE_TRIM - Enable __FILE__ trim (ON by default) +TBB_FILE_TRIM - Enable __FILE__ trim, replace a build-time full path with a relative path in the debug info and macro __FILE__, this can be used to make + reproducible builds that are location independent (ON by default) ``` ## Configure, Build, and Test diff --git a/cmake/compilers/AppleClang.cmake b/cmake/compilers/AppleClang.cmake index 016473e888..9cf0b08628 100644 --- a/cmake/compilers/AppleClang.cmake +++ b/cmake/compilers/AppleClang.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022 Intel Corporation +# Copyright (c) 2020-2024 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 5115535076351e484c64f27fa1a441617cbe1bc4 Mon Sep 17 00:00:00 2001 From: Fang Xu Date: Tue, 3 Sep 2024 18:07:45 +0800 Subject: [PATCH 4/5] Update cmake/README.md Co-authored-by: Alexandra --- cmake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/README.md b/cmake/README.md index 11f71a93fb..29a9126650 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -20,7 +20,7 @@ TBB_VALGRIND_MEMCHECK:BOOL - Enable scan for memory leaks using Valgrind (OFF by TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-config tool (OFF by default) TBB_ENABLE_IPO - Enable Interprocedural Optimization (IPO) during the compilation (ON by default) TBB_BUILD_APPLE_FRAMEWORKS - Enable the Apple* frameworks instead of dylibs, only available on the Apple platform. (OFF by default) -TBB_FILE_TRIM - Enable __FILE__ trim, replace a build-time full path with a relative path in the debug info and macro __FILE__, this can be used to make +TBB_FILE_TRIM - Enable __FILE__ trim, replace a build-time full path with a relative path in the debug info and macro __FILE__; use it to make reproducible builds that are location independent (ON by default) ``` From 653b02f84b5f863d313f394ac2c678de7197ea1c Mon Sep 17 00:00:00 2001 From: Fang Xu Date: Tue, 3 Sep 2024 18:07:54 +0800 Subject: [PATCH 5/5] Update cmake/README.md Co-authored-by: Alexandra --- cmake/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/README.md b/cmake/README.md index 29a9126650..a9b8088e06 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -21,7 +21,7 @@ TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH - Disable HWLOC automatic search by pkg-confi TBB_ENABLE_IPO - Enable Interprocedural Optimization (IPO) during the compilation (ON by default) TBB_BUILD_APPLE_FRAMEWORKS - Enable the Apple* frameworks instead of dylibs, only available on the Apple platform. (OFF by default) TBB_FILE_TRIM - Enable __FILE__ trim, replace a build-time full path with a relative path in the debug info and macro __FILE__; use it to make - reproducible builds that are location independent (ON by default) + reproducible location-independent builds (ON by default) ``` ## Configure, Build, and Test