Bug #96720 cmake botches the names of the source files when printing compile errors on Win
Submitted: 2 Sep 2019 15:17 Modified: 3 Oct 2019 18:00
Reporter: Georgi Kodinov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[2 Sep 2019 15:17] Georgi Kodinov
Description:
Cmake seems to somehow cause MSVC to garble the names of source files when printing error messages in MSVC 2019.
As a result the error list window is filled in with the errors, but when I try to click on them they don't open the offending file.
I've tested it with VS2019 16.2.3, but it maybe is repeatable with VS2017 too.

How to repeat:
0. Clone the mysql git tree. I have mine as a subdirectory of c:\Users\gkodinov\dev : c:\users\gkodinov\dev\mysql-trunk-wl12653.
1. Open the local mysql git tree as a "local directory" in VS2019.
2. wait until cmake project initializes.
3. Make sure you can compile it completion.
4. Make a syntax error. E.g. edit components\test\test_host_application_signal.cc and remove the semicolon after the line "REQUIRES_SERVICE_PLACEHOLDER(udf_registration);"
5. Try to compile.
6. Observe the following error message:
C:\Users\components\test\test_host_application_signal.cc(32): error C2144: syntax error: 'mysql_service_ref_t' should be preceded by ';'

Note that the correct path of the file is: C:\Users\gkodinov\dev\mysql-trunk-wl12653\components\test\test_host_application_signal.cc

I've tried recreating this with a standalone simple library+binary cmake project. Not getting it.

The full error log is:
 [4/8] Building CXX object components\test\CMakeFiles\component_test_host_application_signal.dir\test_host_application_signal.cc.obj
  FAILED: components/test/CMakeFiles/component_test_host_application_signal.dir/test_host_application_signal.cc.obj 
  C:\PROGRA~2\MICROS~1\2019\PROFES~1\VC\Tools\MSVC\1422~1.279\bin\HostX64\x64\cl.exe  /nologo /TP -DHAVE_CONFIG_H -DHAVE_LIBEVENT2 -DHAVE_OPENSSL -DHAVE_TLSv13 -DLZ4_DISABLE_DEPRECATE_WARNINGS -DMYSQL_COMPONENT -DNOGDI -DNOMINMAX -DRAPIDJSON_NO_SIZETYPEDEFINE -DRAPIDJSON_SCHEMA_USE_INTERNALREGEX=0 -DRAPIDJSON_SCHEMA_USE_STDREGEX=1 -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_WIN32_WINNT=0x0601 -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dcomponent_test_host_application_signal_EXPORTS -I. -Iinclude -I..\..\ -I..\..\include -I..\..\extra\rapidjson\include -I..\..\extra\lz4 -I..\..\extra\zstd\lib -Iextra\zlib -I..\..\extra\zlib -IC:\openssl\openssl-1.1.1c-windows-x86-64bit\include /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP /wd4996 /wd4267 /wd4244 /permissive- -DSAFE_MUTEX -DENABLED_DEBUG_SYNC /MDd /Z7 /Ob1 /Od /RTC1 /JMC /EHsc /std:c++14 /showIncludes /Focomponents\test\CMakeFiles\component_test_host_application_signal.dir\test_host_application_signal.cc.obj /Fdcomponents\test\CMakeFiles\component_test_host_application_signal.dir\ /FS -c ..\..\components\test\test_host_application_signal.cc
C:\Users\components\test\test_host_application_signal.cc(32): error C2144: syntax error: 'mysql_service_ref_t' should be preceded by ';'

Suggested fix:
Simplify the cmake file so it doesn't chew up the source path names ?
[2 Sep 2019 15:54] Georgi Kodinov
Posted by developer:
 
FWIW I can't reproduce this against the public git tree: 

  [167/169] C:\PROGRA~2\MICROS~1\2019\Preview\VC\Tools\MSVC\1423~1.280\bin\HostX64\x64\cl.exe  /nologo /TP -DHAVE_CONFIG_H -DHAVE_LIBEVENT2 -DHAVE_OPENSSL -DHAVE_TLSv13 -DLZ4_DISABLE_DEPRECATE_WARNINGS -DNOGDI -DNOMINMAX -DRAPIDJSON_NO_SIZETYPEDEFINE -DRAPIDJSON_SCHEMA_USE_INTERNALREGEX=0 -DRAPIDJSON_SCHEMA_USE_STDREGEX=1 -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_WIN32_WINNT=0x0601 -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dcomponent_test_host_application_signal_EXPORTS -I. -Iinclude -I..\..\..\ -I..\..\..\include -Ilibbinlogevents\include -I..\..\..\libbinlogevents\export -I..\..\..\extra\rapidjson\include -I..\..\..\extra\lz4 -I..\..\..\extra\zlib -Iextra\zlib -IC:\openssl\openssl-1.1.1c-windows-x86-64bit\include /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP /wd4996 /wd4267 /wd4244 /permissive- -DSAFE_MUTEX -DENABLED_DEBUG_SYNC /MDd /ZI /Ob1 /Od /RTC1 /JMC /EHsc /std:c++14 /showIncludes /Focomponents\test\CMakeFiles\component_test_host_application_signal.dir\test_host_application_signal.cc.obj /Fdcomponents\test\CMakeFiles\component_test_host_application_signal.dir\ /FS -c ..\..\..\components\test\test_host_application_signal.cc
  FAILED: components/test/CMakeFiles/component_test_host_application_signal.dir/test_host_application_signal.cc.obj 
  C:\PROGRA~2\MICROS~1\2019\Preview\VC\Tools\MSVC\1423~1.280\bin\HostX64\x64\cl.exe  /nologo /TP -DHAVE_CONFIG_H -DHAVE_LIBEVENT2 -DHAVE_OPENSSL -DHAVE_TLSv13 -DLZ4_DISABLE_DEPRECATE_WARNINGS -DNOGDI -DNOMINMAX -DRAPIDJSON_NO_SIZETYPEDEFINE -DRAPIDJSON_SCHEMA_USE_INTERNALREGEX=0 -DRAPIDJSON_SCHEMA_USE_STDREGEX=1 -DUNISTR_FROM_CHAR_EXPLICIT=explicit -DUNISTR_FROM_STRING_EXPLICIT=explicit -DWIN32_LEAN_AND_MEAN -D_USE_MATH_DEFINES -D_WIN32_WINNT=0x0601 -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dcomponent_test_host_application_signal_EXPORTS -I. -Iinclude -I..\..\..\ -I..\..\..\include -Ilibbinlogevents\include -I..\..\..\libbinlogevents\export -I..\..\..\extra\rapidjson\include -I..\..\..\extra\lz4 -I..\..\..\extra\zlib -Iextra\zlib -IC:\openssl\openssl-1.1.1c-windows-x86-64bit\include /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MP /wd4996 /wd4267 /wd4244 /permissive- -DSAFE_MUTEX -DENABLED_DEBUG_SYNC /MDd /ZI /Ob1 /Od /RTC1 /JMC /EHsc /std:c++14 /showIncludes /Focomponents\test\CMakeFiles\component_test_host_application_signal.dir\test_host_application_signal.cc.obj /Fdcomponents\test\CMakeFiles\component_test_host_application_signal.dir\ /FS -c ..\..\..\components\test\test_host_application_signal.cc
C:\Users\gkodinov\dev\git-mysql\components\test\test_host_application_signal.cc(32): error C2144: syntax error: 'mysql_service_ref_t' should be preceded by ';'
[4 Sep 2019 15:56] Tor Didriksen
Posted by developer:
 
I always build from the command line, against source mounted over samba, no problem with the error message:

  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.20.27508\bin\HostX64\x64\CL.exe /c /I"C:\ade\trunk-review" /I"C:\ade\trunk-review\include" /I"Z:\didrik\gitclone\trunk-review" /I"Z:\didrik\gitclone\trunk-review\include" /I"Z:\didrik\gitclone\trunk-review\extra\rapidjson\include" /I"Z:\didrik\gitclone\trunk-review\extra\lz4" /I"Z:\didrik\gitclone\trunk-review\extra\zstd\lib" /I"C:\ade\trunk-review\extra\zlib" /I"Z:\didrik\gitclone\trunk-review\extra\zlib" /I"C:\Program Files\OpenSSL-Win64\include" /Z7 /nologo /W3 /WX- /diagnostics:classic /MP /Od /Ob1 /D WIN32 /D _WINDOWS /D SAFE_MUTEX /D ENABLED_DEBUG_SYNC /D MYSQL_COMPONENT /D _WIN32_WINNT=0x0601 /D WIN32_LEAN_AND_MEAN /D NOGDI /D NOMINMAX /D RAPIDJSON_NO_SIZETYPEDEFINE /D RAPIDJSON_SCHEMA_USE_INTERNALREGEX=0 /D RAPIDJSON_SCHEMA_USE_STDREGEX=1 /D HAVE_CONFIG_H /D HAVE_OPENSSL /D __STDC_LIMIT_MACROS /D __STDC_FORMAT_MACROS /D _USE_MATH_DEFINES /D LZ4_DISABLE_DEPRECATE_WARNINGS /D HAVE_TLSv13 /D HAVE_LIBEVENT2 /D UNISTR_FROM_STRING_EXPLICIT=explicit /D UNISTR_FROM_CHAR_EXPLICIT=explicit /D "CMAKE_INTDIR=\"Debug\"" /D component_test_host_application_signal_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /GR /std:c++14 /Fo"component_test_host_application_signal.dir\Debug\\" /Fd"component_test_host_application_signal.dir\Debug\vc142.pdb" /Gd /TP /wd4996 /wd4267 /wd4244 /errorReport:queue "Z:\didrik\gitclone\trunk-review\components\test\test_host_application_signal.cc"
  test_host_application_signal.cc
Z:\didrik\gitclone\trunk-review\components\test\test_host_application_signal.cc(32): error C2144: syntax error: 'mysql_service_ref_t' should be preceded by ';' [C:\ade\trunk-review\components\test\component_test_host_application_signal.vcxproj]
Done Building Project "C:\ade\trunk-review\components\test\component_test_host_application_signal.vcxproj" (default targets) -- FAILED.

Build FAILED.
[10 Sep 2019 12:37] Georgi Kodinov
Posted by developer:
 
It seems to be a VS2019 issue:

VS2019 adds /ZI by default. This, according to cl's documentation, turns on /FC on by default too. This causes all error messages to produce full paths to the source files. So VS works properly. 

BUT ! 

If you try to disable /FC the above issue happens. 

Here's how to reproduce the effect: 
1. Create a c:\users\\dev\xx 
2. In it add the following files: 
2.1. CMakeLists.txt 
PROJECT(hello_world) 
ADD_LIBRARY(hello_lib SHARED hellolib.cc) 
ADD_EXECUTABLE(hello_world hello.cc) 
TARGET_LINK_LIBRARIES(hello_world hello_lib) 

2.2. 
hello.cc 
#include <stdio.h> 
extern int libfunc(int a); 
int main() { 
  fprintf(stdout, "hello, world %d\n", libfunc(12)); 
} 

2.3. hellolib.cc
#include <stdio.h>
__declspec(dllexport) int libfunc(int a) { return a + 12 } 

3. Open the directory via "open local directory" in VS. and select X64-debug 
4. Make sure cmake cache is generated 
5. build. you need to get one error: 
C:\Users\\dev\xx\hellolib.cc(3): error C2143: syntax error: missing ';' before '}' 
6. Make sure that double-clicking on the error in the errors list works. 
7. Edit the Cmake Cache file (Project/CMake Cache/view CMakeCache.thx). 
8. Replace all /ZI with /Zi 
9. rebuild 
10. Make sure you get one error again, but with a wrong file name
 C:\hellolib.cc(3): error C2143: syntax error: missing ';' before '}' 
11. Make sure that double-clicking on the error in the error list doesn't work
[10 Sep 2019 12:44] Georgi Kodinov
Posted by developer:
 
Filed as https://developercommunity.visualstudio.com/content/problem/729350/cmake-project-cant-clic...
[10 Sep 2019 12:54] Georgi Kodinov
Posted by developer:
 
https://docs.microsoft.com/en-us/cpp/build/reference/fc-full-path-of-source-code-file-in-d... says:

The /FC option is implied by /ZI.

But we replace /ZI with /Z7 in cmake/os/Windows.cmake. 
Hence the following diff fixes the issue:

diff --git a/cmake/os/Windows.cmake b/cmake/os/Windows.cmake
index 0e70220173e..a2046f44125 100644
--- a/cmake/os/Windows.cmake
+++ b/cmake/os/Windows.cmake
@@ -147,6 +147,7 @@ IF(MSVC)
       STRING(REPLACE "/Ob0"  "/Ob1" "${flag}" "${${flag}}")
     ENDIF()
     SET("${flag}" "${${flag}} /EHsc")
+    SET("${flag}" "${${flag}} /FC")
   ENDFOREACH()

   # Turn on c++14 mode explicitly so that using c++17 features is disabled.
[3 Oct 2019 18:00] Paul DuBois
Posted by developer:
 
Fixed in 8.0.19.

MSVC 2019 produced garbled source file names for compilation errors.
A workaround in the CMake configuration was implemented to correct
for this.