Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnkit Meel <ankitjmeel@gmail.com>2020-11-02 12:40:10 +0300
committerAnkit Meel <ankitjmeel@gmail.com>2020-11-02 12:42:10 +0300
commit1daa3c3f0a1cfd74bef527e0207f38154e591d46 (patch)
tree1851541dd2c81f8987c77f39a96dc794ab5d8c6f /CMakeLists.txt
parentcc09c0d0484be334c985ccd143c46c266abb8aa0 (diff)
Clang/GCC: use relative path in __FILE__ macro
This change removes the user-specific information from macros like `__FILE__` and keeps it relative to top level source or build (for generated files) directory. It makes traces concise. Added option `WITH_COMPILER_SHORT_FILE_MACRO` enabled by default. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D9386
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt37
1 files changed, 37 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eb04da749ab..9c5ab607bf6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -570,6 +570,11 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
endif()
endif()
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+ option(WITH_COMPILER_SHORT_FILE_MACRO "Make paths in macros like __FILE__ relative to top level source and build directories." ON)
+ mark_as_advanced(WITH_COMPILER_SHORT_FILE_MACRO)
+endif()
+
if(WIN32)
# Use hardcoded paths or find_package to find externals
option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
@@ -1655,6 +1660,38 @@ if(UNIX AND NOT APPLE)
endif()
endif()
+if(WITH_COMPILER_SHORT_FILE_MACRO)
+ # Use '-fmacro-prefix-map' for Clang and GCC (MSVC doesn't support this).
+ if((CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.4) OR
+ (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) OR
+ (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
+ )
+
+ if(APPLE)
+ if(XCODE AND ${XCODE_VERSION} VERSION_LESS 12.0)
+ # Developers may have say LLVM Clang-10.0.1 toolchain with Xcode-11.
+ message_first_run(WARNING
+ "-fmacro-prefix-map flag is NOT supported by Clang shipped with Xcode-${XCODE_VERSION}."
+ " Some Xcode functionality in Product menu may not work. Disabling WITH_COMPILER_SHORT_FILE_MACRO."
+ )
+ set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
+ endif()
+ endif()
+ if(WITH_COMPILER_SHORT_FILE_MACRO)
+ set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} \
+-fmacro-prefix-map=\"${CMAKE_SOURCE_DIR}/\"=\"\" \
+-fmacro-prefix-map=\"${CMAKE_BINARY_DIR}/\"=\"\""
+ )
+ endif()
+ else()
+ message_first_run(WARNING
+ "-fmacro-prefix-map flag is NOT supported by ${CMAKE_C_COMPILER_ID} version-${CMAKE_C_COMPILER_VERSION}."
+ " Disabling WITH_COMPILER_SHORT_FILE_MACRO."
+ )
+ set(WITH_COMPILER_SHORT_FILE_MACRO OFF)
+ endif()
+endif()
+
# Include warnings first, so its possible to disable them with user defined flags
# eg: -Wno-uninitialized
set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")