From a20e007c29e998f4416b29547689bd4a867c6245 Mon Sep 17 00:00:00 2001 From: Yingchun Lai <405403881@qq.com> Date: Tue, 25 Jan 2022 14:12:34 +0800 Subject: [PATCH 1/2] fix(build): fix higher version cmake produce a bad filename as 'compiler_depend.ts' --- bin/dsn.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dsn.cmake b/bin/dsn.cmake index f492ebb790..6ecc034019 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -353,7 +353,7 @@ function(dsn_setup_thirdparty_libs) endfunction(dsn_setup_thirdparty_libs) function(dsn_common_setup) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $<))\"'" CACHE STRING "" FORCE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $@))\"'" CACHE STRING "" FORCE) if(NOT (UNIX)) message(FATAL_ERROR "Only Unix are supported.") From a19933afe1f5b330c3dc9d256fd6993aad25502c Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Thu, 27 Jan 2022 00:50:59 +0800 Subject: [PATCH 2/2] update --- bin/dsn.cmake | 28 ++++++++++++++++++++++++++-- src/runtime/CMakeLists.txt | 1 + 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bin/dsn.cmake b/bin/dsn.cmake index 6ecc034019..fa7f8774bd 100644 --- a/bin/dsn.cmake +++ b/bin/dsn.cmake @@ -41,6 +41,31 @@ endif() # ================================================================== # +# Helper function to add preprocesor definition of FILE_BASENAME +# to pass the filename without directory path for debugging use. +# +# Note that in header files this is not consistent with +# __FILE__ and __LINE__ since FILE_BASENAME will be the +# compilation unit source file name (.c/.cpp). +# +# Example: +# +# define_file_basename_for_sources(my_target) +# +# Will add -DFILE_BASENAME="filename" for each source file depended on +# by my_target, where filename is the name of the file. +# +function(define_file_basename_for_sources targetname) + get_target_property(source_files "${targetname}" SOURCES) + foreach(sourcefile ${source_files}) + # Add the FILE_BASENAME=filename compile definition to the list. + get_filename_component(basename "${sourcefile}" NAME) + # Set the updated compile definitions on the source file. + set_property( + SOURCE "${sourcefile}" APPEND + PROPERTY COMPILE_DEFINITIONS "__FILENAME__=\"${basename}\"") + endforeach() +endfunction() # Install this target into ${CMAKE_INSTALL_PREFIX}/lib function(dsn_install_library) @@ -140,6 +165,7 @@ function(dsn_add_project) set(MY_PROJ_LIBS ${MY_PROJ_LIBS} ${DEFAULT_THIRDPARTY_LIBS} ${MY_BOOST_LIBS} ${DSN_SYSTEM_LIBS}) endif() ms_add_project("${MY_PROJ_TYPE}" "${MY_PROJ_NAME}" "${MY_PROJ_SRC}" "${MY_PROJ_LIBS}" "${MY_BINPLACES}") + define_file_basename_for_sources(${MY_PROJ_NAME}) endfunction(dsn_add_project) function(dsn_add_static_library) @@ -353,8 +379,6 @@ function(dsn_setup_thirdparty_libs) endfunction(dsn_setup_thirdparty_libs) function(dsn_common_setup) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(notdir $(abspath $@))\"'" CACHE STRING "" FORCE) - if(NOT (UNIX)) message(FATAL_ERROR "Only Unix are supported.") endif() diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index 73ea6e4a6c..feda8ffb4e 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -28,4 +28,5 @@ add_library(dsn_runtime STATIC zlocks.cpp ) target_link_libraries(dsn_runtime PRIVATE dsn_utils sasl2 gssapi_krb5 krb5) +define_file_basename_for_sources(dsn_runtime) install(TARGETS dsn_runtime DESTINATION "lib")