Skip to content

Commit 18837f1

Browse files
tkreuzerJoachimHenze
authored andcommitted
[0.4.11] [CMAKE] Fix problem with __RELFILE__ not working when
compiler uses relative paths done in context of CORE-14839 (2 of 2 commits) This usually happens when the build dir is a subdir of the source dir. It is now detected during runtime, using the length of the relative path from the build dir to the source dir as the length of the prefix to skip, if __FILE__ starts with a '.'. Also fix the escaping of REACTOS_*_DIR defines. It was gracefully fixed up by CMake, but resulted in broken syntax highliting. CORE-14839 #resolve cherry picked from commit 0.4.12-dev-29-g 3de04cc
1 parent 7cd5862 commit 18837f1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ endif()
5757
include(sdk/cmake/compilerflags.cmake)
5858

5959
add_definitions(-D__REACTOS__)
60-
add_definitions(-DREACTOS_SOURCE_DIR="\\"${REACTOS_SOURCE_DIR}\\"")
61-
add_definitions(-DREACTOS_BINARY_DIR="\\"${REACTOS_BINARY_DIR}\\"")
62-
add_compile_flags(-D__RELFILE__="&__FILE__[sizeof REACTOS_SOURCE_DIR]")
60+
61+
# Double escape, since CMake unescapes before putting it on the command-line, where it's unescaped again by GCC/CL.
62+
add_definitions(-DREACTOS_SOURCE_DIR="\\\"${REACTOS_SOURCE_DIR}\\\"")
63+
add_definitions(-DREACTOS_BINARY_DIR="\\\"${REACTOS_BINARY_DIR}\\\"")
64+
65+
# There doesn't seem to be a standard for __FILE__ being relative or absolute, so detect it at runtime.
66+
file(RELATIVE_PATH _PATH_PREFIX ${REACTOS_BINARY_DIR} ${REACTOS_SOURCE_DIR})
67+
add_compile_flags(-D__RELFILE__="&__FILE__[__FILE__[0] == '.' ? sizeof \\\"${_PATH_PREFIX}\\\" - 1 : sizeof REACTOS_SOURCE_DIR]")
6368

6469
if(MSVC_IDE)
6570
add_compile_flags("/MP")

0 commit comments

Comments
 (0)