generating eclipse project with subprojects links the main project in the subprojects too

Hi,

I use cmake to generate an eclipse project like this:

cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_ECLIPSE_VERSION=4.18 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=TRUE -DCMAKE_ECLIPSE_MAKE_ARGUMENTS=-j4 PATH_TO_REPOSITORY "${@:1}"

The project has some dependencies which are configured in cmake with “FetchContent_Declare”.

In the eclipse project, the source code directory of the project will also be added to the subprojects (as a link with the main project’s name). This is leading to severe problems in eclipse. When I delete that link eclipse is working properly. Sadly the link gets recreated under some unclear conditions.

I haven’t figured out yet, which changes in the cmake project are causing the link to be recreated. It seems that adding files to a subdirectory is safe. When I delete cmake’s cache the link will be recreated. That’s all I know so far.

What could have caused this issue? How can I possibly prevent it?

I’ve already posted a request in eclipse forum.

This problem still remains for me.

  • In the eclipse project, the main source directory gets linked in the subprojects.
  • In eclipse, refactoring code of the main source fails with unpredictable results and code is broken afterwards (it seems that the already refactored code from the main source is changed once more for the linked source)
  • Deleting the linked main-source from the subprojects helps temporarily but it’s automatically recreated (at least on clearing cmake cache and possibly also on other unclear conditions)

What mistake could I’ve made that would cause the main project to be also linked as a subproject?
Topic in eclipse forum is here: Eclipse Community Forums: C / C++ IDE (CDT) » refactoring fails in cmake generated projects

Best regards

CMakeLists.txt files of my eclipse projects look like this for example:

cmake_minimum_required(VERSION 3.14)
include(FetchContent)

project(NewProject)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

FetchContent_Declare(
    SubProject1
    GIT_REPOSITORY ...
)
FetchContent_MakeAvailable(SubProject1)

FetchContent_Declare(
    SubProject2
    GIT_REPOSITORY ...
)
FetchContent_MakeAvailable(SubProject2)

add_library(NewProject STATIC)

target_include_directories(NewProject
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(NewProject
    SubProject1
    SubProject2
)

add_subdirectory(src)

# Unit tests
enable_testing()

FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

add_executable(NewProject_Tests)

target_link_libraries(NewProject_Tests
    NewProject
    gtest_main
)

include(GoogleTest)
gtest_discover_tests(NewProject_Tests)

add_subdirectory(tests)

I haven’t tried it with a project that doesn’t contain any subprojects provided by FetchContent_Declare.