atilaneves / cmake-ide

Use Emacs as a C/C++ IDE
BSD 3-Clause "New" or "Revised" License
714 stars 92 forks source link

Failure when encountering compile options as quoted strings containing spaces #24

Closed sbroberg closed 8 years ago

sbroberg commented 8 years ago

Our compile line is specifying environment variables which are quoted strings containing spaces. When flycheck is trying to compile the file, the options are not being correctly handled, resulting in errors like:

In file included from <built-in>:346:
<command line>:4:23: warning: missing terminating '"' character

Example (note the value specified for DPRODVER_STRING):

Actual compilation line for translation unit:

cd \
  /Users/stebro/product/daemon/build_debug/src \
  && \
  /usr/bin/clang++ \
  -DASSERT_ON \
  -DPRODVER_BUILD_NO=999 \
  -DPRODVER_FULL=\"99.9.999\" \
  -DPRODVER_MAJOR=99 \
  -DPRODVER_MINOR=9 \
  -DPRODVER_STRING="\"99.9.9d1 build 999 (2008-01-01 12:00:00)\"" \
  -DQT_CORE_LIB \
  -DQT_NETWORK_LIB \
  -D_DEBUG=1 \
  -g \
  -arch \
  i386 \
  -isysroot \
  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk \
  -mmacosx-version-min=10.7 \
  -I/Users/stebro/product/daemon/build_debug/src \
  -I/Users/stebro/product/daemon/src \
  -isystem \
  /Volumes/ProductToolChain/include \
  -isystem \
  /Volumes/ProductToolChain/include/log4qt \
  -isystem \
  /Volumes/ProductToolChain/include/log4qt/varia \
  -I/Users/stebro/product/daemon/src/../include \
  -I/Users/stebro/product/daemon/dbcommon/include \
  -F/Volumes/ProductToolChain/qt-5.5/lib \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtCore.framework/Headers \
  -I/Volumes/ProductToolChain/qt-5.5/mkspecs/macx-clang-32 \
  -I/Users/stebro/product/daemon/dbcommon/ClientShared/include \
  -I/Users/stebro/product/daemon/build_debug/dbcommon/ClientShared/include \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtNetwork.framework/Headers \
  -stdlib=libstdc++ \
  -Werror \
  -Wno-c99-extensions \
  -Wno-c++98-compat \
  -Wreorder \
  -Wunused-variable \
  -Woverloaded-virtual \
  -Wno-unused-local-typedef \
  -Wno-inconsistent-missing-override \
  -Wunused-function \
  -Wno-unknown-warning-option \
  -Wno-#warnings \
  -Wno-c++11-extensions \
  -Wshorten-64-to-32 \
  -Winvalid-pch \
  -fPIC \
  -o \
  CMakeFiles/Client.dir/services/scan/VolumeChangeMonitor.cpp.o \
  -c \
  /Users/stebro/product/daemon/src/services/scan/VolumeChangeMonitor.cpp

Compile line used by flycheck-compile:

clang \
  -fsyntax-only \
  -fno-color-diagnostics \
  -fno-caret-diagnostics \
  -fno-diagnostics-show-option \
  -iquote \
  /Users/stebro/product/daemon/src/services/scan/ \
  -std\=c\+\+1y \
  -Wall \
  -Wextra \
  -DDBCOMMON_EXPORTS \
  -DLOG4QT \
  -DPRODVER_BUILD_NO\=999 \
  -DPRODVER_FULL\=\\\"99.9.999\\\" \
  -DPRODVER_MAJOR\=99 \
  -DPRODVER_MINOR\=9 \
  -DPRODVER_STRING\=\"\\\"99.9.9d1 \
  -DQT_CORE_LIB \
  -DQT_NO_DEBUG \
  -DQT_NETWORK_LIB \
  -DASSERT_ON \
  -DUNIT_TESTING \
  -D_XCODE \
  -DQT_GUI_LIB \
  -DQT_WIDGETS_LIB \
  -DQT_PRINTSUPPORT_LIB \
  -DQT_TESTLIB_LIB \
  -I/Volumes/ProductToolChain/include/log4qt/varia \
  -I/Volumes/ProductToolChain/include/log4qt \
  -I/Volumes/ProductToolChain/include \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/src \
  -I/Users/stebro/product/daemon/dbcommon/src \
  -I/Users/stebro/product/daemon/dbcommon/include \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtCore.framework/Headers \
  -I/Volumes/ProductToolChain/qt-5.5/mkspecs/macx-clang-32 \
  -I/Users/stebro/product/daemon/dbcommon/ClientShared/include \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/ClientShared/include \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/test \
  -I/Users/stebro/product/daemon/dbcommon/test \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/tools-convert/convertstatus \
  -I/Users/stebro/product/daemon/dbcommon/tools-convert/convertstatus \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/ClientShared/src \
  -I/Users/stebro/product/daemon/dbcommon/ClientShared/src \
  -I/Users/stebro/product/daemon/dbcommon/ClientShared/include/QsLog \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtNetwork.framework/Headers \
  -I/Users/stebro/product/daemon/src/daemon/dbcommon/ClientShared/test \
  -I/Users/stebro/product/daemon/dbcommon/ClientShared/test \
  -I/Users/stebro/product/daemon/src/daemon/src \
  -I/Users/stebro/product/daemon/src \
  -I/Users/stebro/product/daemon/src/../include \
  -I/Users/stebro/product/daemon/src/daemon/tests \
  -I/Users/stebro/product/daemon/tests \
  -I/Users/stebro/product/daemon/src/ui/common \
  -I/Users/stebro/product/ui/common \
  -I/Users/stebro/product/ui \
  -I/Users/stebro/product/ui/common/ui \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtGui.framework/Headers \
  -I/System/Library/Frameworks/OpenGL.framework/Headers \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtWidgets.framework/Headers \
  -I/Users/stebro/product/daemon/src/ui/status \
  -I/Users/stebro/product/ui/status \
  -I/Users/stebro/product/daemon/src/ui/install \
  -I/Users/stebro/product/ui/install \
  -I/Users/stebro/product/ui/install/ui \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtPrintSupport.framework/Headers \
  -I/Users/stebro/product/daemon/src/ui/helpers/install \
  -I/Users/stebro/product/ui/helpers/install \
  -I/Users/stebro/product/daemon/src/ui/ui \
  -I/Users/stebro/product/ui/ui \
  -I/Users/stebro/product/ui/ui/../ui \
  -I/Users/stebro/product/daemon/src/ui/tests \
  -I/Users/stebro/product/ui/tests \
  -I/Volumes/ProductToolChain/qt-5.5/lib/QtTest.framework/Headers \
  -x c\+\+ \
  - < /Users/stebro/product/daemon/src/services/scan/VolumeChangeMonitor.cpp
sbroberg commented 8 years ago

I'm looking at your elisp now - it seems you're filtering the compiler commands to yield only includes & defines. But why not use the command as-is, trimming off the beginning and end parts that are inapplicable, instead of searching through the string to find the parts that are? In my project, there doesn't seem to be a problem including everything other than the last part of the command specifying the -o and -c options, which you would replace with the - < .

Relating to the other issue I filed (referenced above - #26 ) - I'm not sure why cmake-ide appears to be pulling in a union of all the include options for all files compiled in my project. I'm not well-versed in lisp, so I can't determine how the flycheck setting is derived, but I can't see how any invocation of cmake, regardless of directory, would result in the commands in the json file have all includes. Are you recursing through the included headers and adding the includes for their compilation units as well?

atilaneves commented 8 years ago

The reason I'm filtering is because flycheck uses different variables for includes and defines. Each package does its own thing, auto-complete-clang just takes all variables at once, so no filtering is needed there.

atilaneves commented 8 years ago

I don't remember any more why I thought filtering was a good idea, I'll change it to stuff everything that isn't includes and defines into flycheck-clang-args

atilaneves commented 8 years ago

I found out what the issue here is; the JSON output has to escape quotes to be valid JSON, but reading the file keeps all the extra backslashes that shouldn't be passed to the shell. I'm still figuring out how to fix this though

atilaneves commented 8 years ago

I fixed a similar issue with a project of mine. I'm not sure it'll fix your issue, though. Why is it

-DPRODVER_STRING="\"99.9.9d1 build 999 (2008-01-01 12:00:00)\""

Instead of simply:

-DPRODVER_STRING=\"99.9.9d1 build 999 (2008-01-01 12:00:00)\"
atilaneves commented 8 years ago

I think this is fixed now so closing.