File tree Expand file tree Collapse file tree 3 files changed +20
-12
lines changed
Expand file tree Collapse file tree 3 files changed +20
-12
lines changed Original file line number Diff line number Diff line change 11include (functions/genex)
2+ include (functions/set_relative_file_macro)
23
34# This function is equivalent to `add_library` but applies DevilutionX-specific
45# compilation flags to it.
@@ -66,6 +67,8 @@ function(add_devilutionx_library NAME)
6667 endif ()
6768
6869 target_compile_definitions (${NAME} PUBLIC ${DEVILUTIONX_DEFINITIONS} )
70+
71+ set_relative_file_macro(${NAME} )
6972endfunction ()
7073
7174# Same as add_devilutionx_library(${NAME} OBJECT) with an additional
Original file line number Diff line number Diff line change 1+ # Sets the __FILE__ macro value to be relative to CMAKE_SOURCE_DIR.
2+ function (set_relative_file_macro TARGET )
3+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
4+ if ((CMAKE_CXX_COMPILER_ID MATCHES "CLANG" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
5+ OR (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8))
6+ target_compile_options (${TARGET} PUBLIC "-ffile-prefix-map=${CMAKE_SOURCE_DIR} /=" )
7+ else ()
8+ get_target_property (_srcs ${TARGET} SOURCES )
9+ foreach (_src ${_srcs} )
10+ set_source_files_properties (${_src} PROPERTIES COMPILE_DEFINITIONS __FILE__="${_src} " )
11+ endforeach ()
12+ target_compile_options (${TARGET} PRIVATE -Wno-builtin-macro-redefined)
13+ endif ()
14+ endif ()
15+ endfunction ()
Original file line number Diff line number Diff line change @@ -247,18 +247,8 @@ if(BUILD_TESTING)
247247 add_subdirectory (test )
248248endif ()
249249
250- if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
251- # Change __FILE__ to only show the path relative to the project folder
252- get_target_property (libdevilutionx_SRCS ${BIN_TARGET} SOURCES )
253- foreach (SOURCE_FILE ${libdevilutionx_SRCS} )
254- set_source_files_properties (${SOURCE_FILE} PROPERTIES
255- COMPILE_DEFINITIONS __FILE__="${SOURCE_FILE} "
256- )
257- endforeach (SOURCE_FILE)
258-
259- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-builtin-macro-redefined" )
260- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined" )
261- endif ()
250+ include (functions/set_relative_file_macro)
251+ set_relative_file_macro(${BIN_TARGET} )
262252
263253if (APPLE )
264254 set_source_files_properties ("./Packaging/apple/AppIcon.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
You can’t perform that action at this time.
0 commit comments