15knots / cmake4eclipse

Let Eclipse use CMake to generate the buildscripts for Eclipse CDT
Eclipse Public License 2.0
84 stars 25 forks source link

Compile commands parser not working with linked files or folders #120

Open gpxricky opened 5 years ago

gpxricky commented 5 years ago

This is a...

Brief Description

The CMAKE_EXPORT_COMPILE_COMMANDS Parser does not seem to handle defines and include paths properly for files which are only linked to the project (either directly or via a linked folder).

(If Bug Report) Brief Summary

The parser works fine if the file is stored in the Eclipse project with its correct file path. However when I change the folder to be a linked folder, the defines are not resolved anymore.

What is the expected behavior?

The correct behavior would be to resolve the defines and include paths according to the real path of the file instead of its virtual path.

What behavior are you observing?

Defines are not resolved properly.

Provide the steps to reproduce the issue, if applicable:

  1. Create a linked folder to your C/C++ file (e.g. main.cpp)
  2. Compile via CMake Builder
  3. Check if the defines are resolved properly in the C/C++ file

Useful Information

gentooise commented 5 years ago

Just an info that could be useful: in my case all Macros/Include Paths are working fine. I'm also using cmake4eclipse (basically same setup/versions of yours) and I usually have the entire src folder included as a Linked Folder: it doesn't seem to cause any issue.

15knots commented 5 years ago

What exactly does

Defines are not resolved properly. mean?

Are the macros missing in the Preprocessor Include Path tab? Or does the C-editor grey out sections that should not be greyed?

Can you post the first "command": line from the compile_commands.json file in the build directory here?

beckenc commented 4 years ago

The same issue here. All the macros are missing in the Preprocessor Include Path tab whereas the include path were parsed correctly.

I use the latest release of cmake4eclipse ( v 2.1.0 ). This is the first command "command" line from compile_commands.json: "command": "/usr/bin/c++ -DGENERIC_INTERFACE_IFNAME_LAN=\\\"enp1s5\\\" -I/home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/src/TI2CXX/asn1c/gen -I/home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/target/Linux-native -I/home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/test-src -I/usr/include/ace/.. -I/usr/include/curl -I/usr/include/ace/../.. -I/usr/include/ace/../../.. -I/home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/src -I/home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/target/Linux/src -I/usr/include/ace/../../../.. -I/usr/include/ace/../../../../.. -I/usr/include/ace/SSL/../.. -I/usr/include/llconf -I/usr/include/ace/../../../../../.. -I/usr/include/ace/../../../../../../.. -I/usr/include/ace/../../../../../../../.. -I/usr/include/xmlsec1 -I/usr/include/libxml2 -Wall -pipe -O2 -fdata-sections -ffunction-sections -Wno-narrowing -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DTARGET_BUILD=0 -g -DXMLSEC_CRYPTO=\\\"openssl\\\" -D__XMLSEC_FUNCTION__=__FUNCTION__ -DXMLSEC_NO_SIZE_T -DXMLSEC_NO_GOST=1 -DXMLSEC_NO_XKMS=1 -DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1 -DXMLSEC_OPENSSL_098=1 -DXMLSEC_CRYPTO_OPENSSL=1 -std=c++17 -o CMakeFiles/xmlsec-test.dir/src/custom-apps/xmlsec-test/main.cpp.o -c /home/cbe/workspace/c4_base/branches/RDC-P2/dev_hyTertiary/src/custom-apps/xmlsec-test/main.cpp",

15knots commented 4 years ago

@nuccleon can you provide a minimal example project allowint to reprodue this?

beckenc commented 4 years ago

Yes, of course. You'll find an entire eclipse project attached.

cmake4eclipse Verstion: 2.1.0

eclipse Version: 2019-12 (4.14.0) Build id: 20191212-1212

openjdk version "1.8.0_222" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_222-b10)

Eclipse runs under Gentoo Linux.

In the example, I have a DEFINE with the name _TARGET. I further have 3 project configurations with different _TARGET definitions (0,1 and 2).

My expectation was, that the CMAKE_COMPILE_COMMANDS Parser extracts the _TARGET definition from "command": "/usr/bin/c++ -I/home/cbe/workspace/piextsample/inc -D_TARGET=0 -o CMakeFiles/piextsample.dir/piextsample.cpp.o -c /home/cbe/workspace/piextsample/piextsample.cpp", But as you can see in the screenshot below, it doesn't.

Screenshot from 2020-02-13 22-08-44

Screenshot from 2020-02-13 22-15-38

I further would expect, that depending on the selected project configuration (with different _TARGET values) the related code section in the Editor window is selected.

Please let me know if you need some more details. Thanks for your support!

piextsample.tar.gz

15knots commented 4 years ago

@nuccleon I do not see any linked folders or files in your sample project. What am I missing?

With your project, the C++ editor shows that the _TARGET macro is properly recognized with value==2. You may not see the _TARGET macro in the properties page, because it is added for the piextsample.cpp file, but not for the project. In contrast, include paths are added for for the source file AND the project (this is to populate the includes folder in the project explorer view). The project properties page seems to show only the entries for the project, hence the marco is not shown there.

jordan-rose-github commented 1 year ago

Hello all, I experienced the same behavior as gpxricky today.

The indexer works fine with source files that are within the projects (-D flags are correctly detected). Unfortunately, the indexer does not work (-D flags) for files located outside the project (using New file -> Link to file in the file system).

Did I missed a configuration?

inxksp commented 10 months ago

Hello all, I experienced the same behavior as gpxricky today.

The indexer works fine with source files that are within the projects (-D flags are correctly detected). Unfortunately, the indexer does not work (-D flags) for files located outside the project (using New file -> Link to file in the file system).

I have the same problem