Fetch Content EXCLUDE_FROM_ALL still adds targets to Xcode IDE

Below is a minimal cmake file that includes eigen with fetch content.

cmake_minimum_required(VERSION 3.28)
project(EigenFetchExample LANGUAGES CXX)

include(FetchContent)

FetchContent_Declare(
    eigen
    GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
    GIT_TAG 3.4.0
    EXCLUDE_FROM_ALL
)

set(BUILD_TESTING OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(eigen)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE Eigen3::Eigen)

When I generate an Xcode project, many of the eigen targets still show up in the Xcode IDE even though I specify EXCLUDE_FROM_ALL

mkdir build && cd build
cmake -G Xcode ..

I thought EXCLUDE_FROM_ALL was meant to prevent this from happening. What am I missing?

You are misunderstanding what EXCLUDE_FROM_ALL does. The dependency is still added to the build, and the same targets are all still defined. When EXCLUDE_FROM_ALL is given, all it means is don’t build the dependency’s targets as part of the default ALL target. They are still defined and can be manually built, hence why they still show up in your IDE.

1 Like

@craig.scott ah, I see I’m mistaken now. Thanks for the reply. Do you happen to know if there is a way to include a project with fetch content without having its targets added to an IDE project?

Well, I suppose the best case is to hope that it can be found with FIND_PACKAGE and use the FIND_PACKAGE_ARGS functionality.

Not that I’m aware of. CMake doesn’t have any mechanism to say “treat this target as internal, don’t show it in IDEs”. Some related discussion can be found in this feature request.